public async Task <PagedResult <NotificationMessageDto> > GetPendingMessagesAsync(string tenantId, NotificationTypesDto notificationType, int?take = null) { ArgumentValidation.ValidateString(nameof(tenantId), tenantId); var tenantContext = await _systemContext.CreateOrGetTenantContext(tenantId); var session = await tenantContext.Repository.StartSessionAsync(); session.StartTransaction(); var result = await tenantContext.Repository.GetRtEntitiesByTypeAsync <RtSystemNotificationMessage>(session, new DataQueryOperation { FieldFilters = new[] { new FieldFilter(nameof(RtSystemNotificationMessage.SendStatus), FieldFilterOperator.Equals, SendStatusDto.Pending), new FieldFilter(nameof(RtSystemNotificationMessage.LastTryDateTime), FieldFilterOperator.LessEqualThan, DateTime.UtcNow.AddMinutes(-5)), new FieldFilter(nameof(RtSystemNotificationMessage.NotificationType), FieldFilterOperator.Equals, notificationType), } }); await session.CommitTransactionAsync(); return(new PagedResult <NotificationMessageDto>(result.Result.Select(CreateNotificationMessage), 0, take, result.TotalCount)); }
public async Task <PagedResult <NotificationMessageDto> > GetPendingMessagesAsync(string tenantId, NotificationTypesDto notificationType, int?take = null) { ArgumentValidation.ValidateString(nameof(tenantId), tenantId); var getQuery = new GraphQLRequest { Query = GraphQl.GetNotificationMessages, Variables = new { fieldFilters = new[] { new FieldFilterDto { AttributeName = nameof(NotificationMessageDto.SendStatus), Operator = FieldFilterOperatorDto.Equals, ComparisonValue = (int)SendStatusDto.Pending }, new FieldFilterDto { AttributeName = nameof(NotificationMessageDto.LastTryDateTime), Operator = FieldFilterOperatorDto.LessEqualThan, ComparisonValue = DateTime.UtcNow.AddMinutes(-5) }, new FieldFilterDto { AttributeName = nameof(NotificationMessageDto.NotificationType), Operator = FieldFilterOperatorDto.Equals, ComparisonValue = (int)notificationType } }, first = take } }; var result = await _tenantClient.SendQueryAsync <NotificationMessageDto>(getQuery); return(new PagedResult <NotificationMessageDto>(result.Items)); }