Exemple #1
0
        public async Task Seed()
        {
            _context.Database.EnsureCreated();

            // Create User ..
            var user = await _userManager.FindByEmailAsync("*****@*****.**");

            if (user == null)
            {
                user = new UserModel()
                {
                    FirstName    = "omolaja",
                    LastName     = "Ganiu",
                    EmailAddress = "*****@*****.**",
                    Password     = "******"
                };

                var result = await _userManager.CreateAsync(user, user.Password);

                if (result != IdentityResult.Success)
                {
                    throw new InvalidOperationException("Failed to create default user");
                }
            }
            _context.SaveChanges();
            // Create Role

            _context.Role.Add(new Role()
            {
                Name        = "Administration",
                CreatedDate = DateTime.Now,
                CreatedBy   = 1
            });
            _context.Role.Add(new Role()
            {
                Name        = "Users",
                CreatedDate = DateTime.Now,
                CreatedBy   = 1
            });
            _context.SaveChanges();

            _context.UserRole.Add(new UserRole()
            {
                RoleId      = 1,
                UserId      = 1,
                CreatedDate = DateTime.Now,
                CreatedBy   = 1
            });
            await _context.SaveChangesAsync();
        }
Exemple #2
0
        public static void Seed(ShutterCartContext context)
        {
            _context = context;
            _context.Database.EnsureCreated();
            string password = "******";

            var userm = new UserModel()
            {
                FirstName    = "Demo-User",
                LastName     = "Account",
                MiddleName   = "user",
                EmailAddress = "*****@*****.**",
                Password     = password
            };


            string salt = Guid.NewGuid().ToString();

            var user = new User()
            {
                FirstName       = "Demo",
                LastName        = "Admin",
                EmailAddress    = "*****@*****.**",
                Password        = EncryptPassword(password, salt),
                Salt            = salt,
                Address         = "123",
                ApplicationCode = Guid.NewGuid().ToString(),
                Channel         = RegistrationChannel.IsWeb,
                CreatedBy       = 1,
                DateOfBirth     = DateTime.Now,
                Gender          = 1,
                CreatedDate     = DateTime.Now,
                LastLoginDate   = DateTime.Now,
                MiddleName      = "G",
                Mobile          = "08130230146",
                Title           = "Mr",
            };

            user.UserName = $"{user.FirstName}.{user.LastName}{new Random().Next(1000, 24344)}@shuttercart.com";

            _context.Users.Add(user);

            _context.SaveChanges();

            // Create Role

            _context.Role.Add(new Role()
            {
                Name        = "Administration",
                CreatedDate = DateTime.Now,
                CreatedBy   = 1
            });
            _context.Role.Add(new Role()
            {
                Name        = "Users",
                CreatedDate = DateTime.Now,
                CreatedBy   = 1
            });
            _context.SaveChanges();

            _context.UserRole.Add(new UserRole()
            {
                RoleId      = 1,
                UserId      = 1,
                CreatedDate = DateTime.Now,
                CreatedBy   = 1
            });
            _context.SaveChanges();
        }