예제 #1
0
        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());
        }
예제 #2
0
        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));
 }
예제 #5
0
 public ActionResult Edit(Chelner chelner)
 {
     if (ModelState.IsValid)
     {
         db.Entry(chelner).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(chelner));
 }
예제 #6
0
 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));
 }
예제 #7
0
 public bool Update(Restaurant restaurant)
 {
     try
     {
         _db.Entry(restaurant).State = EntityState.Modified;
         _db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
예제 #8
0
 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;
 }
예제 #10
0
 public void Update(Plate plate)
 {
     _context.Entry <Plate>(plate).State = EntityState.Modified;
 }