private User EnsureLoginSettings(SharePointAccessInfo accessInfo) { //Persist user and Tenant data if it doesn't already exist and update refresh token var user = new User(); using (var loginService = _loginSettingsService) { var tenantGuid = new Guid(accessInfo.TenantId); var tenant = loginService.GetTenantById(tenantGuid); if (tenant == null) { tenant = new Tenant { TenantId = tenantGuid }; loginService.Add(tenant); } var userGuid = new Guid(accessInfo.UserId); user = loginService.GetUserById(userGuid); if (user == null) { user = new User { UserId = new Guid(accessInfo.UserId), TenantId = tenant.TenantId, RefreshToken = accessInfo.RefreshToken }; loginService.Add(user); } else { user.RefreshToken = accessInfo.RefreshToken; } loginService.Save(); } return(user); }
private User EnsureLoginSettings(SharePointAccessInfo accessInfo) { //Persist user and Tenant data if it doesn't already exist and update refresh token var user = new User(); using (var loginService = _loginSettingsService) { var tenantGuid = new Guid(accessInfo.TenantId); var tenant = loginService.GetTenantById(tenantGuid); if (tenant == null) { tenant = new Tenant { TenantId = tenantGuid }; loginService.Add(tenant); } var userGuid = new Guid(accessInfo.UserId); user = loginService.GetUserById(userGuid); if (user == null) { user = new User { UserId = new Guid(accessInfo.UserId), TenantId = tenant.TenantId, RefreshToken = accessInfo.RefreshToken }; loginService.Add(user); } else { user.RefreshToken = accessInfo.RefreshToken; } loginService.Save(); } return user; }