예제 #1
0
        private void CreateDefaultUser()
        {
            var email = _configuration["DefaultUserEmail"];

            using (var transaction = _dbContext.Database.BeginTransaction()) {
                try {
                    if (_accountManager.CreateUser(email) &&
                        _accountManager.CreateDefaultRoles() &&
                        _accountManager.SetUserRole(
                            email,
                            new SingleAccountEdit()
                    {
                        Permission = YearApPermissionLevels.Admin,
                        VersionStamp = _accountManager.GetAccountInfoByEmail(email).LastUpdate
                    }))
                    {
                        transaction.Commit();
                        _emailService.SendMessage(email,
                                                  _configuration["WelcomeEmail:Subject"],
                                                  _configuration["WelcomeEmail:Text"]);
                    }
                    else
                    {
                        transaction.Rollback();
                    }
                }catch (Exception e) {
                    Console.WriteLine(e.Message);
                    transaction.Rollback();
                }
            }
        }
예제 #2
0
 private YearApPermissionLevels GetUserRole(string userEmail)
 {
     using (var scope = WebHost.Services.CreateScope()) {
         var services = scope.ServiceProvider;
         manager = services.GetService <IAccountManagementService>();
         return(manager.GetAccountInfoByEmail(userEmail).Role);
     }
 }
예제 #3
0
        private void ThereIsUserWithRole(string userEmail, YearApPermissionLevels role)
        {
            using (var scope = WebHost.Services.CreateScope()) {
                var services = scope.ServiceProvider;
                manager = services.GetService <IAccountManagementService>();

                manager.CreateUser(userEmail);
                var accountInfo = manager.GetAccountInfoByEmail(userEmail);
                manager.SetUserRole(userEmail, new SingleAccountEdit()
                {
                    Permission = role, VersionStamp = accountInfo.LastUpdate
                });
            }
        }
예제 #4
0
 public AccountInfo GetRole()
 {
     return(_accountManager.GetAccountInfoByEmail(User.Identity.Name));
 }