public async Task <Result> Handle(CreateRecipeCommand command) { foreach (var validator in _validators) { var validationResult = validator.Validate(command); if (validationResult.IsFailure) { return(validationResult); } } // var imageUrl = _imageUploader.Upload(command.Image, command.Id.ToString(), command.Name); var recipeIngredients = command.RecipeIngredients.Select(x => _recipeIngredientFactory.Create(x.IngredientId, x.Grams)); await _recipeFactory.Create(command.Id, command.Name, command.Description, "imageUrl", command.RecipeInfo, recipeIngredients); _eventPublisher.Rise(); return(Result.Ok()); }
public async Task <Result> Handle(UpdateRecipeCommand command) { foreach (var validator in _validators) { var validationResult = validator.Validate(command); if (validationResult.IsFailure) { return(validationResult); } } var recipe = _recipeRepository.GetById(command.Id); if (recipe == null) { return(Result.Fail(ResultCode.NotFound, $"Recipe with Id{command.Id} does not exist;")); } var recipeIngredients = command.RecipeIngredients.Select(x => _recipeIngredientFactory.Create(x.IngredientId, x.Grams)); recipe.Update(command.Name, command.Description, command.RecipeInfo, recipeIngredients); _eventPublisher.Rise(); return(Result.Ok()); }