Пример #1
0
        public IActionResult Post([FromBody] Vote value, [FromHeader] string jwt)
        {
            int userId = 0;

            try
            {
                userId = Shared.Jwt.JwtUtility.ReadJwt(jwt);
            }
            catch { return(BadRequest("Not Authorized.")); }

            List <Vote> votes = voteRepository.GetUser(userId).ToList();

            for (int i = 0; i < votes.Count(); i++)
            {
                if (votes[i].ArticleId == value.ArticleId)
                {
                    votes[i].Rating = value.Rating;
                    voteRepository.Put(votes[i].Id, votes[i]);
                    return(Ok("Vote Changed."));
                }
            }

            value.Id      = 0;
            value.UserId  = userId;
            value.Created = DateTime.Now;

            voteRepository.Post(value);

            return(Ok());
        }