public IActionResult Post([FromBody] Recipe recipe) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var existingRecipe = from g in _context.Recipe where g.Name == recipe.Name select g; if (existingRecipe.Count <Recipe>() > 0) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } _context.Recipe.Add(recipe); try { _context.SaveChanges(); } catch (DbUpdateException) { if (RecipeExists(recipe.RecipeId)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtRoute("GetRecipe", new { id = recipe.RecipeId }, recipe)); }
public IActionResult Post([FromBody] Ingredient ingredient) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var existingIngredient = from g in _context.Ingredient where g.Name == ingredient.Name select g; if (existingIngredient.Count <Ingredient>() > 0) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } _context.Ingredient.Add(ingredient); try { _context.SaveChanges(); } catch (DbUpdateException) { if (IngredientExists(ingredient.IngredientId)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtRoute("GetIngredient", new { id = ingredient.IngredientId }, ingredient)); }
public IActionResult Post([FromBody] FoodEater foodeater) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var existingFoodie = from g in _context.FoodEater where g.Username == foodeater.Username select g; if (existingFoodie.Count <FoodEater>() > 0) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } _context.FoodEater.Add(foodeater); try { _context.SaveChanges(); } catch (DbUpdateException) { if (FoodEaterExists(foodeater.FoodEaterId)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtRoute("GetFoodEater", new { id = foodeater.FoodEaterId }, foodeater)); }