Exemplo n.º 1
0
        public ActionResult Edit(int id)
        {
            var service = CreateSightingService();
            var detail  = service.GetSightingByID(id);
            var model   =
                new SightingEdit
            {
                SightingID = detail.SightingID,
                TimeSeen   = detail.TimeSeen
            };

            return(View(model));
        }
Exemplo n.º 2
0
        public bool UpdateSighting(SightingEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Sightings
                    .Single(e => e.SightingID == model.SightingID);

                entity.TimeSeen = model.TimeSeen;

                return(ctx.SaveChanges() == 1);
            }
        }
Exemplo n.º 3
0
        public ActionResult Edit(int id, SightingEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

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

            var service = CreateSightingService();

            if (service.UpdateSighting(model))
            {
                TempData["SaveResult"] = "The sighting was updated.";
                return(RedirectToAction("Index"));
            }

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