Exemple #1
0
        public static void ConfigureIposMemberShip(IPosDbContext context)
        {
            var appMembershipSettings = new List <aspnet_SchemaVersions>
            {
                new aspnet_SchemaVersions {
                    Feature = "membership", CompatibleSchemaVersion = "1", IsCurrentVersion = true
                },
                new aspnet_SchemaVersions {
                    Feature = "health monitoring", CompatibleSchemaVersion = "1", IsCurrentVersion = true
                },
                new aspnet_SchemaVersions {
                    Feature = "personalization", CompatibleSchemaVersion = "1", IsCurrentVersion = true
                },
                new aspnet_SchemaVersions {
                    Feature = "common", CompatibleSchemaVersion = "1", IsCurrentVersion = true
                },
                new aspnet_SchemaVersions {
                    Feature = "profile", CompatibleSchemaVersion = "1", IsCurrentVersion = true
                },
                new aspnet_SchemaVersions {
                    Feature = "role manager", CompatibleSchemaVersion = "1", IsCurrentVersion = true
                }
            };

            context.Set <aspnet_SchemaVersions>().AddOrUpdate(p => p.Feature, appMembershipSettings.ToArray());
            context.SaveChanges();
        }
Exemple #2
0
        public static void CreateTestData(IPosDbContext context, ApplicationIdentityUser user)
        {
            //old db
            var connetionString = ConfigurationManager.ConnectionStrings["OldIPosDbContext"];

            var categories = ImportExistingData <Category>(connetionString.ConnectionString).Result;

            categories.ToList().ForEach((e) =>
            {
                e.CreatedBy_Id = user.Id;
            });
            context.Set <Category>().AddOrUpdate(p => p.CategoryUId, categories.ToArray());
            context.SaveChanges();

            var adminUser = IposMembershipService.GetUserId("*****@*****.**");
            var products  = ImportExistingData <Product>(connetionString.ConnectionString).Result;

            products.ToList().ForEach((e) =>
            {
                e.CreatedBy_Id = user.Id;
                e.Category_UId = Rand.Next(1, categories.Count());
                e.Insert_UId   = adminUser;
            });
            context.Set <Product>().AddOrUpdate(p => p.ProductUId, products.ToArray());
            context.SaveChanges();
        }
Exemple #3
0
        public static ApplicationIdentityUser CreateAdminUser(IPosDbContext context)
        {
            var applicationUserManager = IdentityFactory.CreateUserManager(context);

            string username = "******";
            string password = "******";

            ApplicationIdentityUser user = applicationUserManager.FindByNameAsync(username).Result;

            if (user != null)
            {
                return(user);
            }

            user = new ApplicationIdentityUser
            {
                UserName = username,
                Email    = username
            };


            if (IposConfig.UseMembership)
            {
                IposMembershipService.CreateUserAccount(new AppUserViewModel {
                    UserName = username, Password = password
                });
            }


            applicationUserManager.CreateAsync(user, password).Wait();
            applicationUserManager.SetLockoutEnabled(user.Id, false);
            applicationUserManager.Update(user);

            var isInRole = applicationUserManager.IsInRoleAsync(user.Id, IposRoleHelper.ADMIN);

            if (user != null && !isInRole.Result)
            {
                applicationUserManager.AddToRoleAsync(user.Id, IposRoleHelper.ADMIN).Wait();
            }
            return(user);
        }
Exemple #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Ipos v2 user account migrator... \n");

            List <UserRoleViewModel> oldUsers;

            using (var oldIposDbCtxt = new DbContext("OldIPosDbContext"))
            {
                oldUsers = oldIposDbCtxt.Database.SqlQuery <UserRoleViewModel>(@"Select userName,RoleName from [dbo].[aspnet_Users] u,
                                                                    [dbo].[aspnet_roles] r,
                                                                    [dbo].[aspnet_UsersInRoles] ur
                                                                     Where u.UserId = ur.UserId
                                                                     and ur.RoleId = r.RoleId
                                                                     and UserName != 'admin'").ToList();
            }

            if (oldUsers.Count > 0)
            {
                using (var db = new IPosDbContext())
                {
                    var p = new Program(db);

                    foreach (var oldUser in oldUsers)
                    {
                        var newUser = p.CreateUser(oldUser.UserName, "Micr0s0ft_");
                        if (newUser != null)
                        {
                            p.AddToRole(oldUser.RoleName, newUser);
                        }
                        Console.WriteLine("Successfully migrated User: {0} with Role: {1} to Ipos V2.", oldUser.UserName, oldUser.RoleName);
                    }
                }
                Console.WriteLine("User migration was successful.");
            }
            else
            {
                Console.WriteLine("There was no user to migrate.");
            }
            Console.ReadLine();
        }
Exemple #5
0
        public static void CreateRoles(IPosDbContext context)
        {
            String[] roleNames = new String[]
            {
                IposRoleHelper.ADMIN,
                IposRoleHelper.STAFF,
                IposRoleHelper.SUPPORT,
                IposRoleHelper.SUPERADMIN,
            };

            var applicationRoleManager = IdentityFactory.CreateRoleManager(context);

            Array.ForEach(roleNames, (string roleName) =>
            {
                var roleResult = applicationRoleManager.RoleExistsAsync(roleName);
                if (!roleResult.Result)
                {
                    applicationRoleManager.CreateAsync(new ApplicationIdentityRole {
                        Name = roleName
                    }).Wait();
                }
            });
        }