public void CreateNewOrder(string cartId) { var currentTime = DateTime.Now; // Create New Order var newOrder = new Order { Total = 0, OrderCompleted = false, DateCreated = currentTime, OrderReference = cartId }; _context.Add(newOrder); _context.SaveChanges(); }
public void AddToCart(MenuItem menuItem, int quantity, string cartId) { // Check Orders to see if item exist var orderCartItem = _context.CartItems .SingleOrDefault(asset => asset.MenuItem.MenuItemId == menuItem.MenuItemId && asset.CartId == cartId); // If Item does not exist add to the Table if (orderCartItem == null) { orderCartItem = new CartItem { MenuItem = menuItem, Quantity = quantity, CartId = cartId }; _context.Add(orderCartItem); } // If Item exist add new Quantity to existing entry else { _context.Update(orderCartItem); orderCartItem.Quantity += quantity; } _context.SaveChanges(); }
public void AddRating(int menuItemId, int rating) { var menuItem = GetMenuItem(menuItemId); var entry = new Rating { MenuItem = menuItem, Value = rating }; _context.Add(entry); _context.SaveChanges(); }