public IHttpActionResult DeleteRecipe(int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _recipeService.RemoveById(id); db.SaveChangesAsync(); return(Ok()); }
public async Task <IHttpActionResult> PutGroceryCategory(int id, IngredientCategoryModel ingredientCategoryModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != ingredientCategoryModel.Id) { return(BadRequest()); } var ingredientCategory = _ingredientCategoryService.GetById(id); ObjectFactory.Parse(ingredientCategoryModel, ingredientCategory); _ingredientCategoryService.Update(ingredientCategory); try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GroceryCategoryExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> PutCustomIngredient(int id, CustomIngredientModel customIngredientModels) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != customIngredientModels.Id) { return(StatusCode(HttpStatusCode.NotAcceptable)); } var customIngredient = _customIngredientService.GetCustomIngredientById(id); ObjectFactory.Parse(customIngredientModels, customIngredient); _customIngredientService.Update(customIngredient); try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomIngredientExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> PutRecipeIngredient(int id, RecipeIngredientModel recipeIngredientModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != recipeIngredientModel.Id) { return(BadRequest()); } var recipeIngredient = _recipeIngredientService.GetRecipeIngredientById(id); ObjectFactory.Parse(recipeIngredientModel, recipeIngredient); _recipeIngredientService.Update(recipeIngredient); try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RecipeIngredientExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> PutDirection(int id, DirectionModel directionModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != directionModel.Id) { return(BadRequest()); } var direction = _directionService.GetDirectionById(id); ObjectFactory.Parse(directionModel, direction); _directionService.Update(direction); try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DirectionExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }