Example #1
0
        private static async Task InitializeSupplies(RecipEaseContext context)
        {
            if (!context.Supplies.Any())
            {
                var supplies = new[]
                {
                    new Supplies()
                    {
                        UserId   = _testSupplierId,
                        Quantity = 5,
                        IngrName = Flour,
                        UnitName = Grams,
                    },
                    new Supplies()
                    {
                        UserId   = _testSupplierId,
                        Quantity = 100,
                        IngrName = Rice,
                        UnitName = Grams,
                    },
                    new Supplies()
                    {
                        UserId   = _testSupplierId,
                        Quantity = 10,
                        IngrName = GoatMilk,
                        UnitName = Cups,
                    }
                };

                await context.Supplies.AddRangeAsync(supplies);

                await context.SaveChangesAsync();
            }
        }
Example #2
0
        private static async Task InitializeIngredients(RecipEaseContext context)
        {
            if (!context.Ingredient.Any())
            {
                var ingredients = new[]
                {
                    new Ingredient()
                    {
                        Name             = Flour,
                        Rarity           = Rarity.Common,
                        WeightToVolRatio = 0.5
                    },
                    new Ingredient()
                    {
                        Name             = Rice,
                        Rarity           = Rarity.Common,
                        WeightToVolRatio = 0.9
                    },
                    new Ingredient()
                    {
                        Name             = GoatMilk,
                        Rarity           = Rarity.Rare,
                        WeightToVolRatio = 0.6
                    },
                };

                await context.Ingredient.AddRangeAsync(ingredients);
            }
        }
Example #3
0
        private static async Task InitializeRecipes(RecipEaseContext context)
        {
            if (!context.Recipe.Any())
            {
                var recipes = new[]
                {
                    new Recipe
                    {
                        Name        = "Mac N' Cheese",
                        AuthorId    = _testCustomerId,
                        Calories    = 1,
                        Carbs       = 2,
                        Cholesterol = 3,
                        Fat         = 4,
                        Protein     = 5,
                        Sodium      = 6,
                        Steps       = "The steps to make the recipe..."
                    },
                    new Recipe
                    {
                        Name        = "Pork Cutlets",
                        AuthorId    = _testCustomerId,
                        Calories    = 1,
                        Carbs       = 2,
                        Cholesterol = 3,
                        Fat         = 4,
                        Protein     = 5,
                        Sodium      = 6,
                        Steps       = "The steps to make the recipe..."
                    },
                    new Recipe
                    {
                        Name        = "Sushi",
                        AuthorId    = _testCustomerId2,
                        Calories    = 1,
                        Carbs       = 2,
                        Cholesterol = 3,
                        Fat         = 4,
                        Protein     = 5,
                        Sodium      = 6,
                        Steps       = "The steps to make the recipe..."
                    },
                };

                await context.Recipe.AddRangeAsync(recipes);

                await context.SaveChangesAsync();
            }

            var allRecipes = await context.Recipe.ToListAsync();

            if (allRecipes.Count == 3)
            {
                _recipe0Id = allRecipes[0].Id;
                _recipe1Id = allRecipes[1].Id;
                _recipe2Id = allRecipes[2].Id;
            }
        }
Example #4
0
        private static async Task InitializeRecipeCollections(RecipEaseContext context)
        {
            if (!context.RecipeCollection.Any())
            {
                var recipeCollections = new[]
                {
                    new RecipeCollection
                    {
                        UserId      = _testCustomerId,
                        Title       = _recColl1Title,
                        Description = "All my favourite breakfast recipes",
                        Visibility  = Visibility.Public
                    },
                    new RecipeCollection
                    {
                        UserId      = _testCustomerId,
                        Title       = _recColl2Title,
                        Description = "All my favourite seafood recipes",
                        Visibility  = Visibility.Public
                    },
                };

                var recipeInCollections = new[]
                {
                    new RecipeInCollection
                    {
                        RecipeId         = _recipe0Id,
                        CollectionTitle  = _recColl1Title,
                        CollectionUserId = _testCustomerId,
                    },
                    new RecipeInCollection
                    {
                        RecipeId         = _recipe1Id,
                        CollectionTitle  = _recColl1Title,
                        CollectionUserId = _testCustomerId,
                    },
                    new RecipeInCollection
                    {
                        RecipeId         = _recipe1Id,
                        CollectionTitle  = _recColl2Title,
                        CollectionUserId = _testCustomerId,
                    },
                    new RecipeInCollection
                    {
                        RecipeId         = _recipe2Id,
                        CollectionTitle  = _recColl2Title,
                        CollectionUserId = _testCustomerId,
                    },
                };

                await context.RecipeCollection.AddRangeAsync(recipeCollections);

                await context.RecipeInCollection.AddRangeAsync(recipeInCollections);

                await context.SaveChangesAsync();
            }
        }
