Exemplo n.º 1
0
        // Update -- Menu Item
        public bool UpdateMenuItem(MenuItemEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .MenuItems
                    .Single(e => e.MenuItemId == model.MenuItemId);

                entity.Name            = model.Name;
                entity.Description     = model.Description;
                entity.Category        = model.Category;
                entity.Price           = model.Price;
                entity.ServingsInStock = model.ServingsInStock;

                // Just added this
                if (entity.ServingsInStock > 0 && entity.ServingsInStock >= 1)
                {
                    entity.IsAvailable = true;
                }
                else
                {
                    entity.IsAvailable = false;
                }


                return(ctx.SaveChanges() == 1);
            }
        }
Exemplo n.º 2
0
        public IHttpActionResult Put(MenuItemEdit menuItem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreateMenuItemService();

            if (!service.UpdateMenuItem(menuItem))
            {
                return(InternalServerError());
            }
            return(Ok());
        }
Exemplo n.º 3
0
 public bool UpdateMenuItem(MenuItemEdit model)
 {
     using (var ctx = new ApplicationDbContext())
     {
         var entity =
             ctx
             .MenuItems
             .Single(e => e.MenuItemId == model.MenuItemId && e.OwnerId == _userId);
         entity.MenuItemId          = model.MenuItemId;
         entity.RestaurantId        = model.RestaurantId;
         entity.MenuItemName        = model.MenuItemName;
         entity.MenuItemDescription = model.MenuItemDescription;
         entity.MenuItemPrice       = model.MenuItemPrice;
         entity.MenuItemPicture     = model.MenuItemPicture;
         return(ctx.SaveChanges() == 1);
     }
 }
Exemplo n.º 4
0
        // GET: MenuItem/Edit/{id} aka Update
        public ActionResult Edit(int id)
        {
            var service = CreateMenuItemService();
            var detail  = service.GetMenuItemById(id);
            var model   =
                new MenuItemEdit
            {
                MenuItemId      = detail.MenuItemId,
                Name            = detail.Name,
                Description     = detail.Description,
                Category        = detail.Category,
                Price           = detail.Price,
                ServingsInStock = detail.ServingsInStock
            };

            return(View(model));
        }
Exemplo n.º 5
0
        public ActionResult Edit(int id, MenuItemEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.MenuItemId != id)
            {
                ModelState.AddModelError("", "Menu Item Id Mismatch");
                return(View(model));
            }

            var service = CreateMenuItemService();

            if (service.UpdateMenuItem(model))
            {
                TempData["SaveResult"] = "Your Menu Item Was Updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Your Menu Item Could Not Be Updated.");
            return(View(model));
        }