Пример #1
0
        public async Task <IActionResult> AddReview(ReviewForCreateDto reviewClient)
        {
            if (reviewClient.UserId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            if (await _repo.AlreadyUserReview(reviewClient.UserId, reviewClient.RecipeId))
            {
                throw new Exception($"You already review this recipe");
            }

            reviewClient.Created = DateTime.Now;
            reviewClient.Status  = "Acepted";

            var reviewMap = _mapper.Map <Review>(reviewClient);

            _repo.Add(reviewMap);

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception($"the creation for review fail");
        }