public async Task <IActionResult> PutOrder(int id, Order order) { try { var ord = _context.orders.Where(p => p.OrderId == order.OrderId).Include(p => p.OrderItem).SingleOrDefault(); if (ord != null) { //update order _context.Entry(ord).CurrentValues.SetValues(order); // Delete children foreach (var existingOrdItem in ord.OrderItem.ToList()) { if (!order.OrderItem.Any(c => c.OrderItemId == existingOrdItem.OrderItemId)) { _context.OrderItems.Remove(existingOrdItem); } } //update and insert orderitem foreach (var orderItemModel in order.OrderItem) { var ordItem = ord.OrderItem.Where(c => c.OrderItemId == orderItemModel.OrderItemId).SingleOrDefault(); if (ordItem != null) { //update orderitem _context.Entry(ordItem).CurrentValues.SetValues(orderItemModel); } else { //insert orderitem var newitem = new OrderItem { OrderItemId = orderItemModel.OrderItemId, Quantity = orderItemModel.Quantity, Amount = orderItemModel.Amount, FoodItemId = orderItemModel.FoodItemId, }; ord.OrderItem.Add(newitem); } } await _context.SaveChangesAsync(); } } catch (DbUpdateConcurrencyException) { if (!OrderExists(id)) { return(NotFound()); } else { throw; } } return(Ok()); }
public async Task <IActionResult> PutFoodItem(int id, FoodItem foodItem) { if (id != foodItem.FoodItemId) { return(BadRequest()); } _context.Entry(foodItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FoodItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutCustomer(int id, Customer customer) { if (id != customer.CustomerId) { return(BadRequest()); } _context.Entry(customer).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult Edit(MeniuClient meniuclient) { if (ModelState.IsValid) { db.Entry(meniuclient).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(meniuclient)); }
public ActionResult Edit(Chelner chelner) { if (ModelState.IsValid) { db.Entry(chelner).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(chelner)); }
public ActionResult Edit(Client client) { if (ModelState.IsValid) { db.Entry(client).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Chelner = new SelectList(db.Chelners, "Id", "ChelnerName", client.Chelner); ViewBag.Comanda = new SelectList(db.MeniuClients, "Id", "Meniu", client.Comanda); return(View(client)); }
public bool Update(Restaurant restaurant) { try { _db.Entry(restaurant).State = EntityState.Modified; _db.SaveChanges(); return(true); } catch { return(false); } }
public bool Update(Plate plate) { try { _db.Entry(plate).State = EntityState.Modified; _db.SaveChanges(); return(true); } catch { return(false); } }
public void Update(_Restaurant restaurant) { _context.Entry <_Restaurant>(restaurant).State = EntityState.Modified; }
public void Update(Plate plate) { _context.Entry <Plate>(plate).State = EntityState.Modified; }