// GET: Order/Edit/5 public ActionResult Edit(int id) { OrderStatusRepository orderStatusRepo = new OrderStatusRepository(); CustomerRepository custRepo = new CustomerRepository(); PurchaseOrderRepository purchaseOrder = new PurchaseOrderRepository(); PurchaseItemsRepository purchaseItemsRepo = new PurchaseItemsRepository(); SKURepository skuRepo = new SKURepository(); var list = new List <ItemListViewModel>(); var order = purchaseOrder.GetPurchaseOrders().Find(m => m.Id == id); var purchaseItems = purchaseItemsRepo.GetPurchaseItems().Where(x => x.PurchaseOrderId == order.Id).ToList(); var skus = skuRepo.GetSKUs(); var itemList = from purchaseItem in purchaseItems join sku in skus on purchaseItem.SKUId equals sku.Id select new { SKU = sku.Name, Quantity = purchaseItem.Quantity, Price = purchaseItem.Price, PurchaseItemId = purchaseItem.Id }; foreach (var item in itemList) { list.Add( new ItemListViewModel { SKU = item.SKU, Quantity = item.Quantity, Price = item.Price, PurchaseItemId = item.PurchaseItemId }); } order.AmountDue = purchaseItemsRepo.GetPurchaseItems().Where(x => x.PurchaseOrderId == order.Id).Sum(x => x.Price); var viewModel = new OrderTakingEditForm() { PurchaseOrder = order, OrderStatuses = orderStatusRepo.GetOrderStatus(), Customers = custRepo.GetCustomers(), Items = list }; Session["PurchaseOrderId"] = order.Id; return(View(viewModel)); }
public bool Update(OrderTakingEditForm purchaseOrder) { int i = 0; try { using (SqlConnection con = new SqlConnection(DbConn)) { con.Open(); SqlCommand cmd = new SqlCommand("sp_UpdatePurchaseOrderRecord", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@DateOfDelivery", Convert.ToDateTime(purchaseOrder.PurchaseOrder.DateOfDelivery)); cmd.Parameters.AddWithValue("@Status", purchaseOrder.PurchaseOrder.Status); cmd.Parameters.AddWithValue("@CustomerId", purchaseOrder.PurchaseOrder.CustomerId); cmd.Parameters.AddWithValue("@AmountDue", purchaseOrder.PurchaseOrder.AmountDue); cmd.Parameters.AddWithValue("@PurchaseOrderId", purchaseOrder.PurchaseOrder.Id); i = cmd.ExecuteNonQuery(); } } catch (Exception ex) { throw ex; } if (i >= 1) { return(true); } else { return(false); } }
public ActionResult Edit(OrderTakingEditForm order) { try { OrderStatusRepository orderStatusRepo = new OrderStatusRepository(); CustomerRepository custRepo = new CustomerRepository(); PurchaseItemsRepository purchaseItemsRepo = new PurchaseItemsRepository(); PurchaseOrderRepository purchaseOrderRepo = new PurchaseOrderRepository(); SKURepository skuRepo = new SKURepository(); if (!ModelState.IsValid) { var items = purchaseItemsRepo.GetPurchaseItems().Where(x => x.PurchaseOrderId == order.PurchaseOrder.Id).ToList(); var skus = skuRepo.GetSKUs(); var list = new List <ItemListViewModel>(); var itemList = from purchaseItem in items join sku in skus on purchaseItem.SKUId equals sku.Id select new { SKU = sku.Name, Quantity = purchaseItem.Quantity, Price = purchaseItem.Price, PurchaseItemId = purchaseItem.Id }; foreach (var item in itemList) { list.Add( new ItemListViewModel { SKU = item.SKU, Quantity = item.Quantity, Price = item.Price, PurchaseItemId = item.PurchaseItemId }); } var viewModel = new OrderTakingEditForm() { Customers = custRepo.GetCustomers(), OrderStatuses = orderStatusRepo.GetOrderStatus(), PurchaseOrder = order.PurchaseOrder, Items = list }; return(View(viewModel)); } order.PurchaseOrder.AmountDue = 0; var purchaseItems = purchaseItemsRepo.GetPurchaseItems().Where(x => x.PurchaseOrderId == order.PurchaseOrder.Id);; foreach (var item in purchaseItems) { order.PurchaseOrder.AmountDue += item.Price; } purchaseOrderRepo.Update(order); return(RedirectToAction("Index")); } catch { return(View()); } }