Exemplo n.º 1
0
        public RecipeToCategory GetCategory(Recipe recipe)
        {
            using (var sqlConnection = new SqlConnection(_dbPath))
            {
                sqlConnection.Open();
                var sqlCommand = new SqlCommand("SELECT RecipeCategoryID FROM RC WHERE " +
                                                $"RecipeID={recipe.Id}", sqlConnection);
                var sqlDataReader = sqlCommand.ExecuteReader();
                try
                {
                    var recipeCategoryModel = new RecipeCategoryModel(_dbPath);
                    var recipeToCategories  = new List <RecipeToCategory>();

                    if (sqlDataReader.Read())
                    {
                        var recipeToCategory = new RecipeToCategory
                        {
                            Recipe         = recipe,
                            RecipeCategory = recipeCategoryModel.GetRecipeCategory((int)sqlDataReader[0])
                        };

                        return(recipeToCategory);
                    }
                }
                finally
                {
                    sqlDataReader.Close();
                }
            }

            return(null);
        }
Exemplo n.º 2
0
        public List <RecipeToCategory> GetRecipes(RecipeCategory recipeCategory)
        {
            using (var sqlConnection = new SqlConnection(_dbPath))
            {
                sqlConnection.Open();
                var sqlCommand = new SqlCommand("SELECT RecipeID FROM RC WHERE " +
                                                $"RecipeCategoryID={recipeCategory.Id}", sqlConnection);
                var sqlDataReader = sqlCommand.ExecuteReader();
                try
                {
                    var recipeModel        = new RecipeModel(_dbPath);
                    var recipeToCategories = new List <RecipeToCategory>();

                    while (sqlDataReader.Read())
                    {
                        var recipeToCategory = new RecipeToCategory
                        {
                            Recipe         = recipeModel.GetRecipe((int)sqlDataReader[0]),
                            RecipeCategory = recipeCategory
                        };

                        recipeToCategories.Add(recipeToCategory);
                    }

                    return(recipeToCategories);
                }
                finally
                {
                    sqlDataReader.Close();
                }
            }
        }