public async Task <CreateProcessStatus> CreateSupplierInvoiceDetailsByView(SupplierInvoiceView view) { var query = await(from e in _dbContext.SupplierInvoices where e.SupplierInvoiceNumber == view.SupplierInvoiceNumber select e).FirstOrDefaultAsync <SupplierInvoice>(); if (query != null) { long supplierInvoiceId = query.SupplierInvoiceId; foreach (var detail in view.SupplierInvoiceDetailViews) { detail.SupplierInvoiceId = supplierInvoiceId; SupplierInvoiceDetail newDetail = new SupplierInvoiceDetail(); applicationViewFactory.MapSupplierInvoiceDetailEntity(ref newDetail, detail); var queryDetail = await(from e in _dbContext.SupplierInvoiceDetails where e.ItemId == detail.ItemId && e.SupplierInvoiceDetailId == newDetail.SupplierInvoiceDetailId select e).FirstOrDefaultAsync <SupplierInvoiceDetail>(); if (queryDetail == null) { _dbContext.Set <SupplierInvoiceDetail>().Add(newDetail); } } return(CreateProcessStatus.Insert); } return(CreateProcessStatus.Failed); }
public async Task <CreateProcessStatus> CreateSupplierInvoiceByView(SupplierInvoiceView view) { decimal amount = 0; try { //check if packing slip exists var query = await(from e in _dbContext.SupplierInvoices where e.SupplierInvoiceNumber == view.SupplierInvoiceNumber select e).FirstOrDefaultAsync <SupplierInvoice>(); if (query != null) { return(CreateProcessStatus.AlreadyExists); } foreach (var detail in view.SupplierInvoiceDetailViews) { amount += detail.ExtendedCost ?? 0; } view.Amount = amount; SupplierInvoice supplierInvoice = new SupplierInvoice(); applicationViewFactory.MapSupplierInvoiceEntity(ref supplierInvoice, view); base.AddObject(supplierInvoice); return(CreateProcessStatus.Insert); } catch (Exception ex) { throw new Exception(GetMyMethodName(), ex); } }