public ActionResult Create(OrderDetail orderdetail) { if (ModelState.IsValid) { db.OrderDetails.Add(orderdetail); db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.OrderId = new SelectList(db.Orders, "OrderId", "OrderId", orderdetail.OrderId); return View(orderdetail); }
private Order ProcessTheOrder(Cart cart, ShippingDetails shippingDetails) { var order = new Order(); var orderDetailsList = new List<OrderDetail>(); try { foreach (var item in cart.Lines) { var orderDetail = new OrderDetail { OrderId = order.OrderId, ProductName = item.Product.Name, Quantity = item.Quantity, UnitPrice = item.Product.Price }; order.TotalCost += orderDetail.UnitPrice*orderDetail.Quantity; //TODO: Make Unit Test orderDetailsList.Add(orderDetail); } } catch (Exception) { // TODO: Add HttpException handling in place of Exception below throw new Exception("Erorr building list of oder details -> cart.Lines was probably null."); } var firstCartLineProduct = cart.Lines.FirstOrDefault(); int establishmentId = firstCartLineProduct.Product.EstablishmentId; order.OrderDetails = orderDetailsList; order.EstablishmentId = establishmentId; order.CustomerName = shippingDetails.Name; order.TimeProcessed = DateTime.Now; return order; }
public ActionResult Edit(OrderDetail orderdetail) { if (ModelState.IsValid) { db.Entry(orderdetail).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.OrderId = new SelectList(db.Orders, "OrderId", "OrderId", orderdetail.OrderId); return View(orderdetail); }