Пример #1
0
        public async Task AddToFavorites(int id)
        {
            var userId = _userContextService.GetUserId;

            if (userId == null)
            {
                throw new ForbidException();
            }

            var recipe = await _recipesRepository.Get(id);

            if (recipe == null)
            {
                throw new NotFoundException($"Recipe with id: {id} not found");
            }

            var favorite = await _recipesRepository
                           .GetFavorite(id, (int)userId);

            if (favorite != null)
            {
                throw new BadRequestException(
                          $"User already have recipe with id: {id} in favorites");
            }

            await _recipesRepository.AddRecipeToFavorite(id, (int)userId);
        }