public async Task <IActionResult> ConfirmOrder(ConfirmOrderView formModel) { ConfirmOrderView model = HttpContext.Session.Get <ConfirmOrderView>("orderConfirm"); if (model == null) { return(RedirectToAction("ShowCart", "Cart")); } var date = DateTime.Now; Order order = new Order { OrderDate = date, CustomerId = model.Customer.Id, OrderStatus = OrderStatus.Ordered, EndPointCity = Request.Form["EndPointCity"], EndPointStreet = formModel.EndPointStreet, CommonPrice = Convert.ToInt32(Request.Form["commonPrice"]) }; unitOfWork.Orders.SetProducts(await GetGoodsAsync(model.Goods), order); await unitOfWork.Orders.Create(order); foreach (var good in await GetGoodsAsync(model.Goods)) { await this.RemoveFromCart(good.Id); } await unitOfWork.SaveAsync(); return(RedirectToAction("ShowCart")); }
public async Task <IActionResult> ConfirmGoods(List <string> goodCount) { int customerId = unitOfWork.Customers.GetAll().Where(c => c.Email == User.Identity.Name).First().Id; Customer customer = await unitOfWork.Customers.Get(customerId); var goods = HttpContext.Session.Get <List <OrderPart> >("goodsConfirm"); var modelGoods = new List <OrderPart>(); if (goods == null) { return(RedirectToAction("ShowCart", "Cart")); } for (int i = 0; i < goodCount.Count; i++) { if (goodCount[i] == "0") { continue; } modelGoods.Add(new OrderPart { Good = goods[i].Good, Count = Convert.ToInt32(goodCount[i]), GoodId = goods[i].Good.Id }); } if (modelGoods.Count != 0) { ConfirmOrderView model = new ConfirmOrderView { Country = new Country(), Customer = customer, Goods = modelGoods, Storages = await this.GetStorages(modelGoods), Count = Convert.ToInt32(Request.Form["goodCommonCount"]), CommonPrice = Convert.ToInt32(Request.Form["commonPrice"]) }; HttpContext.Session.Set("orderConfirm", model); return(View("ConfirmOrder", model)); } else { ViewBag.Message = "You cannot buy nothing!"; return(View("ErrorPage")); } }