rename to projecting
This commit is contained in:
96
ProjecThing/Pages/Projects/PrintPartItem.cshtml.cs
Normal file
96
ProjecThing/Pages/Projects/PrintPartItem.cshtml.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
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 ProjecThing.Data;
|
||||
using ProjecThing.Models;
|
||||
using ProjecThing.Models.Project;
|
||||
using ProjecThing.Models.Transport;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace ProjecThing.Pages.Projects
|
||||
{
|
||||
[Authorize(Roles = "Administrator,InvoicingUser,ProjecThingUser")]
|
||||
public class PrintPartItem : PageModel
|
||||
{
|
||||
public class PrintPartItemData
|
||||
{
|
||||
public ProjectPartItem PartItem { get; set; }
|
||||
public IList<ProjectPartItemOperation> Operations { get; set; }
|
||||
}
|
||||
|
||||
private readonly ApplicationDbContext _context;
|
||||
private readonly UserManager<IdentityApplicationUser> _userManager;
|
||||
|
||||
public ProjectPartItem PartItem { get; set; }
|
||||
public IList<ProjectPartItemOperation> Operations { get; set; }
|
||||
public IList<PrintPartItemData> Items { get; set; } = new List<PrintPartItemData>();
|
||||
|
||||
public PrintPartItem(ApplicationDbContext context, UserManager<IdentityApplicationUser> userManager)
|
||||
{
|
||||
_context = context;
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnGetAsync(int? id, string ids)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
var itemIds = new List<int>();
|
||||
|
||||
if (!string.IsNullOrEmpty(ids))
|
||||
{
|
||||
itemIds = ids.Split(',', StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(x => int.TryParse(x.Trim(), out var v) ? v : 0)
|
||||
.Where(x => x > 0)
|
||||
.ToList();
|
||||
}
|
||||
else if (id.HasValue)
|
||||
{
|
||||
itemIds.Add(id.Value);
|
||||
}
|
||||
|
||||
if (!itemIds.Any())
|
||||
return NotFound();
|
||||
|
||||
var partItems = await _context.ProjectPartItems
|
||||
.Include(x => x.ProjectPart)
|
||||
.ThenInclude(x => x.Project)
|
||||
.ThenInclude(x => x.Company)
|
||||
.Include(x => x.Material)
|
||||
.Include(x => x.Item)
|
||||
.Where(x => itemIds.Contains(x.IdProjectPartItem) && x.ProjectPart.Project.Company.IdCompany == user.IdCompanyFk)
|
||||
.ToListAsync();
|
||||
|
||||
if (!partItems.Any())
|
||||
return NotFound();
|
||||
|
||||
var allOperations = await _context.ProjectPartItemOperations
|
||||
.Include(x => x.Operation)
|
||||
.Where(x => itemIds.Contains(x.IdProjectPartItemFk))
|
||||
.OrderBy(x => x.Order)
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var partItem in partItems.OrderBy(x => itemIds.IndexOf(x.IdProjectPartItem)))
|
||||
{
|
||||
Items.Add(new PrintPartItemData
|
||||
{
|
||||
PartItem = partItem,
|
||||
Operations = allOperations.Where(x => x.IdProjectPartItemFk == partItem.IdProjectPartItem).ToList()
|
||||
});
|
||||
}
|
||||
|
||||
// Keep backward compatibility for single-item references
|
||||
PartItem = Items.First().PartItem;
|
||||
Operations = Items.First().Operations;
|
||||
|
||||
return Page();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user