public async Task <IActionResult> Create([Bind("MenuItemID,Title,Description,Price,DiscountPrice,Category,IsAvailable,IsSpecialty,Image")] MenuItem menuItem) { if (ModelState.IsValid) { _context.Add(menuItem); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(menuItem)); }
public async Task <IActionResult> Create([Bind("OrderID,IsPlaced,IsPrepared,IsPaid,TableID")] Order order) { if (ModelState.IsValid) { _context.Add(order); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["TableID"] = new SelectList(_context.Tables, "TableID", "TableID", order.TableID); return(View(order)); }
public async Task <IActionResult> writeItem(int?itemid, string name, int score, string comment, int payment) { Review o = new Review { CustomerName = name, Time = System.DateTime.Now, Description = comment, Score = score, MenuItemID = (int)itemid, }; _context.Reviews.Add(o); await _context.SaveChangesAsync(); //calculate the total score for this menu item and save it in menuitem var item = await _context.MenuItems .AsNoTracking() .Include(m => m.Reviews) .SingleOrDefaultAsync(m => m.MenuItemID == itemid); int scores = 0; int no = 0; foreach (var i in item.Reviews) { scores += i.Score; no++; } double totalScore = ((double)scores / no); var scoreToUpdate = await _context.MenuItems.SingleOrDefaultAsync(t => t.MenuItemID == itemid); scoreToUpdate.Score = (decimal)totalScore; await _context.SaveChangesAsync(); var menuItem = await _context.MenuItems.SingleAsync(m => m.MenuItemID == itemid); ViewData["Added"] = 1; ViewData["customer"] = name; ViewData["pid"] = payment; return(View(menuItem)); }
//Marks a table as unavailabel // GET: Tables/Seat/5 public async Task <IActionResult> Seat(int?id) { if (id == null) { return(NotFound()); } var tableToUpdate = await _context.Tables.SingleOrDefaultAsync(t => t.TableID == id); tableToUpdate.IsEmpty = false; try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { ModelState.AddModelError("", "Unable to update table."); } return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> AddItem(int?TableId, int Quantity, int?SideId1, int?SideId2, int ItemId, string Comment) { byte[] orderIdBytes; int orderId; if (!HttpContext.Session.TryGetValue("OrderID", out orderIdBytes)) // no order id in the session. We will need the table id to create one. { Order o = new Order { IsPaid = false, IsPlaced = false, IsPrepared = false, TableID = (int)TableId }; _context.Orders.Add(o); await _context.SaveChangesAsync(); orderId = o.OrderID; HttpContext.Session.Set("OrderID", Encoding.ASCII.GetBytes(orderId.ToString())); } else { orderId = int.Parse(Encoding.ASCII.GetString(orderIdBytes)); } OrderItem item = new OrderItem { MenuItemID = ItemId, OrderID = orderId, Quantity = Quantity, Comment = Comment }; _context.OrderItems.Add(item); if (SideId1 != null) { OrderItem side1 = new OrderItem { MenuItemID = (int)SideId1, OrderID = orderId, Quantity = Quantity }; _context.OrderItems.Add(side1); } if (SideId2 != null) { OrderItem side2 = new OrderItem { MenuItemID = (int)SideId2, OrderID = orderId, Quantity = Quantity }; _context.OrderItems.Add(side2); } await _context.SaveChangesAsync(); var menuItem = await _context.MenuItems.Include(m => m.Reviews).SingleAsync(m => m.MenuItemID == ItemId); ViewData["Added"] = 1; ViewData["OrderID"] = orderId; return(View(menuItem)); }