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> AddToCart(int id, int count = 1) { CartB cartB = new CartB(_context, this.HttpContext); cartB.AddToCart(await _context.Product.FindAsync(id), count); return(RedirectToAction("Index")); }
public async Task <IActionResult> RemoveFromCart(int id) { CartB cartB = new CartB(_context, this.HttpContext); cartB.RemoveFromCart(await _context.Product.FindAsync(id)); return(RedirectToAction("Index")); }
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)); }
public async Task <IViewComponentResult> InvokeAsync() { CartB cartB = new CartB(_context, this.HttpContext); return(View("CartIconComponent", await cartB.GetCartElementsCount())); }