Exemplo n.º 1
0
 /// <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());
 }
Exemplo n.º 2
0
 public ActionResult AddComment(CommentViewModel comment)
 {
     if (User.Identity.IsAuthenticated)
     {
         comment = commentService.AddComment(comment);
         return Json(new { comment = comment });
     }
     return Json(new { result = "error" });
 }
Exemplo n.º 3
0
 /// <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;
 }
Exemplo n.º 4
0
 private Comment MapCommentToDAL(CommentViewModel comment)
 {
     Comment commentDAL = Mapper.Map<Comment>(comment);
     commentDAL.User = unitOfWork.UserRepository.GetById(comment.UserId);
     return commentDAL;
 }
Exemplo n.º 5
0
 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" });
 }