tiskanje bulk + vrsni red opreacij na tiskanju
This commit is contained in:
@@ -19,14 +19,18 @@ namespace EveryThing.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)
|
||||
{
|
||||
@@ -34,27 +38,57 @@ namespace EveryThing.Pages.Projects
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnGetAsync(int id)
|
||||
public async Task<IActionResult> OnGetAsync(int? id, string ids)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
PartItem = await _context.ProjectPartItems
|
||||
.Include(x => x.ProjectPart)
|
||||
.ThenInclude(x => x.Project)
|
||||
.ThenInclude(x => x.Company)
|
||||
.Include(x => x.Material)
|
||||
.Include(x => x.Item)
|
||||
.FirstOrDefaultAsync(x => x.IdProjectPartItem == id && x.ProjectPart.Project.Company.IdCompany == user.IdCompanyFk);
|
||||
var itemIds = new List<int>();
|
||||
|
||||
if (PartItem == null)
|
||||
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();
|
||||
|
||||
|
||||
Operations = await _context.ProjectPartItemOperations
|
||||
.Include(x => x.Operation)
|
||||
.Where(x => x.IdProjectPartItemFk == PartItem.IdProjectPartItem)
|
||||
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