public async Task <IInvoiceLineView> InvoiceLineCreate(IInvoiceLineCreate invoiceLineCreate) { try { var result = new InvoiceLineView(); using (var db = new InvoiceContext()) { var invoiceLine = new Database.InvoiceLine(); if (!db.Invoices.Any(w => w.InvoiceId == invoiceLineCreate.InvoiceId)) { return new InvoiceLineView() { __CQRSSuccessful = false, __CQRSErrorMessage = "Unable to find parent for Invoice", __CQRSStatusCode = 404 } } ; var invoice = db.Invoices.First(w => w.InvoiceId == invoiceLineCreate.InvoiceId); if (invoice.InvoiceLines == null) { invoice.InvoiceLines = new List <Database.InvoiceLine>(); } invoice.InvoiceLines.Add(invoiceLine); invoiceLine.Notes = invoiceLineCreate.Notes; invoiceLine.Product = invoiceLineCreate.Product; invoiceLine.ProductCode = invoiceLineCreate.ProductCode; invoiceLine.Quantity = invoiceLineCreate.Quantity; invoiceLine.SubTotal = invoiceLineCreate.SubTotal; invoiceLine.TaxExempt = invoiceLineCreate.TaxExempt; invoiceLine.TaxTotal = invoiceLineCreate.TaxTotal; invoiceLine.UnitCost = invoiceLineCreate.UnitCost; await db.SaveChangesAsync(); result.InvoiceLineId = invoiceLine.InvoiceLineId; result.LineTotal = invoiceLine.LineTotal; result.Notes = invoiceLine.Notes; result.Product = invoiceLine.Product; result.ProductCode = invoiceLine.ProductCode; result.Quantity = invoiceLine.Quantity; result.SubTotal = invoiceLine.SubTotal; result.TaxExempt = invoiceLine.TaxExempt; result.TaxTotal = invoiceLine.TaxTotal; result.UnitCost = invoiceLine.UnitCost; return(result); } } catch (Exception e) { LogFactory.GetLogger().Log(LogLevel.Error, e); return(new InvoiceLineView() { __CQRSSuccessful = false, __CQRSErrorMessage = "Unable to create InvoiceLineView", __CQRSStatusCode = 500 }); } }
public async Task Cancel() { if (InvoiceLineView.InvoiceLineId > 0) { await Load(InvoiceLineView.InvoiceLineId); } else { InvoiceLineView = new InvoiceLineView(); } }
public async Task <IInvoiceLineView> GetInvoiceLine(IGetInvoiceLine getInvoiceLine) { try { var result = new InvoiceLineView(); using (var db = new InvoiceContext()) { if (await db.InvoiceLines.AnyAsync(w => w.InvoiceLineId == getInvoiceLine.InvoiceLineId)) { var invoiceLine = await db.InvoiceLines.FirstAsync(w => w.InvoiceLineId == getInvoiceLine.InvoiceLineId); result.InvoiceLineId = invoiceLine.InvoiceLineId; result.LineTotal = invoiceLine.LineTotal; result.Notes = invoiceLine.Notes; result.Product = invoiceLine.Product; result.ProductCode = invoiceLine.ProductCode; result.Quantity = invoiceLine.Quantity; result.SubTotal = invoiceLine.SubTotal; result.TaxExempt = invoiceLine.TaxExempt; result.TaxTotal = invoiceLine.TaxTotal; result.UnitCost = invoiceLine.UnitCost; return(result); } else { return(new InvoiceLineView() { __CQRSSuccessful = false, __CQRSErrorMessage = "Unable to find item", __CQRSStatusCode = 500 }); } } } catch (Exception e) { LogFactory.GetLogger().Log(LogLevel.Error, e); return(new InvoiceLineView() { __CQRSSuccessful = false, __CQRSErrorMessage = "Unable to create InvoiceLineView", __CQRSStatusCode = 500 }); } }
public async Task <List <IInvoiceLineView> > GetAllInvoiceLinesForInvoice(IGetAllInvoiceLinesForInvoice getAllInvoiceLinesForInvoice) { var result = new List <IInvoiceLineView>(); try { using (var db = new InvoiceContext()) { var invoiceLines = await db.InvoiceLines.Where(w => w.Invoice.InvoiceNo == getAllInvoiceLinesForInvoice.InvoiceNo).ToListAsync(); foreach (var invoiceLine in invoiceLines) { var toAdd = new InvoiceLineView(); toAdd.InvoiceLineId = invoiceLine.InvoiceLineId; toAdd.LineTotal = invoiceLine.LineTotal; toAdd.Notes = invoiceLine.Notes; toAdd.Product = invoiceLine.Product; toAdd.ProductCode = invoiceLine.ProductCode; toAdd.Quantity = invoiceLine.Quantity; toAdd.SubTotal = invoiceLine.SubTotal; toAdd.TaxExempt = invoiceLine.TaxExempt; toAdd.TaxTotal = invoiceLine.TaxTotal; toAdd.UnitCost = invoiceLine.UnitCost; result.Add(toAdd); } } return(result); } catch (Exception e) { LogFactory.GetLogger().Log(LogLevel.Error, e); result.Clear(); return(result); // return new InvoiceLineView(){__CQRSSuccessful = false,__CQRSErrorMessage = "Unable to create InvoiceLineView",__CQRSStatusCode = 500}; } }