public async Task <Result <AuditModel> > Cancel( AuditOperationTypes operationType, string message, object auditObject, Guid?objectId, Guid creatorId, SrbacRoles role ) { var obj = JsonConvert.SerializeObject( auditObject, Formatting.None, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore } ); var res = await _auditRepository.Create( new AuditModel { OperationType = operationType, Status = AuditStatuses.Cancelled, Roles = role, Comment = message, ObjectDescription = obj, ObjectId = objectId, CreatorId = creatorId } ); return(new Result <AuditModel>(res)); }
public bool CheckPermission(SrbacRoles role, SrbacPermissions permission) { var res = _srbacRepository.RolesPermissions.FirstOrDefault( p => p.Permission == permission && p.Role == role ); return(res != null); }
public async Task <bool> CheckPermission(SrbacRoles role, SrbacPermissions srbacPermission) { using IDbConnection db = new NpgsqlConnection(ConnectionString); return(await db.QueryFirstOrDefaultAsync <bool>( @$ " SELECT true FROM {TableName} WHERE Role = @Role AND Permission = @Permission ", new { Role = role, Permission = srbacPermission } )); }
public async Task ChangeTokenActivityForUser(Guid userId, SrbacRoles role, bool isActive) { using IDbConnection db = new NpgsqlConnection(ConnectionString); await db.ExecuteAsync( @$ " UPDATE {TableName} SET IsActive = @IsActive WHERE UserId = @UserId AND Role = @Role ", new { UserId = userId, Role = role, IsActive = isActive } ); }
public async Task <bool> HasActiveToken(Guid tokenId, Guid userId, SrbacRoles role) { using IDbConnection db = new NpgsqlConnection(ConnectionString); return(await db.QueryFirstOrDefaultAsync <bool>( @$ " {GetBaseSelectQuery()} WHERE UserId = @UserId AND Role = @Role AND Id = @TokenId AND IsActive = true ", new { UserId = userId, Role = role, Id = tokenId } )); }
public async Task <string> CreateFromBase64( FilesTypes fileType, Guid entityId, Guid creatorId, SrbacRoles creatorRole, string contentBase64 = null, string fileName = null ) { try { if (string.IsNullOrWhiteSpace(contentBase64)) { return(null); } if (string.IsNullOrWhiteSpace(fileName)) { fileName = Guid.NewGuid().ToString(); } var name = Path.GetFileNameWithoutExtension(fileName); var extension = GetFileExtension(contentBase64); using var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled); var fileModel = await _fileRepository.Create(new FileModel { EntityType = fileType, Extension = extension, Name = name, EntityId = entityId, CreatorId = creatorId }); var path = Path.Combine( _fileStorageConfiguration.AbsolutePath, fileType.ToString(), entityId.ToString() ); Directory.CreateDirectory(path); var filePath = Path.Combine(path, $"{fileModel.Id.ToString()}.{extension}"); await File.WriteAllBytesAsync(filePath, Convert.FromBase64String(contentBase64)); await _auditService.Success( AuditOperationTypes.CreateFile, "", fileModel, fileModel.Id, creatorId, creatorRole ); scope.Complete(); return(await GetFileUrl(entityId, fileType)); } catch (Exception e) { await _auditService.Error( AuditOperationTypes.CreateFile, e.Message, new AuditErrorObjectContainer { Model = new FileModel { EntityType = fileType, Name = fileName, EntityId = entityId }, Error = e }, null, creatorId, creatorRole ); throw; } }
public async Task <IEnumerable <string> > GetAllActivePushTokenByUser(Guid userId, SrbacRoles role) { using IDbConnection db = new NpgsqlConnection(ConnectionString); return(await db.QueryAsync <string>( @$ " SELECT PushToken FROM {TableName} WHERE UserId = @UserId AND Role = @Role AND IsActive = true ", new { UserId = userId, Role = role, } )); }