public async Task <IActionResult> CreateRecipe(CreateRecipeRequestModel request) { try { var mapped = mapper.Map <RecipeDTO>(request); if (request.File != null) { var imgId = await fileService.Upload(request.File); if (string.IsNullOrWhiteSpace(imgId)) { return(Conflict()); } mapped.FileId = imgId; } var result = recipeService.CreateRecipe(mapped); if (!result) { return(Conflict()); } return(Ok(result)); } catch (Exception ex) { return(Conflict(ex.Message)); } }
public static CreateRecipeRequestModel CreateRecipeRequestModel(RecipeDTO model) { var ingrids = new List <IngredientRequestModel>(); foreach (var ingr in model.Ingredients) { ingrids.Add(CreateIngredientRequestModel(ingr)); } var nutritionDto = CreateNutritionRequestModel(model); var modelDto = new CreateRecipeRequestModel() { Name = model.Name, PrepTime = model.PrepTime, CookTime = model.CookTime, ReadyIn = model.ReadyIn, SkillRequired = model.SkillRequired, Serves = model.Serves, PreparationMethod = model.PreparationMethod.ToList(), Description = model.Description, Nutrition = nutritionDto, Ingredients = ingrids }; return(modelDto); }
public CreateRecipeCommand(CreateRecipeRequestModel requestModel) { Name = requestModel.Name; Description = requestModel.Description; ImagePath = requestModel.ImagePath; Ingredients = requestModel.Ingredients?.Select(x => new RecipeIngredientListItemDto { Name = x.Name.Trim(), Amount = x.Amount }).ToList(); }
public async Task <string> CreateRecipe(CreateRecipeRequestModel model) { var data = ConvertObjToJsonStringContent(model); using (HttpResponseMessage responseMessage = await apiClient.PostAsync(RecipeApiEndpoints.RecipeCreate, data)) { if (responseMessage.IsSuccessStatusCode) { var result = await responseMessage.Content.ReadAsAsync <string>(); return(result); } else { throw new Exception(responseMessage.ReasonPhrase); } } }
public async Task <IActionResult> CreateRecipe([FromBody] CreateRecipeRequestModel requestModel) { await _mediator.Send(new CreateRecipeCommand(requestModel)); return(Ok()); }