コード例 #1
0
        // clear the current list of methods for a given recipe and add the ones based on the file to ingest
        private static void addMethods(RecipeObj recipe)
        {
            // clear the current list
            using (var context = new WoolworthsDBDataContext())
            {
                var methodToDel = context.RecipeMethods.Where(r => r.RecipeID == recipe.RecipeID);
                context.RecipeMethods.DeleteAllOnSubmit(methodToDel);
                context.SubmitChanges();
            }

            if (recipe.Methods == null)
            {
                return;
            }

            using (var context = new WoolworthsDBDataContext())
            {
                foreach (var method in recipe.Methods.Select(obj => new RecipeMethod()
                {
                    Description = obj.Step,
                    Number = obj.StepID,
                    RecipeID = recipe.RecipeID
                }))
                {
                    context.RecipeMethods.InsertOnSubmit(method);
                }
                context.SubmitChanges();
            }
        }
コード例 #2
0
        // clear the current list of ingredients for a given recipe and add the ones based on the file to ingest
        private static void addIngredients(RecipeObj recipe)
        {
            // clear the current list
            using (var context = new WoolworthsDBDataContext())
            {
                var ingredToDel = context.RecipeIngredients.Where(r => r.RecipeID == recipe.RecipeID);
                context.RecipeIngredients.DeleteAllOnSubmit(ingredToDel);
                context.SubmitChanges();
            }

            if (recipe.Ingredients == null)
            {
                return;
            }

            using (var context = new WoolworthsDBDataContext())
            {
                foreach (var ingred in recipe.Ingredients.Select(obj => new RecipeIngredient()
                {
                    Description = obj.Ingredient,
                    Number = obj.IngredientID,
                    ProductArticle = obj.ProductID,
                    RecipeID = recipe.RecipeID
                }))
                {
                    context.RecipeIngredients.InsertOnSubmit(ingred);
                }
                context.SubmitChanges();
            }
        }
コード例 #3
0
        // adds or returns the actual Recipe record (id)
        private int createRecipeRecord(RecipeObj recipe)
        {
            using (var context = new WoolworthsDBDataContext())
            {
                var existing = context.Recipes.SingleOrDefault(r => r.ID == recipe.RecipeID);

                // if the recipe already exists and the action isn't to update then just return the recipe identifier
                if (existing != null) //Always update, regardless of action (well, it should be "i" or "u" -- && recipe.Action.ToLower() == "u")
                {
                    // if the recipe exists and the instruction is to update then updates
                    existing.CookingTime    = recipe.CookingTime;
                    existing.Description    = recipe.Description;
                    existing.Recipe1        = recipe.Recipe;
                    existing.ImageURL       = downloadRemoteImageFile(recipe.ImageURL, ImgDir, recipe.Recipe);
                    existing.OriginImageUrl = recipe.ImageURL;
                    existing.PrepTime       = recipe.PreparationTime;
                    existing.Serves         = recipe.Serves;
                    existing.Tip            = recipe.Tip;
                    existing.Title          = recipe.Title;
                    existing.TotalTime      = recipe.TotalTime;
                    context.SubmitChanges();
                    return(existing.ID);
                }
                else
                {
                    // create the record regardless of whether it was an insert or update record
                    var newRecipe = new WoolworthsDAL.Recipe
                    {
                        ID             = recipe.RecipeID,
                        CookingTime    = recipe.CookingTime,
                        Recipe1        = recipe.Recipe,
                        Description    = recipe.Description,
                        ImageURL       = downloadRemoteImageFile(recipe.ImageURL, ImgDir, recipe.Recipe),
                        OriginImageUrl = recipe.ImageURL,
                        PrepTime       = recipe.PreparationTime,
                        Serves         = recipe.Serves,
                        Tip            = recipe.Tip,
                        Title          = recipe.Title,
                        TotalTime      = recipe.TotalTime
                    };
                    context.Recipes.InsertOnSubmit(newRecipe);
                    context.SubmitChanges();
                    return(newRecipe.ID);
                }
            }
        }
