public void Create(AddPurchaseOrderViewModel model) { var entity = this.mapper.Map <PurchaseOrder>(model); entity.TotalAmount = model.Price * model.Quantity; this.purchaseOrderRepository.Create(entity); this.purchaseOrderRepository.SaveChanges(); }
public ActionResult New() { var model = new AddPurchaseOrderViewModel { Suppliers = AutoMapper.Mapper.Map <List <SupplierModel> >(supplierService.GetSuppliers(1)), Products = AutoMapper.Mapper.Map <List <ProductModel> >(productService.GetProductItems(null)), }; return(View("New", model)); }
public ActionResult Save(AddPurchaseOrderViewModel model) { InvoiceDto invoice; try { invoice = invoiceService.SaveNewPurchaseOrder(model.SelectedSupplierId); model.InvoiceId = invoice.Id; foreach (var product in model.InvoiceProducts) { try { invoiceService.SaveNewPurchaseOrderProduct(invoice.Id, product.ProductId, product.TotalCost, product.OrderedQuantity); product.IsSynced = true; } catch (Exception e) { product.IsSynced = false; product.SyncMessage = e.Message; } } if (model.InvoiceProducts.Any(x => x.IsSynced == false)) { throw new ApplicationException("Unable to save Invoice."); } } catch (Exception e) { TempData["Toast"] = e.Message; TempData["ToastType"] = "Error"; model.Suppliers = AutoMapper.Mapper.Map <List <SupplierModel> >(supplierService.GetSuppliers(1)); model.Products = AutoMapper.Mapper.Map <List <ProductModel> >(productService.GetProductItems(null)); return(View("New", model)); } TempData["ToastType"] = "Success"; TempData["Toast"] = "Invoice Saved Successfully."; return(Index()); }
public IActionResult Create(AddPurchaseOrderViewModel model) { this.purchaseOrderService.Create(model); this.SetSuccessMessage("Purchase Order added."); return(this.RedirectToAction(nameof(CustomerController.Details), "Customer", new { Id = model.CustomerId })); }