public async Task <IdentityResult> CreateAsync(Role role, CancellationToken cancellationToken) { Throw.IfArgumentNull(role, nameof(role)); await _uowManager.PerformAsyncUow <Task>(() => _roleRepository.InsertAsync(role)); _memoryCache.Remove(Key); return(IdentityResult.Success); }
public virtual async Task <IList <string> > GetRolesAsync(User user, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); Throw.IfArgumentNull(user, nameof(user)); return(await _unitOfWorkManager.PerformAsyncUow <Task <IList <string> > >(async() => { var query = from userRole in _userRoleRepository.GetAll() join role in _roleRepository.GetAll() on userRole.RoleId equals role.Id where userRole.UserId == user.Id select role.RoleName; return await Task.FromResult(query.ToList()); })); }
public async Task Configured(IConfigure configure) { await _unitOfWorkManager.PerformAsyncUow(async() => { foreach (var permissionProvider in _permissionProviders) { // get and iterate stereotypical groups of permissions var stereotypes = permissionProvider.GetDefaultStereotypes(); foreach (var stereotype in stereotypes) { var role = await _roleManager.FindByNameAsync(stereotype.Name); if (role == null) { if (_logger.IsEnabled(LogLevel.Information)) { _logger.LogInformation( $"Defining new role {stereotype.Name} for permission stereotype"); } role = new Role { RoleName = stereotype.Name }; await _roleManager.CreateAsync(role); await _unitOfWorkManager.Current.SaveChangesAsync(); } // and merge the stereotypical permissions into that role var stereotypePermissionNames = (stereotype.Permissions ?? Enumerable.Empty <Permission>()).Select(x => x.Name); var currentPermissionNames = (await _roleManager.GetClaimsAsync(role)).Where(x => x.Type == Permission.ClaimType) .Select(x => x.Value).ToList(); var distinctPermissionNames = currentPermissionNames .Union(stereotypePermissionNames) .Distinct(); // update role if set of permissions has increased var additionalPermissionNames = distinctPermissionNames.Except(currentPermissionNames).ToList(); if (additionalPermissionNames.Any()) { foreach (var permissionName in additionalPermissionNames) { if (_logger.IsEnabled(LogLevel.Debug)) { _logger.LogInformation("Default role {0} granted permission {1}", stereotype.Name, permissionName); } await _roleManager.AddClaimAsync(role, new Claim(Permission.ClaimType, permissionName)); } } } } }); }
public async Task DistributeAsync(Guid notificationId) { await _unitOfWorkManager.PerformAsyncUow(async() => { var notification = await _notificationStore.GetNotificationOrNullAsync(notificationId); if (notification == null) { _logger.LogWarning( "NotificationDistributerJob cannot continue since could not found notification by id: " + notificationId); return; } var users = await GetUsers(notification); var userNotifications = await SaveUserNotifications(users, notification); // await _notificationStore.DeleteNotificationAsync(notification); try { var notificationType = Type.GetType(notification.NotificationDataTypeAssemblyQualifiedName); foreach (var notificationChannel in _notificationChannels) { if (!notificationChannel.CanHandle(notificationType)) { continue; } foreach (var userNotificationInfo in userNotifications) { await notificationChannel.ProcessAsync(userNotificationInfo); } } } catch (Exception e) { _logger.LogWarning(e.ToString(), e); } }); }
public async Task SendAsync( string notificationName, INotificationData data = null, EntityIdentifier entityIdentifier = null, NotificationSeverity severity = NotificationSeverity.Info, long[] userIds = null, long[] excludedUserIds = null) { Throw.IfArgumentNull(notificationName, nameof(notificationName)); var notification = new NotificationInfo(_guidGenerator.Create()) { NotificationName = notificationName, NotificationDataTypeAssemblyQualifiedName = data == null ? typeof(NotificationData).AssemblyQualifiedName : data.GetType().AssemblyQualifiedName, EntityTypeName = entityIdentifier?.Type.FullName, EntityTypeAssemblyQualifiedName = entityIdentifier?.Type.AssemblyQualifiedName, EntityId = entityIdentifier?.Id.ToJsonString(), Severity = severity, UserIds = userIds.IsNullOrEmpty() ? null : userIds.Select(uid => uid).JoinAsString(","), ExcludedUserIds = excludedUserIds.IsNullOrEmpty() ? null : excludedUserIds.Select(uid => uid).JoinAsString(","), Data = data?.ToJsonString(), DataTypeName = data?.GetType().AssemblyQualifiedName }; await _unitOfWorkManager.PerformAsyncUow(async() => { await _notificationStore.InsertNotificationAsync(notification); // To get Id of the notification await _unitOfWorkManager.Current.SaveChangesAsync(); if (userIds != null && userIds.Length <= MaxUserCountToDirectlySendANotification) { // We can process the notification since there are not much receivers await _notificationDistributer.DistributeAsync(notification.Id); } else { await _backgroundJobManager .EnqueueAsync <NotificationDistributerJob, NotificationDistributerJobArgs>( new NotificationDistributerJobArgs(notification.Id)); } }); }
public async Task StoreAsync(PersistedGrant grant) { await _unitOfWorkManager.PerformAsyncUow(async() => { var entity = await _persistedGrantRepository.FirstOrDefaultAsync(grant.Key); if (entity == null) { await _persistedGrantRepository.InsertAsync(Mapper.Map <PersistedGrantEntity>(grant)); } else { Mapper.Map(grant, entity); } }); }
public Task InsertAsync(BackgroundJobInfo jobInfo) { return(_unitOfWorkManager.PerformAsyncUow <Task>(() => _backgroundJobRepository.InsertAsync(jobInfo))); }
public async Task InsertSubscriptionAsync(NotificationSubscriptionInfo subscription) { await _unitOfWorkManager.PerformAsyncUow <Task>(async() => { await _notificationSubscriptionRepository.InsertAsync(subscription); await _unitOfWorkManager.Current.SaveChangesAsync(); }); }
public async Task InsertRegistrationAsync(FirebaseRegistration firebaseRegistration) { await _unitOfWorkManager.PerformAsyncUow <Task>(() => _firebaseRegistrationRepository.InsertAsync(firebaseRegistration)); }