示例#1
0
        public ActionResult Edit(int id)
        {
            var service = CreateNestService();
            var detail  = service.GetNestById(id);
            var model   = new NestEdit
            {
                LoggerId   = detail.LoggerId,
                OwnerId    = detail.OwnerId,
                Site       = detail.Site,
                Materials  = detail.Materials,
                Altitude   = detail.Altitude,
                Eggs       = detail.Eggs,
                Hatchlings = detail.Hatchlings,
                NestId     = detail.NestId,
            };

            return(View(model));
        }
示例#2
0
        public bool UpdateNest(NestEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = ctx.Nests.Single(e => e.NestId == model.NestId && e.OwnerId == _userId);

                entity.NestId = model.NestId;
                //entity.OwnerId = model.OwnerId;
                entity.LoggerId   = model.LoggerId;
                entity.Site       = model.Site;
                entity.Altitude   = model.Altitude;
                entity.Eggs       = model.Eggs;
                entity.Hatchlings = model.Hatchlings;
                //entity.CreatedUtc = DateTimeOffset.UtcNow;
                entity.ModifiedUtc = DateTimeOffset.UtcNow;

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

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

            var service = CreateNestService();

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

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