コード例 #4
0
        // work out if the cuisine already exists, if it does then use it for the mapping table, else create it
        private static void addCuisines(RecipeObj recipe)
        {
            using (var context = new WoolworthsDBDataContext())
            {
                // clear the current mappings
                var maps = context.RecipeCuisineMaps.Where(r => r.RecipeID == recipe.RecipeID);
                context.RecipeCuisineMaps.DeleteAllOnSubmit(maps);
                context.SubmitChanges();

                if (recipe.Cuisines == null)
                {
                    return;
                }

                foreach (var cuisine in recipe.Cuisines)
                {
                    // create or retrieve the RecipeCuisine.ID value
                    var master          = context.RecipeCuisines.SingleOrDefault(c => c.Description == cuisine.Cuisine);
                    var recipeCuisineID = 0;
                    if (master == null)
                    {
                        var toCreate = new RecipeCuisine()
                        {
                            Description = cuisine.Cuisine
                        };
                        context.RecipeCuisines.InsertOnSubmit(toCreate);
                        context.SubmitChanges();
                        recipeCuisineID = toCreate.ID;
                    }
                    else
                    {
                        recipeCuisineID = master.ID;
                    }

                    // add to the mapping table
                    var map = new RecipeCuisineMap()
                    {
                        RecipeCuisineID = recipeCuisineID,
                        RecipeID        = recipe.RecipeID
                    };
                    context.RecipeCuisineMaps.InsertOnSubmit(map);
                    context.SubmitChanges();
                }
            }
        }
コード例 #5
0
 private static void updateRecipeAsFeatured(FeaturedRecipeObj featuredRecipe)
 {
     using (var context = new WoolworthsDBDataContext())
     {
         var recipe = context.Recipes.SingleOrDefault(r => r.ID == featuredRecipe.RecipeID);
         if (recipe != null)
         {
             recipe.FeaturedStartDate = DateTime.Parse(featuredRecipe.STARTDATE);
             context.SubmitChanges();
         }
     }
 }
コード例 #6
0
 private void updateRecipeAsFeatured(FeaturedRecipeObj featuredRecipe)
 {
     using (var context = new WoolworthsDBDataContext())
     {
         var recipe = context.Recipes.SingleOrDefault(r => r.ID == featuredRecipe.RecipeID);
         if (recipe == null) return;
         recipe.FeaturedStartDate = DateTime.Parse(featuredRecipe.STARTDATE);
         context.SubmitChanges();
     }
 }
コード例 #7
0
        // clear the current list of ingredients for a given recipe and add the ones based on the file to ingest
        private static void addIngredients(RecipeObj recipe)
        {
            // clear the current list
            using (var context = new WoolworthsDBDataContext())
            {
                var ingredToDel = context.RecipeIngredients.Where(r => r.RecipeID == recipe.RecipeID);
                context.RecipeIngredients.DeleteAllOnSubmit(ingredToDel);
                context.SubmitChanges();
            }

            if (recipe.Ingredients == null)
                return;

            using (var context = new WoolworthsDBDataContext())
            {
                foreach (var obj in recipe.Ingredients)
                {
                    var ingred = new RecipeIngredient()
                    {
                        Description = obj.Ingredient,
                        Number = obj.IngredientID,
                        ProductArticle = obj.ProductID,
                        RecipeID = recipe.RecipeID
                    };
                    context.RecipeIngredients.InsertOnSubmit(ingred);
                }
                context.SubmitChanges();
            }
        }
コード例 #8
0
        // clear the current list of methods for a given recipe and add the ones based on the file to ingest
        private static void addMethods(RecipeObj recipe)
        {
            // clear the current list
            using (var context = new WoolworthsDBDataContext())
            {
                var methodToDel = context.RecipeMethods.Where(r => r.RecipeID == recipe.RecipeID);
                context.RecipeMethods.DeleteAllOnSubmit(methodToDel);
                context.SubmitChanges();
            }

            if (recipe.Methods == null)
                return;

            using (var context = new WoolworthsDBDataContext())
            {
                foreach (var obj in recipe.Methods)
                {
                    var method = new RecipeMethod()
                    {
                        Description = obj.Step,
                        Number = obj.StepID,
                        RecipeID = recipe.RecipeID
                    };
                    context.RecipeMethods.InsertOnSubmit(method);
                }
                context.SubmitChanges();
            }
        }
