private void UpdateRecipe(RecipeDTO recipeDTO) { var recipe = RecipeConverter.RecipeDTOToRecipe(recipeDTO); var xmlRecipe = getXmlFromRecipe(recipe); try { using (SqlConnection connection = new SqlConnection(this.ConnectionString)) { connection.Open(); SqlCommand updateCommand = connection.CreateCommand(); updateCommand.CommandType = CommandType.StoredProcedure; updateCommand.CommandText = "ssp_recipes_insert"; updateCommand.Parameters.Add(new SqlParameter("@name", recipe.Name)); updateCommand.Parameters.Add(new SqlParameter("@description", recipe.Description)); updateCommand.Parameters.Add(new SqlParameter("@ingredients", xmlRecipe.ToString())); updateCommand.Parameters.Add(new SqlParameter("@rId", recipe.Id)); updateCommand.ExecuteNonQuery(); } } catch (SqlException exeption) { Console.WriteLine(exeption.Message); } }
public ActionResult <IEnumerable <RecipeDTO> > GetRecipes() { var recipeIngredients = _context.RecipeIngredients.Include(r => r.Ingredient).ToList(); var result = _context.Recipes.Include(r => r.Ingredients).ToList(); return(result.Select(x => RecipeConverter.RecipeToRecipeDTO(x)).ToList()); }
/// <summary>Creates an instance for the default language.</summary> /// <returns>A repository.</returns> public IRecipeRepository ForDefaultCulture() { var recipeCollectionConverter = new RecipeCollectionConverter(); var recipeConverterFactory = new RecipeConverterFactory(); var craftingDisciplineCollectionConverter = new CraftingDisciplineCollectionConverter(new CraftingDisciplineConverter()); var recipeFlagCollectionConverter = new RecipeFlagCollectionConverter(new RecipeFlagConverter()); var quantityCollectionConverter = new CollectionConverter <IngredientDTO, ItemQuantity>(new ItemQuantityConverter()); var recipeConverter = new RecipeConverter(recipeConverterFactory, craftingDisciplineCollectionConverter, recipeFlagCollectionConverter, quantityCollectionConverter); return(new RecipeRepository(this.serviceClient, recipeCollectionConverter, recipeConverter)); }
/// <summary>Creates an instance for the default language.</summary> /// <returns>A repository.</returns> public override IRecipeRepository ForDefaultCulture() { var recipeConverterFactory = new RecipeConverterFactory(); var craftingDisciplineCollectionConverter = new CraftingDisciplineCollectionConverter(new CraftingDisciplineConverter()); var recipeFlagCollectionConverter = new RecipeFlagCollectionConverter(new RecipeFlagConverter()); var itemStackCollectionConverter = new CollectionConverter <IngredientDTO, ItemQuantity>(new ItemQuantityConverter()); var recipeConverter = new RecipeConverter(recipeConverterFactory, craftingDisciplineCollectionConverter, recipeFlagCollectionConverter, itemStackCollectionConverter); var identifiersResponseConverter = new ResponseConverter <ICollection <int>, ICollection <int> >(new ConverterAdapter <ICollection <int> >()); var responseConverter = new ResponseConverter <RecipeDTO, Recipe>(recipeConverter); var bulkResponseConverter = new DictionaryRangeResponseConverter <RecipeDTO, int, Recipe>(recipeConverter, recipe => recipe.RecipeId); var pageResponseConverter = new CollectionPageResponseConverter <RecipeDTO, Recipe>(recipeConverter); return(new RecipeRepository(this.serviceClient, identifiersResponseConverter, responseConverter, bulkResponseConverter, pageResponseConverter)); }
public async Task <ActionResult <RecipeDTO> > GetRecipe(int id) { var recipe = await _context.Recipes.FindAsync(id); recipe.Ingredients = _context.RecipeIngredients.Include(r => r.Ingredient).ToList().Where(x => x.RecipeId == id).ToList(); var recipeDTO = RecipeConverter.RecipeToRecipeDTO(recipe); if (recipe == null) { return(NotFound()); } return(recipeDTO); }
/// <summary> /// The ConvertRecipe method converts a recipe using the RecipeConverter /// </summary> /// <param name="ingredients">Text of ingredients</param> /// <param name="desiredServings">Desired number of servings</param> /// <param name="originalServings">Original number of servings</param> /// <returns>New text</returns> private string ConvertRecipe(string ingredients, int desiredServings, int originalServings) { RecipeConverter converter = new RecipeConverter(ingredients, new NonNegativeFraction(desiredServings, originalServings)); return(converter.Convert()); }