public IActionResult Order(ShippingDetail shippingDetail) { if (Carte.Lines.Count() == 0) { ModelState.AddModelError("Empty", "Sorry, your carte is empty!"); } if (ModelState.IsValid) { shippingDetail.FullName = _dBaseTechProduct.dbUsers.FirstOrDefault(user => user.FullName == User.FindFirst("FullName").Value).FullName; shippingDetail.orderDate = System.DateTime.Now; shippingDetail.buyer = _dBaseTechProduct.dbUsers.FirstOrDefault(user => user.FullName == User.FindFirst("FullName").Value); shippingDetail.state = false; shippingDetail.orders = (List <CarteLine>)Carte.Lines; _dBaseTechProduct.dbOrders.Add(shippingDetail); _dBaseTechProduct.SaveChanges(); Carte.Clear(); ViewData.Add("CitiesList", getCitiesList()); return(RedirectToAction(nameof(Complited))); } else { ModelState.AddModelError("Empty", "Gov =" + shippingDetail.Gouvernerat); } ViewData.Add("CitiesList", getCitiesList()); return(View(shippingDetail)); }
public IActionResult Order(ShippingDetail shippingDetail) { if (Carte.Lines.Count() == 0) { ModelState.AddModelError("Empty", "Sorry, your carte is empty!"); } if (ModelState.IsValid) { Carte.Clear(); return(RedirectToAction(nameof(Complited))); } else { return(View(shippingDetail)); } }