Example #1
0
        public async Task <ActionResult> Post(Guid id)
        {
            var username = User.Claims.FirstOrDefault(m => m.Type == "sub");

            if (username == null)
            {
                return(Unauthorized());
            }
            var user = await _userManager.FindByEmailAsync(username.Value);

            if (user == null)
            {
                return(Unauthorized());
            }
            if (!_reasonService.ExistsReason(id))
            {
                return(NotFound(new ErrorData(StatusCodes.Status404NotFound, "Not found", null)));
            }
            var result = _reasonService.AddVote(id, user.Id);

            if (result)
            {
                return(Ok());
            }
            return(Conflict(new ErrorData(StatusCodes.Status409Conflict,
                                          "Conflict", new List <string> {
                "This user already voted this reason"
            })));
        }