Ejemplo n.º 1
0
        public JsonResult Vote(int commentId, string currentUserId)
        {
            int checkvote = _commentVoteService.CheckVote(currentUserId, commentId);
            var vote      = new CommentVote();

            vote.CommentId = commentId;
            vote.UserId    = User.Identity.GetUserId();
            var listVote = _commentVoteService.GetAll();

            if (checkvote == 0)
            {
                _commentVoteService.Add(vote);
                _commentVoteService.Save();

                return(Json(new
                {
                    status = true
                }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                _commentVoteService.Delete(currentUserId, commentId);
                _commentVoteService.Save();
            }
            return(Json(new
            {
                status = false
            }, JsonRequestBehavior.AllowGet));
        }
 public IHttpActionResult GetAll()
 {
     try
     {
         ItemsResponse <CommentVote> response = new ItemsResponse <CommentVote>
         {
             Items = _commentVoteService.GetAll()
         };
         return(Ok(response));
     }
     catch (Exception ex)
     {
         _errorLogService.Post(new Models.Requests.Logs.ErrorLogAddRequest
         {
             ErrorSourceTypeId = 1,
             Message           = ex.Message,
             StackTrace        = ex.StackTrace,
             Title             = "Error in " + GetType().Name + " " + System.Reflection.MethodBase.GetCurrentMethod().Name
         });
         return(BadRequest(ex.Message));
     }
 }