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

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

            var service = CreateReplyService();
            var detail  = service.GetReplyByID(replyID);

            if (service.UpdateReply(model))
            {
                TempData["SaveResult"] = "Your reply was updated.";
                return(RedirectToAction("PostRepliesIndex", new { postID = detail.PostID }));
            }

            ModelState.AddModelError("", "Your reply could not be updated.");
            return(View(model));
        }
コード例 #2
0
        public bool UpdateReply(PostReplyEdit model)
        {
            var entity = _dbContext.Replies
                         .Single(x => x.ReplyID == model.ReplyID);

            entity.ReplyContent = model.ReplyContent;
            // May add in future
            //entity.ModifiedUtc = DateTimeOffset.UtcNow;

            return(_dbContext.SaveChanges() == 1);
        }
コード例 #3
0
        // GET: /PostReply/Edit/{id}
        public ActionResult Edit(int id)
        {
            var service = CreateReplyService();
            var detail  = service.GetReplyByID(id);
            var model   = new PostReplyEdit
            {
                ReplyID      = detail.ReplyID,
                ReplyContent = detail.ReplyContent,
            };

            ViewData["postID"] = detail.PostID;

            if (service.ValidateUser(id) == true)
            {
                return(View(model));
            }

            return(View("ValidationFailed"));
        }