Example #5
0
        private static async Task InitializeUses(RecipEaseContext context)
        {
            if (!context.Uses.Any())
            {
                var uses = new[]
                {
                    new Uses
                    {
                        RecipeId = _recipe0Id,
                        IngrName = Flour,
                        UnitName = Grams,
                        Quantity = 5
                    },
                    new Uses
                    {
                        RecipeId = _recipe1Id,
                        IngrName = Flour,
                        UnitName = Grams,
                        Quantity = 100
                    },
                    new Uses
                    {
                        RecipeId = _recipe2Id,
                        IngrName = Flour,
                        UnitName = Grams,
                        Quantity = 6
                    },
                    new Uses
                    {
                        RecipeId = _recipe0Id,
                        IngrName = GoatMilk,
                        UnitName = Cups,
                        Quantity = 10
                    },
                    new Uses
                    {
                        RecipeId = _recipe1Id,
                        IngrName = Rice,
                        UnitName = Cups,
                        Quantity = 4
                    },
                    new Uses
                    {
                        RecipeId = _recipe2Id,
                        IngrName = Rice,
                        UnitName = Grams,
                        Quantity = 200
                    },
                };

                await context.Uses.AddRangeAsync(uses);

                await context.SaveChangesAsync();
            }
        }
Example #6
0
        public static async Task Initialize(RecipEaseContext context, UserManager <User> userManager,
                                            RoleManager <IdentityRole> roleManager)
        {
            await context.Database.EnsureCreatedAsync();

            await InitializeRoles(roleManager);
            await InitializeUsers(context, userManager);

            await InitializeIngredients(context);
            await InitializeUnits(context);
            await InitializeSupplies(context);
            await InitializeShoppingList(context);

            await InitializeRecipes(context);
            await InitializeRecipeRatings(context);
            await InitializeRecipeCollections(context);
            await InitializeUses(context);
            await InitializeRecipeCategories(context);

            await context.SaveChangesAsync();
        }
Example #7
0
        private static async Task InitializeUnits(RecipEaseContext context)
        {
            if (!context.Unit.Any())
            {
                var units = new[]
                {
                    new Unit()
                    {
                        Name     = Grams,
                        Symbol   = "g",
                        UnitType = UnitType.Mass
                    },
                    new Unit()
                    {
                        Name     = Cups,
                        Symbol   = "cups",
                        UnitType = UnitType.Volume
                    },
                };

                await context.Unit.AddRangeAsync(units);
            }

            if (!context.UnitConversion.Any())
            {
                var conversions = new[]
                {
                    new UnitConversion {
                        ConvertsToUnitName = Grams, ConvertsFromUnitName = Cups, Ratio = 2.1
                    },
                };
                await context.UnitConversion.AddRangeAsync(conversions);
            }

            await context.SaveChangesAsync();
        }
