예제 #1
0
        internal static void SeedAdmin(GiftBoxDbContext context)
        {
            const string AdminEmail = "*****@*****.**";
            const string AdminPassword = "******";

            if (context.Users.Any(u => u.Email == AdminEmail))
            {
                return;
            }

            var userManager = new UserManager<User>(new UserStore<User>(context));

            var admin = new User
            {
                FirstName = "Adrian",
                UserRole = "Admin",
                LastName = "Apostolov",
                Email = AdminEmail,
                UserName = "******",
                PhoneNumber = "0889972697",
                ImageUrl = GlobalConstants.DefaultUserPicture,
            };

            userManager.Create(admin, AdminPassword);
            userManager.AddToRole(admin.Id, GlobalConstants.AdminRole);
            userManager.AddToRole(admin.Id, GlobalConstants.UserRole);
            userManager.AddToRole(admin.Id, GlobalConstants.HomeAdministrator);

            context.SaveChanges();
        }
예제 #2
0
        internal static void SeedNeedsCategories(GiftBoxDbContext context)
        {
            if (!context.NeedCategorys.Any())
            {
                    var needCategories = new List<NeedCategory>()
                {
                    new NeedCategory() { Name = "Food" },
                    new NeedCategory() { Name = "Мedicaments" },
                    new NeedCategory() { Name = "Building Materials" }
                };

                context.NeedCategorys.AddOrUpdate(needCategories.ToArray());
                context.SaveChanges();
            }
        }
예제 #3
0
        internal static void SeedRoles(GiftBoxDbContext context)
        {
            if (context.Roles.Any())
            {
                return;
            }

            var roleStore = new RoleStore<IdentityRole>(context);
            var roleManager = new RoleManager<IdentityRole>(roleStore);

            roleManager.Create(new IdentityRole { Name = GlobalConstants.HomeAdministrator });
            roleManager.Create(new IdentityRole { Name = GlobalConstants.AdminRole });
            roleManager.Create(new IdentityRole { Name = GlobalConstants.UserRole });

            context.SaveChanges();
        }
예제 #4
0
        internal static void SeedEventCategories(GiftBoxDbContext context)
        {
            if (!context.EventCategorys.Any())
            {
                    var eventCategories = new List<EventCategory>()
                {
                    new EventCategory() { Name = "Christmas" },
                    new EventCategory() { Name = "Birthday" }
                };

                context.EventCategorys.AddOrUpdate(eventCategories.ToArray());
                context.SaveChanges();
            }
        }