public bool DeleteComment(int postCommentOrLikeId, int userId) { PostCommentOrLike commentOrLike = _context.CommentOrLike .FirstOrDefault(x => x.PostCommentOrLikeId == postCommentOrLikeId && x.IdUser == userId && x.RecordStatusId == (int)RecordStatus.Active); return(DeleteCommentOrLike(commentOrLike)); }
public bool DeleteLike(int postId, int loginUserId) { PostCommentOrLike commentOrLike = _context.CommentOrLike.FirstOrDefault(x => x.IdPost == postId && x.IdUser == loginUserId && x.DoYouLike && x.RecordStatusId == (int)RecordStatus.Active); return(DeleteCommentOrLike(commentOrLike)); }
private bool DeleteCommentOrLike(PostCommentOrLike commentOrLike) { if (commentOrLike != null) { commentOrLike.RecordStatusId = (int)RecordStatus.Deleted; _context.Entry(commentOrLike).State = System.Data.Entity.EntityState.Modified; return(SaveChanges()); } return(false); }
public bool CreateCommentOrLike(PostCommentOrLike commentOrLike) { if (commentOrLike == null) { throw new ArgumentNullException(nameof(commentOrLike)); } commentOrLike.DateAndTime = DateTime.Now; commentOrLike.RecordStatusId = (int)RecordStatus.Active; _context.CommentOrLike.Add(commentOrLike); return(SaveChanges()); }
public JsonResult Like(PostCommentOrLike like) { like.IdUser = _loginUser.UserId; like.DoYouLike = true; if (_postsRepo.CreateCommentOrLike(like)) { return(Json(new JsonResponseVM { Result = "OK" })); } return(Json(new JsonResponseVM { Result = "ERROR", Msg = "Pogreska" })); }
public void CommentPost_DatabaseSaveFailed() { int postId = 2; string comment = "Hello"; PostCommentOrLike postComment = new PostCommentOrLike { IdPost = postId, Comment = comment, IdUser = _loginUser.UserId }; _postsRepoMock.Setup(m => m.CreateCommentOrLike(postComment)).Returns(false); PostController controller = new PostController(_postsRepoMock.Object, _loginUser); JsonResult result = controller.CommentPost(comment, postId); Assert.IsNotNull(result); Assert.IsNotNull(result.Data); Assert.IsTrue(result.Data is JsonResponseVM); Assert.IsTrue((result.Data as JsonResponseVM).Result == "ERROR"); }
public bool UpdateCommentOrLike(PostCommentOrLike commentOrLike) { PostCommentOrLike commentOrLikeDb = _context.CommentOrLike .FirstOrDefault(x => x.PostCommentOrLikeId == commentOrLike.PostCommentOrLikeId && x.IdUser == commentOrLike.IdUser && x.RecordStatusId == (int)RecordStatus.Active); if (commentOrLikeDb != null) { commentOrLikeDb.Comment = commentOrLike.Comment; commentOrLikeDb.DoYouLike = commentOrLike.DoYouLike; commentOrLikeDb.IdComment = commentOrLike.IdComment; commentOrLikeDb.DateAndTime = DateTime.Now; commentOrLikeDb.RecordStatusId = (int)RecordStatus.Active; _context.Entry(commentOrLikeDb).State = System.Data.Entity.EntityState.Modified; return(SaveChanges()); } return(false); }
public JsonResult EditCommentPost(string comment, int postCommentOrLikeId, int idPost) { if (!String.IsNullOrEmpty(comment)) { PostCommentOrLike commentModel = new PostCommentOrLike { Comment = comment, PostCommentOrLikeId = postCommentOrLikeId, IdUser = _loginUser.UserId }; if (_postsRepo.UpdateCommentOrLike(commentModel)) { return(Json(new JsonResponseVM { Result = "OK", PostId = idPost })); } return(Json(new JsonResponseVM { Result = "ERROR", Msg = "Pogreska" })); } else { return(Json(new JsonResponseVM { Result = "ERROR", Msg = "Tekst komentara je obavezan" })); } }