コード例 #1
0
ファイル: AdminServices.cs プロジェクト: gomaltao/HRM
 public BasicResult AddStandardUser(string adminEmail,   string UserID, string firstName, string lastName, string phoneNumber, string userName, string userCode, string email = "" )
 {
     var usr = uow.UserRepository.GetEagerLoad(w =>
     w.UserID.Equals(UserID, StringComparison.OrdinalIgnoreCase)
     && w.AdminEmail.Equals( adminEmail, StringComparison.OrdinalIgnoreCase)
     ).FirstOrDefault();
     if (usr != null)
     {
         return new BasicResult(false, "user already exists", null);
     }
         var user = new User()
         { AdminEmail = adminEmail,  UserID = UserID, FirstName = firstName, LastName = lastName, PhoneNumber = phoneNumber, UserName = userName, UserCode = userCode, Email = email  };
         uow.UserRepository.Insert(user);
         uow.Save();
         return new BasicResult(true, "user created", null);
 }
コード例 #2
0
ファイル: Startup.cs プロジェクト: gomaltao/HRM
        private async Task Seed(IUnitOfWork uow  , UserManager<ApplicationUser> usrMan, RoleManager<IdentityRole> _RoleManager)
        {

            var email = "*****@*****.**";
            var RoleName = "CustomerAdmin";
            var role = await _RoleManager.FindByNameAsync(RoleName);
            if (role == null)
            {
                role = new IdentityRole { Name = RoleName };
                await _RoleManager.CreateAsync(role);
            }

        RoleName = "superadmin";
            role = await _RoleManager.FindByNameAsync( RoleName );
            if ( role == null)
            {
                role = new IdentityRole { Name = "SuperAdmin" };
                await _RoleManager.CreateAsync(role);
            }
            
            var appUser = await usrMan.FindByEmailAsync(email);
            if (appUser != null)
            {
                var result = await usrMan.DeleteAsync(appUser);
            }
            else 
            {
                appUser = new ApplicationUser() { UserName = email, Email = email };
                var result2 = await usrMan.CreateAsync(appUser, "Shafiro2,");
                if (result2.Succeeded)
                {
                    await usrMan.AddToRoleAsync(appUser,  RoleName ); 
                    var hrmUser = new User()
                    {
                        UserID = "7310209296",
                        FirstName = "Gabriel",
                        LastName = "Tekin",
                        UserName = "******",
                        UserCode = "tekgab",
                        PhoneNumber = "0702385537"
                    };
                    if (uow.UserRepository.GetEagerLoad( w => w.UserID.Equals( hrmUser.UserID, StringComparison.OrdinalIgnoreCase )).FirstOrDefault()   == null )
                    {
                        uow.UserRepository.Insert(hrmUser);
                        uow.Save();
                    }
                    
                }
                else
                {
                    var code = result2.Errors.FirstOrDefault().Code;
                }
            }

            } // method seed