public async Task <IActionResult> Create([Bind("Id,Login,FirstName,LastName,Address")] Order order) { if (ModelState.IsValid) { order.CreatedAt = DateTime.Now; await _context.AddAsync(order); CartB cartB = new CartB(_context, this.HttpContext); var elements = await cartB.GetCartElements(); foreach (var element in elements) { var orderElement = new OrderElement() { ProductId = element.ProductId, OrderId = order.Id, Price = element.Product.Price, Count = element.Count }; await _context.OrderElement.AddAsync(orderElement); } order.Sum = await cartB.GetCartSum(); cartB.ClearCart(); await _context.SaveChangesAsync(); return(RedirectToAction("Details", new { id = order.Id })); } return(View(order)); }
public async Task <IActionResult> Index() { CartB cartB = new CartB(_context, this.HttpContext); var cartDetails = new CartDetails() { CartElements = await cartB.GetCartElements(), CartSum = await cartB.GetCartSum() }; return(View(cartDetails)); }