예제 #1
0
        public ActionResult Edit(int id)
        {
            var service = CreateCigarMakerService();
            var detail  = service.GetCigarMakerById(id);
            var model   =
                new CigarMakerEdit
            {
                MakerName = detail.MakerName,
            };

            return(View(model));
        }
예제 #2
0
        public bool UpdateCigarMaker(CigarMakerEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .CigarMakers
                    .Single(e => e.MakerId == model.MakerId);
                if (entity.MakerName == model.MakerName)
                {
                    return(true);
                }

                {
                    entity.MakerId   = model.MakerId;
                    entity.MakerName = model.MakerName;
                }
                return(ctx.SaveChanges() == 1);
            }
        }
예제 #3
0
        public ActionResult Edit(int id, CigarMakerEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

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

            var service = CreateCigarMakerService();

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

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