public async Task <RecordsPage <DeletedMessageSummary> > SearchDeletedMessagesAsync( DeletedMessageSearchCriteria searchCriteria, IEnumerable <SortingCriteria> sortingCriteria, PagingCriteria pagingCriteria) { _authorizationService.RequireClaims(AuthorizationClaim.LogViewDeletedMessages); return(await _deletedMessageRepository.SearchSummariesPagedAsync(searchCriteria, sortingCriteria, pagingCriteria)); }
public async Task <IActionResult> DeletedMessagesAsync() { var buffer = new byte[Request.ContentLength.Value]; await Request.Body.ReadAsync(buffer, 0, (int)Request.ContentLength); var json = Encoding.UTF8.GetString(buffer); var tableParams = JsonConvert.DeserializeObject <TableParameters>(json); var sortProperty = DeletedMessageSummary.SortablePropertyNames.FirstOrDefault( x => x.Equals(tableParams.Sort.Field, StringComparison.OrdinalIgnoreCase)) ?? nameof(DeletedMessageSummary.Created); var searchCriteria = new DeletedMessageSearchCriteria() { GuildId = UserGuild.Id }; foreach (var filter in tableParams.Filters) { searchCriteria.WithPropertyValue(filter.Field, filter.Value); } var result = await ModerationService.SearchDeletedMessagesAsync(searchCriteria, new[] { new SortingCriteria { PropertyName = sortProperty, Direction = tableParams.Sort.Direction, } }, new PagingCriteria { FirstRecordIndex = tableParams.Page *tableParams.PerPage, PageSize = tableParams.PerPage, }); var mapped = new { result.TotalRecordCount, result.FilteredRecordCount, Records = result.Records.Select( x => new { Channel = x.Channel.Name, Author = x.Author.DisplayName, x.Created, CreatedBy = x.CreatedBy.DisplayName, x.Content, x.Reason, x.BatchId, }), }; return(Ok(mapped)); }
public async Task <IActionResult> DeletedMessagesAsync([FromBody] TableParameters tableParams) { var sortProperty = DeletedMessageSummary.SortablePropertyNames.FirstOrDefault( x => x.Equals(tableParams.Sort.Field, StringComparison.OrdinalIgnoreCase)) ?? nameof(DeletedMessageSummary.Created); var searchCriteria = new DeletedMessageSearchCriteria() { GuildId = UserGuild.Id }; foreach (var filter in tableParams.Filters) { searchCriteria.WithPropertyValue(filter.Field, filter.Value); } var result = await ModerationService.SearchDeletedMessagesAsync(searchCriteria, new[] { new SortingCriteria { PropertyName = sortProperty, Direction = tableParams.Sort.Direction, } }, new PagingCriteria { FirstRecordIndex = tableParams.Page *tableParams.PerPage, PageSize = tableParams.PerPage, }); var mapped = new { result.TotalRecordCount, result.FilteredRecordCount, Records = result.Records.Select( x => new { Channel = x.Channel.Name, Author = x.Author.GetFullUsername(), x.Created, CreatedBy = x.CreatedBy.GetFullUsername(), x.Content, x.Reason, x.BatchId, }), }; return(Ok(mapped)); }
/// <inheritdoc /> public async Task <RecordsPage <DeletedMessageSummary> > SearchSummariesPagedAsync( DeletedMessageSearchCriteria searchCriteria, IEnumerable <SortingCriteria> sortingCriteria, PagingCriteria pagingCriteria) { var sourceQuery = ModixContext.Set <DeletedMessageEntity>().AsNoTracking(); var filteredQuery = sourceQuery .FilterBy(searchCriteria); var pagedQuery = filteredQuery .AsExpandable() .Select(DeletedMessageSummary.FromEntityProjection) .SortBy(sortingCriteria, DeletedMessageSummary.SortablePropertyMap) .OrderThenBy(x => x.MessageId, SortDirection.Ascending) .PageBy(pagingCriteria); return(new RecordsPage <DeletedMessageSummary>() { TotalRecordCount = await sourceQuery.LongCountAsync(), FilteredRecordCount = await filteredQuery.LongCountAsync(), Records = await pagedQuery.ToArrayAsync(), }); }