public IHttpActionResult Put([FromUri] int id, [FromBody] CommentEdit updatedComment)

        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreateCommentService();

            if (!service.UpdateComment(updatedComment, id))
            {
                return(InternalServerError());
            }
            return(Ok());
        }
        // Update Comment by Id
        public bool UpdateComment(CommentEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Comments
                    .Single(e => e.CommentId == model.CommentId && e.Id == _userId.ToString());

                entity.CommentText = model.CommentText;
                entity.ModifiedUtc = DateTimeOffset.UtcNow;

                return(ctx.SaveChanges() == 1);
            }
        }
Example #3
0
        public bool UpdateComment(CommentEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Comments
                    .Single(e => e.CommentId == model.CommentId);

                entity.CommentId = model.CommentId;
                entity.Content   = model.Content;

                return(ctx.SaveChanges() == 1);
            }
        }
        public IHttpActionResult Put(CommentEdit comment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreateCommentService();

            if (!service.UpdateComment(comment))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
Example #5
0
 public ActionResult Edit(CommentEdit comment, int id)
 {
     if (ModelState.IsValid)
     {
         var service = CreateCommentService().UpdateComment(comment, id);
         if (service)
         {
             return(RedirectToAction("Index", "Home"));
         }
         else
         {
             return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
         }
     }
     return(View(comment));
 }
Example #6
0
        public bool UpdateComment(CommentEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var commentEntity = ctx.Comments.Single(p => p.Id == model.Id && p.ApplicationUserId == _userId.ToString());
                if (commentEntity == null)
                {
                    return(false);
                }

                commentEntity.Text        = model.Text;
                commentEntity.ModifiedUtc = DateTimeOffset.UtcNow;

                return(ctx.SaveChanges() == 1);
            }
        }
Example #7
0
        public bool UpdateComment(CommentEdit model, int id)
        {
            var userInfoService = new UserInfoService(_userID);
            var getUser         = userInfoService.GetUsersByID(_userID);
            var username        = getUser.Username;

            using (var ctx = new ApplicationDbContext())
            {
                var entity = ctx
                             .Comments_Reactions
                             .Single(e => e.Id == _userID && e.CommentID == id);

                entity.CommentText  = model.CommentText;
                entity.DateModified = DateTimeOffset.UtcNow;

                return(ctx.SaveChanges() == 1);
            }
        }
Example #8
0
        public bool UpdateComment(CommentEdit comment, int id)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Comments
                    .SingleOrDefault(e => e.Id == id && e.Author == _userId);
                if (entity == null)
                {
                    return(false);
                }


                entity.Text = comment.Text;

                return(ctx.SaveChanges() >= 1);
            }
        }
Example #9
0
        public IHttpActionResult EditComment(CommentEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            CommentService service = CreateCommentService();

            try
            {
                if (!service.EditComment(model))
                {
                    return(InternalServerError());
                }
                return(Ok());
            }
            catch (System.InvalidOperationException)
            {
                return(BadRequest("Users can only edit their own comments"));
            }
        }
Example #10
0
        public ActionResult Edit(int id, CommentEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

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

            if (service.UpdateComment(model))
            {
                TempData["SaveResult"] = "Your comment was updated";
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "Your comment could not be updated.");
            return(View(model));
        }
Example #11
0
        public ActionResult Edit(int ID)
        {
            var service = CreateCommentService();
            var detail  = service.GetCommentByID(ID);
            var model   =
                new CommentEdit
            {
                CommentID = detail.CommentID,
                //BookID = detail.BookID,
                //Book = detail.Book,
                //MovieID = detail.MovieID,
                //Movie = detail.Movie,
                // ShowID = detail.ShowID,
                // Show = detail.Show,
                // TheaterProductionID = detail.TheaterProductionID,
                // TheaterProducton = detail.TheaterProduction,
                TypeOfMedia   = detail.TypeOfMedia,
                MyComment     = detail.MyComment,
                IsRecommended = detail.IsRecommended,
                ModifiedUtc   = DateTimeOffset.UtcNow
            };

            return(View(model));
        }
Example #12
0
        public ActionResult Edit(int id, CommentEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (id != model.CommentId)
            {
                ModelState.AddModelError("", "IDs do not match.");
                return(View(model));
            }

            var service = CreateCommentService();

            if (service.UpdateComment(model))
            {
                TempData["SaveResult"] = "Comment Edited.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Comment was not able to be edited.");
            return(View(model));
        }
        public ActionResult Reply(PermissionArea Area, PermissionPost Post, ApType ApType, CommentEdit CommentEdit)
        {
            if (!ModelState.IsValid)
            {
                var postEdit = Mapper.Map<Post, PostEdit>(Post.Entity);

                ViewData["Post"] = postEdit;
                ViewData["Comment"] = CommentEdit;
                ViewData["Salt"] = "CommentReply";

                return View("FormComment", Area);
            }

            var comment = Mapper.Map<CommentEdit, Comment>(CommentEdit);

            var permissionComment = middleManagement.Comment.Add(comment);

            return Redirect(Url.Action("View", "Blog",
                                    new
                                    {
                                        postid = Post.Entity.ID,
                                        title = Post.Entity.Title.ToUrlFriendly()
                                    }) + string.Format("#{0}", permissionComment.Entity.ID));
        }
        public ActionResult Reply(PermissionArea Area, PermissionPost Post, ApType ApType)
        {
            var postEdit = Mapper.Map<Post, PostEdit>(Post.Entity);

            ViewData["Post"] = postEdit;
            ViewData["Comment"] = new CommentEdit();
            ViewData["Salt"] = "CommentReply";

            return View("FormComment", Area);
        }
        public ActionResult Edit(PermissionArea Area, PermissionPost Post, CommentEdit CommentEdit, ApType ApType)
        {
            if (!ModelState.IsValid)
            {
                var postEdit = Mapper.Map<Post, PostEdit>(Post.Entity);

                ViewData["Post"] = postEdit;
                ViewData["Comment"] = CommentEdit;
                ViewData["Salt"] = "PostComment";

                return View("FormComment", Area);
            }

            var commentToSave = Mapper.Map<CommentEdit, Comment>(CommentEdit);
            middleManagement.Comment.Save(commentToSave);

            return RedirectToAction("View", "Blog", new
            {
                postid = Post.Entity.ID,
                title = Post.Entity.Title.ToUrlFriendly()
            });
        }
Example #16
0
 public bool UpdateComment(CommentEdit model)
 {
     throw new NotImplementedException();
 }