Ejemplo n.º 1
0
 /// <summary>
 /// Create role
 /// </summary>
 /// <param name="myRole">the role to add</param>
 public void CreateRole(string myRole)
 {
     if (!MyRoleManager.RoleExists(myRole))
     {
         MyRoleManager.Create(new IdentityRole(myRole));
     }
 }
Ejemplo n.º 2
0
        protected override void Seed(ExtJS_Store.DAL.ApplicationContext context)
        {
            var userManager = new MyUserManager(new UserStore <User>(context));
            var roleManager = new MyRoleManager(new RoleStore <MyRole>(context));

            // создаем две роли
            var role1 = new MyRole {
                Name = "admin"
            };
            var role2 = new MyRole {
                Name = "user"
            };

            // добавляем роли в бд
            roleManager.Create(role1);
            roleManager.Create(role2);

            // создаем пользователей
            var user = new User {
                Email = "*****@*****.**", UserName = "******"
            };
            string password = "******";
            var    result   = userManager.Create(user, password);

            // если создание пользователя прошло успешно
            if (result.Succeeded)
            {
                // добавляем для пользователя роли
                userManager.AddToRole(user.Id, role1.Name);
                userManager.AddToRole(user.Id, role2.Name);
            }

            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //
        }
Ejemplo n.º 3
0
        protected override void Seed(Infrastructure.DbContext.MyIdentityDbContext context)
        {
            MyUserManager userManager = new MyUserManager(new UserStore <MyUser>(context));
            MyRoleManager roleManager = new MyRoleManager(new RoleStore <MyRole>(context));

            string roleName = "Administrator";
            string userName = "******";
            string password = "******";
            string email    = "*****@*****.**";

            if (!roleManager.RoleExists(roleName))
            {
                roleManager.Create(new MyRole(roleName));
            }

            MyUser user = userManager.FindByName(userName);

            if (user == null)
            {
                userManager.Create(new MyUser {
                    UserName = userName, Email = email
                },
                                   password);
                user = userManager.FindByName(userName);
            }

            if (!userManager.IsInRole(user.Id, roleName))
            {
                userManager.AddToRole(user.Id, roleName);
            }
            foreach (MyUser dbUser in userManager.Users)
            {
                if (dbUser.Country == Countries.None)
                {
                    dbUser.SetCountryFromCity(dbUser.City);
                }
            }
            context.SaveChanges();
        }
Ejemplo n.º 4
0
        protected override void Seed(ExtStore2.DAL.ApplicationContext context)
        {
            var userManager = new MyUserManager(new UserStore <User>(context));
            var roleManager = new MyRoleManager(new RoleStore <MyRole>(context));

            // создаем две роли
            var role1 = new MyRole {
                Name = "admin"
            };
            var role2 = new MyRole {
                Name = "user"
            };

            // добавляем роли в бд
            roleManager.Create(role1);
            roleManager.Create(role2);

            // создаем пользователей
            var user = new User
            {
                Email    = "*****@*****.**",
                UserName = "******",
                Name     = "Admin",
                Address  = "My address",
                Code     = "My code",
                Discount = 50
            };
            string password = "******";
            var    result   = userManager.Create(user, password);

            // если создание пользователя прошло успешно
            if (result.Succeeded)
            {
                // добавляем для пользователя роли
                userManager.AddToRole(user.Id, role1.Name);
                userManager.AddToRole(user.Id, role2.Name);
            }

            var products = new List <Product>
            {
                new Product {
                    Name = "Продукт 1", Price = 100, Category = "Category", Code = "Code 1"
                },
                new Product {
                    Name = "Продукт 2", Price = 500, Category = "Category", Code = "Code 2"
                },
                new Product {
                    Name = "Новый продукт 3", Price = 8350, Category = "New category", Code = "New code 1"
                },
                new Product {
                    Name = "Новый продукт 4", Price = 15613, Category = "New category", Code = "New code 2"
                }
            };

            for (int i = 1; i <= 50; i++)
            {
                products.Add(new Product {
                    Name = "Product " + i, Price = i * 1000 + i * 3, Category = "Category " + i, Code = "Code " + i
                });
            }
            ;

            products.ForEach(s => context.Products.AddOrUpdate(p => p.Name, s));
            context.SaveChanges();
        }
Ejemplo n.º 5
0
        protected override void Seed(Hotel.Data.HotelDbContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data.
            if (!context.Roles.Any(r => r.Name == "Admin"))
            {
                var roleManager = new MyRoleManager(new MyRoleStore(context));
                var adminRole   = new IdentityRole("Admin");
                roleManager.Create(adminRole);
            }
            if (!context.Users.Any(u => u.Email == "*****@*****.**"))
            {
                var manager = new UserManager <Employee>(new UserStore <Employee>(context));
                var user    = new Employee()
                {
                    UserName  = "******",
                    Email     = "*****@*****.**",
                    FirstName = "Test",
                    LastName  = "Test"
                };
                manager.Create(user, "123123");
                manager.AddToRole(user.Id, "Admin");
            }
            RoomType basic = new RoomType {
                Id          = 1, Title = "Basic", BasicRate = 10, LivingRoomsCount = 1, ImageUrl = "basic.jpg",
                Description = "Basic setup for comfortable living with all needed features."
            };
            RoomType normal = new RoomType {
                Id          = 2, Title = "Normal", BasicRate = 15, LivingRoomsCount = 2, ImageUrl = "normal.jpg",
                Description = "Extend format for comfortable living with one additional room."
            };
            RoomType business = new RoomType {
                Id          = 3, Title = "Business", BasicRate = 20, LivingRoomsCount = 3, ImageUrl = "business.jpg",
                Description = "Basic setup for comfortable living with all needed features."
            };
            RoomType luxury = new RoomType {
                Id          = 4, Title = "Luxury", BasicRate = 35, LivingRoomsCount = 5, ImageUrl = "luxury.jpg",
                Description = "The best apartments with perfecrt view of the city for our best guests."
            };

            context.RoomTypes.AddOrUpdate(basic);
            context.RoomTypes.AddOrUpdate(normal);
            context.RoomTypes.AddOrUpdate(business);
            context.RoomTypes.AddOrUpdate(luxury);

            RoomFeature condition = new RoomFeature {
                Id = 1, Title = "Air condition", Description = "High quility air condition", AdditionalCost = 2
            };
            RoomFeature miniBar = new RoomFeature {
                Id = 2, Title = "Minibar", Description = "Unlimited minibar", AdditionalCost = 3
            };

            context.RoomFeatures.AddOrUpdate(condition);
            context.RoomFeatures.AddOrUpdate(miniBar);

            Room basicRoom = new Room {
                Id = 1, Floor = 2, MaxVisitorsCount = 1, Type = basic, Title = "Basic room", ImageUrl = "basic.jpg"
            };
            Room normalRoom = new Room {
                Id       = 2, Floor = 2, MaxVisitorsCount = 2, Type = normal, Title = "Normal room", ImageUrl = "normal.jpg",
                Features = new System.Collections.Generic.List <RoomFeature> {
                    condition
                }
            };
            Room businessRoom = new Room {
                Id       = 3, Floor = 5, MaxVisitorsCount = 2, Type = business, Title = "Business room", ImageUrl = "business.jpg",
                Features = new System.Collections.Generic.List <RoomFeature> {
                    condition, miniBar
                }
            };

            context.Rooms.AddOrUpdate(basicRoom);
            context.Rooms.AddOrUpdate(normalRoom);
            context.Rooms.AddOrUpdate(businessRoom);
        }