/// <summary> /// Adds the comment. /// </summary> /// <param name="comment">The comment.</param> /// <returns></returns> public CommentViewModel AddComment(CommentViewModel comment) { comment.UserId = currentUserId; Comment commentDAL = MapCommentToDAL(comment); unitOfWork.CommentRepository.Add(commentDAL); unitOfWork.Save(); return Mapper.Map<CommentViewModel>(unitOfWork.CommentRepository.Get().Last()); }
public ActionResult AddComment(CommentViewModel comment) { if (User.Identity.IsAuthenticated) { comment = commentService.AddComment(comment); return Json(new { comment = comment }); } return Json(new { result = "error" }); }
/// <summary> /// Likes the comment. /// </summary> /// <param name="comment">The comment.</param> /// <returns></returns> public bool LikeComment(CommentViewModel comment) { RatingComment rating = unitOfWork.RatingCommentRepository.Get(filter: e => e.UserId == currentUserId && e.CommentId == comment.Id) .FirstOrDefault(); if (rating == null) { rating = new RatingComment { UserId = currentUserId, CommentId = comment.Id }; unitOfWork.RatingCommentRepository.Add(rating); unitOfWork.Save(); return true; } unitOfWork.RatingCommentRepository.Delete(rating.Id); unitOfWork.Save(); return false; }
private Comment MapCommentToDAL(CommentViewModel comment) { Comment commentDAL = Mapper.Map<Comment>(comment); commentDAL.User = unitOfWork.UserRepository.GetById(comment.UserId); return commentDAL; }
public ActionResult LikeComment(CommentViewModel comment) { if (User.Identity.IsAuthenticated) { bool liked = commentService.LikeComment(comment); int likes = commentService.CountLikes(comment.Id); return Json(new { likes = likes, result = "success", liked = liked }); } return Json(new { result = "error" }); }