public async Task <IActionResult> Create([FromBody] CreateIngredientRequest ingredientsRequest) { var ingredient = new Ingredients { id = ingredientsRequest.id, Name = ingredientsRequest.Name, Price = ingredientsRequest.Price, Selectable = ingredientsRequest.Selectable }; await _ingredientsService.CreateIngredientsAsync(ingredient); var baseUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}"; var locationUri = baseUrl + "/" + ApiRoutes.Ingredients.Get.Replace("{id}", ingredient.id.ToString()); return(Created(locationUri, new IngredientsResponse { id = ingredient.id })); }
public async Task <ActionResult <IngredientResponse> > CreateIngredientAsync(CreateIngredientRequest ingredient, [FromServices] Command <CreateIngredientRequest, IngredientResponse> command) { var response = await command.ExecuteAsync(ingredient); return(CreatedAtRoute("GetSingleIngredient", new { ingredientId = response.Id }, response)); }