public async Task <IActionResult> Create([Bind("CategoryId,CategoryName,CategoryDescription")] Category category) { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Create([Bind("ProductId,Name,Description,Price,ImageUrl,ImageThumbnailUrl,IsOnSale,CategoryId")] Product product) { product.DateAdded = DateTime.Now; if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(product)); }
public void CreateOrder(Order order) { order.OrderDate = DateTime.Now; order.OrderTotal = _shoppingCart.GetShoppingCartTotal(); _context.Add(order); _context.SaveChanges(); var shoppingCartItems = _shoppingCart.GetShoppingCartItems(); foreach (var shoppingCartItem in shoppingCartItems) { var OrderItem = new OrderItem { Price = shoppingCartItem.Product.Price, ProductId = shoppingCartItem.Product.ProductId, OrderId = order.OrderId }; _context.OrderItem.Add(OrderItem); } _context.SaveChanges(); }