public ActionResult Edit(int id)
        {
            var service = CreateGhostService();
            var detail  = service.GetGhostById(id);
            var model   =
                new GhostEdit
            {
                GhostId = detail.GhostId,
                Title   = detail.Title,
                Content = detail.Content
            };

            return(View(model));
        }
Beispiel #2
0
    public bool UpdateGhost(GhostEdit model)
    {
        using (var ctx = new ApplicationDbContext())
        {
            var entity =
                ctx
                .Ghosts
                .Single(e => e.GhostId == model.GhostId && e.OwnerId == _userId);

            entity.Title       = model.Title;
            entity.Content     = model.Content;
            entity.ModifiedUtc = DateTimeOffset.UtcNow;

            return(ctx.SaveChanges() == 1);
        }
    }
        public ActionResult Edit(int id, GhostEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

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

            var service = CreateGhostService();

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

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