Files
everything/EveryThing/Pages/Projects/PrintProjectPartPaths.cshtml.cs
David Štaleker db0cc8d3de prvi
2025-07-18 05:33:16 +02:00

61 lines
2.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using EveryThing.Data;
using EveryThing.Models;
using EveryThing.Models.Invoice;
using EveryThing.Models.Transport;
using DocumentFormat.OpenXml.Wordprocessing;
using System.ComponentModel.DataAnnotations;
namespace EveryThing.Pages.Projects
{
[Authorize(Roles = "Administrator,InvoicingUser,ProjecThingUser")]
public class PrintProjectPartPathsModel : PageModel
{
private readonly ApplicationDbContext _context;
private readonly UserManager<IdentityApplicationUser> _userManager;
public Models.Project.Project Project { get; set; }
public IList<Models.Project.ProjectPartItem> Items { get; set; }
public string ProjectNumber { get; set; }
public PrintProjectPartPathsModel(ApplicationDbContext context, UserManager<IdentityApplicationUser> userManager)
{
_context = context;
_userManager = userManager;
}
public async Task<IActionResult> OnGetAsync(int id)
{
var user = _userManager.GetUserAsync(User).Result;
var projectPart = _context
.ProjectParts.Include(x => x.Project)
.ThenInclude(x => x.Company)
.FirstOrDefault();
if (projectPart == null)
return NotFound();
Project = projectPart.Project;
ProjectNumber = projectPart.ProjectPartNumberFormatted;
Items = await _context.ProjectPartItems
.Include(x => x.ProjectPart)
.ThenInclude(x => x.Project)
.Include(x => x.Item)
.Where(x => x.IdProjectPartFk == id)
.ToListAsync();
return Page();
}
}
}