コード例 #9
0
        // work out if the cuisine already exists, if it does then use it for the mapping table, else create it
        private void addCuisines(RecipeObj recipe)
        {
            using (var context = new WoolworthsDBDataContext())
            {
                // clear the current mappings
                var maps = context.RecipeCuisineMaps.Where(r => r.RecipeID == recipe.RecipeID);
                context.RecipeCuisineMaps.DeleteAllOnSubmit(maps);
                context.SubmitChanges();

                if (recipe.Cuisines == null)
                    return;

                foreach (var cuisine in recipe.Cuisines)
                {
                    // create or retrieve the RecipeCuisine.ID value
                    var master = context.RecipeCuisines.SingleOrDefault(c => c.Description == cuisine.Cuisine);
                    var recipeCuisineID = 0;
                    if (master == null)
                    {
                        var toCreate = new RecipeCuisine()
                        {
                            Description = cuisine.Cuisine
                        };
                        context.RecipeCuisines.InsertOnSubmit(toCreate);
                        context.SubmitChanges();
                        recipeCuisineID = toCreate.ID;
                    }
                    else
                    {
                        recipeCuisineID = master.ID;
                    }

                    // add to the mapping table
                    var map = new RecipeCuisineMap()
                    {
                        RecipeCuisineID = recipeCuisineID,
                        RecipeID = recipe.RecipeID
                    };
                    context.RecipeCuisineMaps.InsertOnSubmit(map);
                    context.SubmitChanges();
                }
            }
        }
コード例 #10
0
        // adds or returns the actual Recipe record (id)
        private int createRecipeRecord(RecipeObj recipe)
        {
            using (var context = new WoolworthsDBDataContext())
            {
                var existing = context.Recipes.SingleOrDefault(r => r.ID == recipe.RecipeID);

                // if the recipe already exists and the action isn't to update then just return the recipe identifier
                if (existing != null) //Always update, regardless of action (well, it should be "i" or "u" -- && recipe.Action.ToLower() == "u")
                {
                    // if the recipe exists and the instruction is to update then updates
                    existing.CookingTime = recipe.CookingTime;
                    existing.Description = recipe.Description;
                    existing.Recipe1 = recipe.Recipe;
                    existing.ImageURL = downloadRemoteImageFile(recipe.ImageURL, ImgDir, recipe.Recipe);
                    existing.OriginImageUrl = recipe.ImageURL;
                    existing.PrepTime = recipe.PreparationTime;
                    existing.Serves = recipe.Serves;
                    existing.Tip = recipe.Tip;
                    existing.Title = recipe.Title;
                    existing.TotalTime = recipe.TotalTime;
                    context.SubmitChanges();
                    return existing.ID;
                }
                else 
                {
                    // create the record regardless of whether it was an insert or update record
                    var newRecipe = new WoolworthsDAL.Recipe
                    {
                        ID = recipe.RecipeID,
                        CookingTime = recipe.CookingTime,
                        Recipe1 = recipe.Recipe,
                        Description = recipe.Description,
                        ImageURL = downloadRemoteImageFile(recipe.ImageURL, ImgDir, recipe.Recipe),
                        OriginImageUrl = recipe.ImageURL,
                        PrepTime = recipe.PreparationTime,
                        Serves = recipe.Serves,
                        Tip = recipe.Tip,
                        Title = recipe.Title,
                        TotalTime = recipe.TotalTime
                    };
                    context.Recipes.InsertOnSubmit(newRecipe);
                    context.SubmitChanges();
                    return newRecipe.ID;
                }
            }
        }