Exemplo n.º 1
0
        public async Task CreateDefaultSuperAdmin()
        {
            try
            {
                await _roles.GenerateRolesFromPagesAsync();

                ApplicationUser superAdmin = new ApplicationUser();
                superAdmin.Email          = _superAdminDefaultOptions.Email;
                superAdmin.UserName       = superAdmin.Email;
                superAdmin.EmailConfirmed = true;

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

                if (result.Succeeded)
                {
                    //add to user profile
                    UserProfile profile = new UserProfile();
                    profile.FirstName         = "Super";
                    profile.LastName          = "Admin";
                    profile.Email             = superAdmin.Email;
                    profile.ApplicationUserId = superAdmin.Id;
                    await _context.UserProfile.AddAsync(profile);

                    await _context.SaveChangesAsync();

                    await _roles.AddToRoles(superAdmin.Id);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 2
0
        public async Task CreateDefaultSuperAdmin()
        {
            try
            {
                await _roles.GenerateRolesFromPagesAsync();

                var roles = _roleManager.Roles.ToList();
                //add memberships
                Membership MS_Admin = new Membership();
                MS_Admin.Name = "SuperAdmin";
                await _context.Membership.AddAsync(MS_Admin);

                await _context.SaveChangesAsync();

                Membership MS_User = new Membership();
                MS_User.Name = "User";
                await _context.Membership.AddAsync(MS_User);

                await _context.SaveChangesAsync();

                //add membership role
                foreach (var item in roles)
                {
                    MembershipRole MSRole = new MembershipRole();
                    MSRole.MembershipId = MS_Admin.MembershipId;
                    MSRole.RoleName     = item.Name;
                    await _context.MembershipRole.AddAsync(MSRole);

                    await _context.SaveChangesAsync();
                }

                //add users
                ApplicationUser superAdmin = new ApplicationUser();
                superAdmin.Email          = _superAdminDefaultOptions.Email;
                superAdmin.UserName       = superAdmin.Email;
                superAdmin.EmailConfirmed = true;

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

                if (result.Succeeded)
                {
                    //add to user profile
                    UserProfile profile = new UserProfile();
                    profile.FirstName         = "Super";
                    profile.LastName          = "Admin";
                    profile.Email             = superAdmin.Email;
                    profile.ApplicationUserId = superAdmin.Id;
                    profile.MembershipId      = MS_Admin.MembershipId;
                    await _context.UserProfile.AddAsync(profile);

                    await _context.SaveChangesAsync();

                    await _roles.AddToRoles(superAdmin.Id);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 3
0
        public async Task CreateUserProfile(ApplicationUser existingUser, string firstName, string lastName)
        {
            var profile = _context.UserProfile.SingleOrDefault(x => x.ApplicationUserId.Equals(existingUser.Id));

            if (profile == null)
            {
                await _roles.GenerateRolesFromPagesAsync();

                //add to user profile
                profile = new UserProfile
                {
                    FirstName         = firstName,
                    LastName          = lastName,
                    Email             = existingUser.Email,
                    ApplicationUserId = existingUser.Id
                };
                await _context.UserProfile.AddAsync(profile);

                await _context.SaveChangesAsync();

                await _roles.AddToRoles(existingUser.Id);
            }
        }
Exemplo n.º 4
0
        public async Task CreateDefaultSuperAdmin()
        {
            try
            {
                await _roles.GenerateRolesFromPagesAsync();

                VinarishUser superAdmin = new VinarishUser
                {
                    Email = _superAdminDefaultOptions.Email
                };
                superAdmin.UserName       = superAdmin.Email;
                superAdmin.EmailConfirmed = true;

                IdentityResult result = await _userManager.CreateAsync(superAdmin, _superAdminDefaultOptions.Password);

                if (result.Succeeded)
                {
                    //add to user profile
                    UserProfile profile = new UserProfile
                    {
                        FirstName      = "Farzad",
                        LastName       = "Motallebizaade",
                        Email          = superAdmin.Email,
                        VinarishUserId = superAdmin.Id
                    };
                    await _context.UserProfile.AddAsync(profile);

                    await _context.SaveChangesAsync();

                    await _roles.AddToRoles(superAdmin.Id);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }