예제 #1
0
        //GET: Gecko/Edit
        public ActionResult Edit(int id)
        {
            var service = CreateGeckoService();
            var detail  = service.GetGeckoById(id);
            var model   =
                new GeckoEdit
            {
                GeckoID        = detail.GeckoID,
                GeckoName      = detail.GeckoName,
                GeckoSexIsMale = detail.GeckoSexIsMale,
                GeckoWeight    = detail.GeckoWeight,
                HatchDate      = detail.HatchDate
            };

            return(View(model));
        }
예제 #2
0
        public bool UpdateGecko(GeckoEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Geckos
                    .Single(e => e.GeckoID == model.GeckoID && e.OwnerID == _userID);

                entity.GeckoName      = model.GeckoName;
                entity.GeckoSexIsMale = model.GeckoSexIsMale;
                entity.GeckoWeight    = model.GeckoWeight;
                entity.HatchDate      = model.HatchDate;

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

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

            var service = CreateGeckoService();

            if (service.UpdateGecko(model))
            {
                TempData["SaveResult"] = "Gecko information was updated.";
                return(RedirectToAction("Index"));
            }

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