コード例 #1
0
        public async Task <IActionResult> DeleteRecipeRating(ApiRecipeRating apiObj)
        {
            var ratingToDelete = RecipeRating.FromApiToRecipeRating(apiObj);

            _context.Entry(ratingToDelete).State = EntityState.Deleted;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RecipeRatingExists(ratingToDelete))
                {
                    return(NotFound());
                }

                throw;
            }

            return(NoContent());
        }
コード例 #2
0
        public async Task <ActionResult <ApiRecipeRating> > PostRecipeRating(ApiRecipeRating apiRecipeRating)
        {
            //convert api model to regular model
            var recipeRating = RecipeRating.FromApiToRecipeRating(apiRecipeRating);
            await _context.RecipeRating.AddAsync(recipeRating);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (RecipeRatingExists(recipeRating))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetRecipeRating", new { id = apiRecipeRating.UserId }, apiRecipeRating));
        }