Пример #1
0
        public async Task <JsonResult> RatingIncrement([FromBody] int?id)
        {
            var userId = _userManager.GetUserId(User);  //gets the usersId

            if (id == null)
            {
                return(Json("Error"));
            }
            var wholeThread = _service.GetById(id);
            //make a list of users that liked the thread
            var listOfLikes = _service.ListOfLikes(id);

            //check if the user already pressed the btn
            if (_service.CheckAreadyLiked(wholeThread, userId) == true)
            {
                return(Json(listOfLikes.Count()));
            }
            else
            {
                //add the user that pressed the button to the list of liked on the thread
                await _service.AddUserToLikeList(id, userId);

                wholeThread.Votes = listOfLikes.Count();
                return(Json(listOfLikes.Count()));    //makes a json with the amount of votes that are currently in the database
            }
        }