//Метод сохранения заказов public void SaveKfcOrder(KfcOrder order) { context.AttachRange(order.Lines.Select(l => l.Kfc)); if (order.Id == 0) { context.KfcOrders.Add(order); } context.SaveChanges(); }
public IActionResult MarkShipped(int id) { KfcOrder kfcOrder = repository.KfcOrders.FirstOrDefault(o => o.Id == id); if (kfcOrder != null) { kfcOrder.Shipped = true; repository.SaveKfcOrder(kfcOrder); } return(RedirectToAction(nameof(ListOrder))); }
public IActionResult Checkout(KfcOrder order) { if (cart.Lines.Count() == 0) { ModelState.AddModelError("", "Извините ваша корзина пуста"); } if (ModelState.IsValid) { order.Lines = cart.Lines.ToArray(); repository.SaveKfcOrder(order); cart.Clear(); return(RedirectToAction(nameof(Completed))); } else { return(View(order)); } }