Esempio n. 1
0
        public ActionResult Edit(int id)
        {
            var service = new RootService();
            var detail  = service.GetRootById(id);
            var model   =
                new RootListItem
            {
                Id          = detail.Id,
                RootName    = detail.RootName,
                NotesOnRoot = detail.NotesOnRoot
            };

            return(View(model));
        }
Esempio n. 2
0
        public bool UpdateRoot(RootListItem model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Roots
                    .Single(e => e.Id == model.Id);

                entity.RootName    = model.RootName;
                entity.NotesOnRoot = model.NotesOnRoot;

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

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

            var service = new RootService();

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

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