// GET: FoodOrders public ActionResult Index() { var UserName = User.Identity.GetUserName(); return(View(_productOrdersRepository.Find(x => x.UserEmail == UserName && x.OrderStatus != "Checked Out"))); }
public void AddItemToCart(int id, string username) { shoppingCartID = GetCartID(); ProductOrder = new ProductOrder(); var item = _itemRepository.GetById(id); if (item != null) { //FoodOrder var foodItem = _productOrderRepository.Find(x => x.cart_id == shoppingCartID && x.item_id == item.ItemCode).FirstOrDefault(); var cartItem = _cartItemRepository.Find(x => x.cartId == shoppingCartID && x.ItemdId == item.ItemCode).FirstOrDefault(); if (cartItem == null) { var cart = _cartRepository.GetById(shoppingCartID); if (cart == null) { _cartRepository.Insert(model: new Cart() { CartID = shoppingCartID, date_created = DateTime.Now }); //dataContext.SaveChanges(); } _cartItemRepository.Insert(model: new CartItem() { Id = Guid.NewGuid().ToString(), cartId = shoppingCartID, ItemdId = item.ItemCode, quantity = 1, price = item.Price, UserEmail = username } ); //food.item_id = cartItem.item_id; //food.cart_id = cartItem.cart_id; //food.quantity = cartItem.quantity; //food.UserEmail = cartItem.UserEmail; //dataContext.FoodOrders.Add(food); _productOrderRepository.Insert(model: new ProductOrder() { cart_item_id = Guid.NewGuid().ToString(), cart_id = shoppingCartID, item_id = item.ItemCode, quantity = 1, price = item.Price, ItemName = item.Name, UserEmail = username, Picture = item.Picture, OrderDate = DateTime.Now.Date.ToString(), OrderStatus = "Not Cheked Out" }); } else { cartItem.quantity++; foodItem.quantity++; } //dataContext.SaveChanges(); } }