public async Task <IActionResult> OnPostAsync() { try { if (!ModelState.IsValid) { return(Page()); } Invoice_Entry.TaxCode = await NodeContext.App_tbTaxCodes.Where(c => c.TaxDescription == TaxDescription).Select(c => c.TaxCode).FirstAsync(); NodeContext.Attach(Invoice_Entry).State = EntityState.Modified; try { await NodeContext.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!await NodeContext.Invoice_Entries.AnyAsync(e => e.AccountCode == Invoice_Entry.AccountCode && e.CashCode == Invoice_Entry.CashCode)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); } catch (Exception e) { NodeContext.ErrorLog(e); throw; } }
public async Task <IActionResult> OnPostAsync() { try { if (!ModelState.IsValid) { return(Page()); } var previousItemValue = await NodeContext.Invoice_tbItems.Where(m => m.InvoiceNumber == Invoice_Item.InvoiceNumber && m.CashCode == Invoice_Item.CashCode) .Select(i => i.InvoiceValue + i.TotalValue).FirstAsync(); Invoice_Item.TaxCode = await NodeContext.App_tbTaxCodes.Where(c => c.TaxDescription == TaxDescription).Select(c => c.TaxCode).FirstAsync(); var invoiceHeader = await NodeContext.Invoice_tbInvoices.Where(i => i.InvoiceNumber == Invoice_Item.InvoiceNumber).FirstAsync(); bool orgRebuild = (previousItemValue != Invoice_Item.InvoiceValue + Invoice_Item.TotalValue); FinancialPeriods periods = new(NodeContext); bool periodRebuild = (invoiceHeader.InvoicedOn < periods.ActiveStartOn); NodeContext.Attach(Invoice_Item).State = EntityState.Modified; try { await NodeContext.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!await NodeContext.Invoice_tbItems.AnyAsync(e => e.InvoiceNumber == Invoice_Item.InvoiceNumber && e.CashCode == Invoice_Item.CashCode)) { return(NotFound()); } else { throw; } } Invoices invoices = new(NodeContext, Invoice_Item.InvoiceNumber); if (await invoices.Accept()) { if (orgRebuild) { Orgs orgs = new(NodeContext, invoiceHeader.AccountCode); await orgs.Rebuild(); } if (periodRebuild) { await periods.Generate(); } } RouteValueDictionary route = new(); route.Add("InvoiceNumber", Invoice_Item.InvoiceNumber); return(RedirectToPage("./Edit", route)); } catch (Exception e) { NodeContext.ErrorLog(e); throw; } }
public async Task <IActionResult> OnPostAsync() { try { if (!ModelState.IsValid) { return(Page()); } NodeEnum.InvoiceStatus invoiceStatus = (NodeEnum.InvoiceStatus) await NodeContext.Invoice_tbStatuses .Where(t => t.InvoiceStatus == InvoiceStatus) .Select(t => t.InvoiceStatusCode).FirstAsync(); NodeEnum.InvoiceType invoiceType = (NodeEnum.InvoiceType) await NodeContext.Invoice_tbTypes .Where(t => t.InvoiceType == InvoiceType) .Select(t => t.InvoiceTypeCode).FirstAsync(); bool periodRebuild = false; FinancialPeriods periods = new(NodeContext); DateTime previousInvoicedOn = await NodeContext.Invoice_tbInvoices.Where(i => i.InvoiceNumber == Invoice_tbInvoice.InvoiceNumber) .Select(i => i.InvoicedOn).FirstAsync(); if (previousInvoicedOn != Invoice_tbInvoice.InvoicedOn) { DateTime activePeriod = periods.ActiveStartOn; periodRebuild = (previousInvoicedOn < activePeriod || Invoice_tbInvoice.InvoicedOn < activePeriod); } bool orgRebuild = ((NodeEnum.InvoiceType)Invoice_tbInvoice.InvoiceTypeCode != invoiceType) || ((NodeEnum.InvoiceStatus)Invoice_tbInvoice.InvoiceStatusCode != invoiceStatus) || periodRebuild; Invoice_tbInvoice.InvoiceStatusCode = (short)invoiceStatus; Invoice_tbInvoice.InvoiceTypeCode = (short)invoiceType; NodeContext.Attach(Invoice_tbInvoice).State = EntityState.Modified; try { await NodeContext.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!await NodeContext.Invoice_tbInvoices.AnyAsync(e => e.AccountCode == Invoice_tbInvoice.InvoiceNumber)) { return(NotFound()); } else { throw; } } Invoices invoices = new(NodeContext, Invoice_tbInvoice.InvoiceNumber); if (await invoices.Accept()) { if (periodRebuild) { periodRebuild = await periods.Generate(); } if (orgRebuild) { Orgs orgs = new(NodeContext, Invoice_tbInvoice.AccountCode); orgRebuild = await orgs.Rebuild(); } } RouteValueDictionary route = new(); route.Add("InvoiceNumber", Invoice_tbInvoice.InvoiceNumber); return(RedirectToPage("./Index", route)); } catch (Exception e) { NodeContext.ErrorLog(e); throw; } }