public async Task StoreRecipeRating(RecipeRatingForm recipeRatingForm)
        {
            if (recipeRatingForm == null)
            {
                throw new ArgumentNullException(nameof(recipeRatingForm));
            }

            if (recipeRatingForm.RecipeId < 1 || recipeRatingForm.RatingValue > 5)
            {
                throw new InvalidOperationException("Rating cannot be less than 1 and greater than 5");
            }
            using var factory = await _dbFactory.Create(IsolationLevel.ReadCommitted);

            using var _dbContext = factory.FactoryFor <ApnaBawarchiKhanaDbContext>();

            await _dbContext.RecipeRatings.AddAsync(new RecipeRating { RecipeId = recipeRatingForm.RecipeId, Rating = recipeRatingForm.RatingValue });

            await _dbContext.SaveChangesAsync();

            factory.CommitTransaction();
        }
Пример #2
0
 public async Task StoreRecipeRating([FromBody] RecipeRatingForm recipeRatingForm)
 {
     await _recipeService.StoreRecipeRating(recipeRatingForm);
 }