示例#1
0
        //UPDATE
        public bool UpdateGlaze(GlazeEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Glaze
                    .Single(e => e.GlazeID == model.GlazeID && e.OwnerId == _userId);

                entity.GlazeID           = model.GlazeID;
                entity.GlazeName         = model.GlazeName;
                entity.Description       = model.Description;
                entity.ListOfIngredients = (ICollection <Ingredient>)model.IngredientList;
                entity.MinCone           = model.MinCone;
                entity.MaxCone           = model.MaxCone;
                entity.MainColor         = model.MainColor;
                entity.Atmosphere        = model.Atmosphere;
                entity.Surface           = model.Surface;
                entity.Opacity           = model.Opacity;
                entity.FoodSafe          = model.FoodSafe;
                entity.ModifiedDate      = DateTimeOffset.UtcNow;

                return(ctx.SaveChanges() == 1);
            }
        }
        //EDIT --------------------------------------------------------------------------
        public ActionResult Edit(int id)
        {
            var service = CreateGlazeService();
            var detail  = service.GetGlazeById(id);
            var model   =
                new GlazeEdit
            {
                GlazeID        = detail.GlazeID,
                GlazeName      = detail.GlazeName,
                IngredientList = detail.IngredientList,
                Description    = detail.Description,
                Atmosphere     = detail.Atmosphere,
                MinCone        = detail.MinCone,
                MaxCone        = detail.MaxCone,
                Opacity        = detail.Opacity,
                Surface        = detail.Surface,
                MainColor      = detail.MainColor,
                FoodSafe       = detail.FoodSafe,
            };

            return(View(model));
        }
        public ActionResult Edit(int id, GlazeEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

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

            var service = CreateGlazeService();

            if (service.UpdateGlaze(model))
            {
                TempData["SaveResult"] = "Your glaze was updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Your glaze could not be updated.");
            return(View(model));
        }