コード例 #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));
        }
コード例 #2
0
        public IHttpActionResult Delete(int commentId)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("invalid model!"));
                }
                _commentVoteService.Delete(commentId); // change

                return(Ok(new SuccessResponse()));
            }
            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));
            }
        }