public void Create(Order order) { if (order != null) { Context.Orders.Add(order); } }
public ActionResult Create(MakeOrderViewModel model) { if (ModelState.IsValid) { Order order = new Order { OrderDate = DateTime.Now, AddressId = model.SelectedAddress, AdditionalInfo = model.AdditionalInfo, IsDeleted = false, Paid = false, UserId = AccountHelper.GetLoggedUserId(), Products = new List<OrderedProduct>() }; List<CartItemViewModel> products; if (!CookieHelper.TryReadCookie<List<CartItemViewModel>>( cartCookieName, cookieProductsField, out products)) { products = new List<CartItemViewModel>(); } foreach (var item in products) { order.Products.Add(new OrderedProduct { Order = order, Price = item.Price, ProductId = item.ProductId, Quantity = item.Quantity }); } OrderManager.Create(order); OrderManager.Save(); CookieHelper.DeleteCookie(cartCookieName); return View("Index", GetUserOrders()); } return View(model); }