Example #8
0
        public static async Task <(User user, IdentityResult result)> CreateUser(UserManager <User> userManager,
                                                                                 RecipEaseContext context,
                                                                                 AccountType accountType, string email, string password, Supplier supplierInfo = null,
                                                                                 Customer customerInfo = null)
        {
            var user = new User {
                UserName = email, Email = email
            };
            var result = await userManager.CreateAsync(user, password);

            if (!result.Succeeded)
            {
                return(user, result);
            }
            switch (accountType)
            {
            case AccountType.Customer:
                Customer customer;
                if (customerInfo != null)
                {
                    customer        = customerInfo;
                    customer.UserId = user.Id;
                }
                else
                {
                    customer = new Customer {
                        UserId = user.Id
                    };
                }
                await context.Customer.AddAsync(customer);

                await userManager.AddToRoleAsync(user, Role.Customer.ToString());

                await context.SaveChangesAsync();

                break;

            case AccountType.Supplier:
                Supplier supplier;
                if (supplierInfo != null)
                {
                    supplier        = supplierInfo;
                    supplier.UserId = user.Id;
                }
                else
                {
                    supplier = new Supplier {
                        UserId = user.Id
                    };
                }
                await context.Supplier.AddAsync(supplier);

                await userManager.AddToRoleAsync(user, Role.Supplier.ToString());

                await context.SaveChangesAsync();

                break;

            default:
                throw new Exception("Account type not provided.");
            }

            return(user, result);
        }
Example #9
0
        private static async Task InitializeShoppingList(RecipEaseContext context)
        {
            if (!context.ShoppingList.Any())
            {
                var shoppingLists = new[]
                {
                    new ShoppingList
                    {
                        Name       = "My Shopping List",
                        LastUpdate = DateTime.Now,
                        UserId     = _testCustomerId
                    },
                    new ShoppingList
                    {
                        Name       = "My Shopping List",
                        LastUpdate = DateTime.Now,
                        UserId     = _testCustomerId2
                    },
                    new ShoppingList
                    {
                        Name       = "My Shopping List",
                        LastUpdate = DateTime.Now,
                        UserId     = _testCustomerId3
                    },
                };
                await context.ShoppingList.AddRangeAsync(shoppingLists);
            }

            if (!context.IngrInShoppingList.Any())
            {
                var ingrInShoppingLists = new[]
                {
                    new IngrInShoppingList()
                    {
                        Quantity = 2,
                        IngrName = Flour,
                        UserId   = _testCustomerId,
                        UnitName = Grams
                    },
                    new IngrInShoppingList()
                    {
                        Quantity = 3,
                        IngrName = GoatMilk,
                        UserId   = _testCustomerId,
                        UnitName = Cups
                    },
                    new IngrInShoppingList()
                    {
                        Quantity = 100,
                        IngrName = Flour,
                        UserId   = _testCustomerId2,
                        UnitName = Grams
                    },
                    new IngrInShoppingList()
                    {
                        Quantity = 3,
                        IngrName = Rice,
                        UserId   = _testCustomerId2,
                        UnitName = Cups
                    },
                    new IngrInShoppingList()
                    {
                        Quantity = 5,
                        IngrName = Flour,
                        UserId   = _testCustomerId3,
                        UnitName = Cups
                    },
                };
                await context.IngrInShoppingList.AddRangeAsync(ingrInShoppingLists);
            }

            await context.SaveChangesAsync();
        }
Example #10
0
        private static async Task InitializeUsers(RecipEaseContext context, UserManager <User> userManager)
        {
            var existingCustomer = await context.Customer.OrderBy(customer => customer.UserId).FirstOrDefaultAsync();

            if (existingCustomer == null)
            {
                var customer1Info = new Customer()
                {
                    CustomerName = "Calum Sieppert",
                    Age          = 20,
                    Weight       = 160,
                    FavMeal      = Meal.Lunch,
                };
                var(customer, _) = await
                                   Users.CreateUser(userManager, context, Users.AccountType.Customer,
                                                    TestCustomerUsername, TestCustomerPassword, customerInfo : customer1Info);

                _testCustomerId = customer.Id;

                var customer2Info = new Customer()
                {
                    CustomerName = "Sajid Choudhry",
                    Age          = 20,
                    Weight       = 160,
                    FavMeal      = Meal.Dinner,
                };
                (customer, _) = await
                                Users.CreateUser(userManager, context, Users.AccountType.Customer,
                                                 "c2@c2", "c2", customerInfo : customer2Info);

                _testCustomerId2 = customer.Id;

                var customer3Info = new Customer()
                {
                    CustomerName = "Khoa Nguyen Tran Dang",
                    Age          = 20,
                    Weight       = 160,
                    FavMeal      = Meal.Breakfast,
                };
                (customer, _) = await
                                Users.CreateUser(userManager, context, Users.AccountType.Customer,
                                                 "c3@c3", "c3", customerInfo : customer3Info);

                _testCustomerId3 = customer.Id;
            }
            else
            {
                _testCustomerId = existingCustomer.UserId;
            }

            var existingSupplier = await context.Supplier.OrderBy(customer => customer.UserId).FirstOrDefaultAsync();

            if (existingSupplier == null)
            {
                var supplierInfo = new Supplier()
                {
                    Email           = "*****@*****.**",
                    Website         = "https://example.com",
                    PhoneNo         = "123-456-7890",
                    SupplierName    = "A Business",
                    StoreVisitCount = 3
                };
                var(supplier, _) = await Users.CreateUser(userManager, context, Users.AccountType.Supplier,
                                                          TestSupplierUsername, TestSupplierPassword, supplierInfo : supplierInfo);

                _testSupplierId = supplier.Id;
            }
            else
            {
                _testSupplierId = existingSupplier.UserId;
            }
        }
