Exemplo n.º 1
0
        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));
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
 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();
 }
Exemplo n.º 4
0
        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);
                }
            }
        }
Exemplo n.º 5
0
        public async Task <IActionResult> CreateRecipe([FromBody] CreateRecipeRequestModel requestModel)
        {
            await _mediator.Send(new CreateRecipeCommand(requestModel));

            return(Ok());
        }