public async Task <IActionResult> PutUsers(long id, Users users) { if (id != users.Id) { return(BadRequest()); } _context.Entry(users).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UsersExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult Edit([Bind(Include = "Id,Title,City")] Restaurant restaurant) { if (ModelState.IsValid) { db.Entry(restaurant).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(restaurant)); }
public ActionResult Edit([Bind(Include = "Id,Comment,Rating")] Review review) { if (ModelState.IsValid) { db.Entry(review).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(review)); }
public async Task <ActionResult <Bills> > UpdateOrders(long tableId, List <OrderDto> orders) { if (!TablesExists(tableId)) { return(NotFound()); } var bill = await _context.Bills.Where(b => b.TableId == tableId && (b.Flag == 0 || b.Flag == null)).FirstOrDefaultAsync(); if (bill == null) { return(NotFound()); } foreach (OrderDto orderDto in orders) { var order = new Orders() { BillId = bill.Id, FoodId = orderDto.FoodId, Quantity = orderDto.Quantity, PaymentAmount = orderDto.Quantity * ((long)await _context.Foods.Where(f => f.Id == orderDto.FoodId).Select(f => f.Price).FirstOrDefaultAsync()) }; if (await _context.Orders.AnyAsync(o => o.BillId == order.BillId && o.FoodId == order.FoodId)) { _context.Entry(order).State = EntityState.Modified; } else { await _context.Orders.AddAsync(order); } } await _context.SaveChangesAsync(); bill.TotalPayment = _context.Orders.Where(o => o.BillId == bill.Id).Sum(o => o.PaymentAmount); _context.Entry(bill).State = EntityState.Modified; await _context.SaveChangesAsync(); return(bill); }