Beispiel #1
0
        private void LoadComboBoxCuisinetype()
        {
            CuisineTypes listCuisineTypes = new CuisineTypes();

            cbbCuisineType.DataSource    = listCuisineTypes.ListAllCuisineType();
            cbbCuisineType.DisplayMember = "CuisineTypeName";
            cbbCuisineType.ValueMember   = "IdCuisine";
        }
        private void LoadDropdowlist()
        {
            Ingredients Listingredients = new Ingredients();

            DropDownListIngredient.DataSource     = Listingredients.ListAll();
            DropDownListIngredient.DataTextField  = "Name";
            DropDownListIngredient.DataValueField = "ID";
            DropDownListIngredient.DataBind();

            MeasurementUnits measurementUnits = new MeasurementUnits();

            DropDownListMeasurementUnit.DataSource     = measurementUnits.ListMeasurementUnits();
            DropDownListMeasurementUnit.DataTextField  = "Name";
            DropDownListMeasurementUnit.DataValueField = "ID";
            DropDownListMeasurementUnit.DataBind();

            DifficultieRanges difficultieRanges = new DifficultieRanges();

            DropDownListRecipeDifficulty.DataSource     = difficultieRanges.ListAllDifficutyRanges();
            DropDownListRecipeDifficulty.DataTextField  = "Difficulty";
            DropDownListRecipeDifficulty.DataValueField = "IdDifficulty";
            DropDownListRecipeDifficulty.DataBind();

            TimesToMake timesToMake = new TimesToMake();

            DropDownListTimeToMake.DataSource     = timesToMake.ListAllTimesToMake();
            DropDownListTimeToMake.DataTextField  = "Time";
            DropDownListTimeToMake.DataValueField = "IdTimeToMake";
            DropDownListTimeToMake.DataBind();

            CostRanges costRanges = new CostRanges();

            DropDownListCostRange.DataSource     = costRanges.ListAllCostRanges();
            DropDownListCostRange.DataTextField  = "Cost";
            DropDownListCostRange.DataValueField = "IDcost";
            DropDownListCostRange.DataBind();

            CuisineTypes cuisineTypes = new CuisineTypes();

            DropDownListCuisineType.DataSource     = cuisineTypes.ListAllCuisineType();
            DropDownListCuisineType.DataTextField  = "CuisineTypeName";
            DropDownListCuisineType.DataValueField = "IdCuisine";
            DropDownListCuisineType.DataBind();

            DishCategories dishCategories = new DishCategories();

            CheckBoxListCategory.DataSource     = dishCategories.ListAllDishCategories();
            CheckBoxListCategory.DataTextField  = "DishCategoryName";
            CheckBoxListCategory.DataValueField = "DishCategoryID";
            CheckBoxListCategory.DataBind();
        }
        //made it a task to not hinder loading which is long enough as it is
        public async Task Initialize()
        {
            var test = Database.GetPendingMigrations();

            if (Database.GetPendingMigrations().Any())
            {
                await Database.MigrateAsync();
            }

            //init roles
            if (Roles.ToList().Count < 3)
            {
                Roles.Add(new Microsoft.AspNetCore.Identity.IdentityRole("Admin")
                {
                    Id = "Admin", NormalizedName = "ADMIN"
                });
                Roles.Add(new Microsoft.AspNetCore.Identity.IdentityRole("Manager")
                {
                    Id = "Manager", NormalizedName = "MANAGER"
                });
                Roles.Add(new Microsoft.AspNetCore.Identity.IdentityRole("User")
                {
                    Id = "User", NormalizedName = "USER"
                });
            }
            //init user roles
            if (UserRoles.ToList().Count < 3)
            {
                if (Users.Any(u => u.Email == "*****@*****.**"))
                {
                    var adminUser = Users.First(u => u.Email == "*****@*****.**");
                    if (!UserRoles.Any(ur => ur.UserId == adminUser.Id))
                    {
                        var adminRole = Roles.First(r => r.Name == "Admin");
                        UserRoles.Add(new Microsoft.AspNetCore.Identity.IdentityUserRole <string> {
                            UserId = adminUser.Id, RoleId = adminRole.Id
                        });
                    }
                }
                if (Users.Any(u => u.Email == "*****@*****.**"))
                {
                    var managerUser = Users.First(u => u.Email == "*****@*****.**");
                    if (!UserRoles.Any(ur => ur.UserId == managerUser.Id))
                    {
                        var managerRole = Roles.First(r => r.Name == "Manager");
                        UserRoles.Add(new Microsoft.AspNetCore.Identity.IdentityUserRole <string> {
                            UserId = managerUser.Id, RoleId = managerRole.Id
                        });
                    }
                }
                if (Users.Any(u => u.Email == "*****@*****.**"))
                {
                    var userUser = Users.First(u => u.Email == "*****@*****.**");
                    if (!UserRoles.Any(ur => ur.UserId == userUser.Id))
                    {
                        var userRole = Roles.First(r => r.Name == "User");
                        UserRoles.Add(new Microsoft.AspNetCore.Identity.IdentityUserRole <string> {
                            UserId = userUser.Id, RoleId = userRole.Id
                        });
                    }
                }
            }
            //init some restaurants
            if (Restaurants.ToList().Count < 3)
            {
                Restaurants.Add(new Restaurant("Pizzeria Italiano", "Szlak 34 Kraków"));
                Restaurants.Add(new Restaurant("Hong bao", "Chinatown 120 Chicago"));
                Restaurants.Add(new Restaurant("Wiejskie smaczki", "Wiejska 3 Warszawa"));
            }
            //init some managers
            if (RestaurantManagers.ToList().Count < 3)
            {
                RestaurantManagers.Add(new RestaurantManager(0, "Maciek", "Kowalski", 45));
                RestaurantManagers.Add(new RestaurantManager(0, "Przemek", "Nowak", 35));
                RestaurantManagers.Add(new RestaurantManager(0, "Zdzisław", "Jankowksi", 55));
            }
            //init some cuisine types
            if (CuisineTypes.ToList().Count < 3)
            {
                CuisineTypes.Add(new CuisineType(0, "Chinesse", "China"));
                CuisineTypes.Add(new CuisineType(0, "Fusion", null));
                CuisineTypes.Add(new CuisineType(0, "Italian", "Italy"));
            }
            //init some dishes
            if (Dishes.ToList().Count < 3)
            {
                Dishes.Add(new Dish(0, "Lasagne", MealType.Meat));
                Dishes.Add(new Dish(0, "Fish and chips", MealType.Fish));
                Dishes.Add(new Dish(0, "Fried vegetables", MealType.Vegan));
            }
            //init some discount type
            if (DiscountTypes.ToList().Count < 1)
            {
                DiscountTypes.Add(new DiscountType(0, "Early birds", 8, 16)
                {
                    Amount = 0.2m
                });
            }
            //can we init users from here?
            SaveChanges();
        }