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(); } } }
private YearApPermissionLevels GetUserRole(string userEmail) { using (var scope = WebHost.Services.CreateScope()) { var services = scope.ServiceProvider; manager = services.GetService <IAccountManagementService>(); return(manager.GetAccountInfoByEmail(userEmail).Role); } }
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 }); } }
public AccountInfo GetRole() { return(_accountManager.GetAccountInfoByEmail(User.Identity.Name)); }