コード例 #1
0
        public ActionResult Edit(int id, IdeaEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

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

            var service = CreateIdeaService();

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

            ModelState.AddModelError("", "Your Idea could not be updated.")

            return(View());
        }
コード例 #2
0
        public ActionResult Edit(int id)
        {
            var service = CreateIdeaService();
            var detail  = service.GetIdeaById(id);
            var model   =
                new IdeaEdit
            {
                IdeaId          = detail.IdeaId,
                IdeaTitle       = detail.IdeaTitle,
                IdeaDescription = detail.IdeaDescription
            };

            return(View(model));
        }
コード例 #3
0
        public bool UpdateIdea(IdeaEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Ideas
                    .Single(e => e.IdeaId == model.IdeaId && e.OwnerId == _userId);

                entity.IdeaTitle        = model.IdeaTitle;
                entity.IdeaDescription  = model.IdeaDescription;
                entity.DateIdeaModified = DateTimeOffset.UtcNow;

                return(ctx.SaveChanges() == 1);
            }
        }