Example #11
0
        private static async Task InitializeRecipeRatings(RecipEaseContext context)
        {
            if (!context.RecipeRating.Any())
            {
                var recipeRatings = new[]
                {
                    // new RecipeRating
                    // {
                    //     Rating = 5,
                    //     RecipeId = _recipe0Id,
                    //     UserId = _testCustomerId
                    // },
                    new RecipeRating
                    {
                        Rating   = 4,
                        RecipeId = _recipe1Id,
                        UserId   = _testCustomerId
                    },
                    new RecipeRating
                    {
                        Rating   = 3,
                        RecipeId = _recipe2Id,
                        UserId   = _testCustomerId
                    },
                    new RecipeRating
                    {
                        Rating   = 2,
                        RecipeId = _recipe0Id,
                        UserId   = _testCustomerId2
                    },
                    new RecipeRating
                    {
                        Rating   = 1,
                        RecipeId = _recipe1Id,
                        UserId   = _testCustomerId2
                    },
                    new RecipeRating
                    {
                        Rating   = 5,
                        RecipeId = _recipe2Id,
                        UserId   = _testCustomerId2
                    },
                    new RecipeRating
                    {
                        Rating   = 4,
                        RecipeId = _recipe0Id,
                        UserId   = _testCustomerId3
                    },
                    new RecipeRating
                    {
                        Rating   = 3,
                        RecipeId = _recipe1Id,
                        UserId   = _testCustomerId3
                    },
                    new RecipeRating
                    {
                        Rating   = 2,
                        RecipeId = _recipe2Id,
                        UserId   = _testCustomerId3
                    },
                };

                await context.RecipeRating.AddRangeAsync(recipeRatings);
            }
        }
Example #12
0
        private static async Task InitializeRecipeCategories(RecipEaseContext context)
        {
            var breakfast = "Breakfast";
            var lunch     = "Lunch";
            var dinner    = "Dinner";

            if (!context.RecipeCategory.Any())
            {
                var categories = new[]
                {
                    new RecipeCategory
                    {
                        Name = breakfast,
                        AverageCaloriesCatg = 500,
                        TotalInCatg         = 1,
                    },
                    new RecipeCategory
                    {
                        Name = lunch,
                        AverageCaloriesCatg = 600,
                        TotalInCatg         = 1
                    },
                    new RecipeCategory
                    {
                        Name = dinner,
                        AverageCaloriesCatg = 700,
                        TotalInCatg         = 1,
                    },
                };

                await context.RecipeCategory.AddRangeAsync(categories);

                await context.SaveChangesAsync();
            }

            if (!context.RecipeInCategory.Any())
            {
                var recipeInCategories = new[]
                {
                    new RecipeInCategory
                    {
                        RecipeId     = _recipe0Id,
                        CategoryName = breakfast
                    },
                    new RecipeInCategory
                    {
                        RecipeId     = _recipe1Id,
                        CategoryName = lunch
                    },
                    new RecipeInCategory
                    {
                        RecipeId     = _recipe2Id,
                        CategoryName = dinner
                    },
                };

                await context.RecipeInCategory.AddRangeAsync(recipeInCategories);

                await context.SaveChangesAsync();
            }
        }