Exemple #1
0
        public bool UpdateWine(WineEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = ctx.Wines
                             .Single(e => e.WineId == model.WineId && e.OwnerId == _userId);

                entity.Brand          = model.Brand;
                entity.SubBrand       = model.SubBrand;
                entity.WineVarietal   = model.WineVarietal;
                entity.Region         = model.Region;
                entity.Year           = model.Year;
                entity.CodeForTasting = model.CodeForTasting;

                return(ctx.SaveChanges() == 1);
            }
        }
Exemple #2
0
        public ActionResult Edit(int id)
        {
            var service = CreateWineService();
            var detail  = service.GetWineById(id);
            var model   = new WineEdit
            {
                OwnerId        = detail.OwnerId,
                WineId         = detail.WineId,
                TastingId      = detail.TastingId,
                Brand          = detail.Brand,
                SubBrand       = detail.SubBrand,
                WineVarietal   = detail.WineVarietal,
                Region         = detail.Region,
                Year           = detail.Year,
                CodeForTasting = detail.CodeForTasting
            };

            return(View(model));
        }
Exemple #3
0
        public ActionResult Edit(int id, WineEdit model, int tastingId)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

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

            var service = CreateWineService();

            if (service.UpdateWine(model))
            {
                TempData["SaveResult"] = "Your Wine was updated.";
                return(RedirectToAction("Index", "Wine", new { tastingId }));
            }

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