public async Task <IActionResult> AddRecipe([FromBody] RecipeForPostDto recipeForPostDto) { var recipe = _mapper.Map <Recipe>(recipeForPostDto); _cookingRepository.Add(recipe); if (!ModelState.IsValid) { return(BadRequest("Invalid data provided.")); } if (await _cookingRepository.SaveChanges()) { var recipeToReturn = _mapper.Map <RecipeForDetailedDto>(recipe); return(Ok(recipeToReturn)); } return(BadRequest("Failed to add Recipe")); }
public async Task <IActionResult> AddMeasurementUnit([FromBody] MeasurementUnitForPostDto unitforPostDto) { var unit = _mapper.Map <MeasurementUnit>(unitforPostDto); _cookingRepository.Add(unit); if (await _cookingRepository.SaveChanges()) { var unitToReturn = _mapper.Map <MeasurementUnitForGetDto>(unit); return(Ok(unitToReturn)); } return(BadRequest("Failed add Measurement Unit")); }
public async Task <IActionResult> AddIngredient([FromBody] IngredientForPostDto ingredientforPostDto) { var ingredient = _mapper.Map <Ingredient>(ingredientforPostDto); _cookingRepository.Add(ingredient); if (await _cookingRepository.SaveChanges()) { var ingredientToReturn = _mapper.Map <IngredientForGetDto>(ingredient); return(Ok(ingredientToReturn)); } return(BadRequest("Failed to add Ingredient")); }
public async Task <IActionResult> AddMeasurementQuantity([FromBody] MeasurementQuantityForPostDto quantityforPostDto) { var quantity = _mapper.Map <MeasurementQuantity>(quantityforPostDto); _cookingRepository.Add(quantity); if (await _cookingRepository.SaveChanges()) { var quantityToReturn = _mapper.Map <MeasurementQuantityForGetDto>(quantity); return(Ok(quantityToReturn)); } return(BadRequest("Failed add Measurement Quantity")); }