/// <summary> /// get all audit logs ordered by time /// </summary> /// <param name="paging"></param> /// <param name="userName">empty means unfiltered</param> /// <param name="orderByTimeDescending"></param> /// <returns></returns> public async Task <RServiceResult <(PaginationMetadata PagingMeta, REvent[] Items)> > GetAll(PagingParameterModel paging, string userName, bool orderByTimeDescending) { try { userName = userName == null ? "" : userName.Trim(); var source = orderByTimeDescending ? _context.AuditLogs .Where(l => string.IsNullOrEmpty(userName) || l.UserName == userName) .OrderByDescending(l => l.StartDate) .AsQueryable() : _context.AuditLogs .Where(l => string.IsNullOrEmpty(userName) || l.UserName == userName) .OrderBy(l => l.StartDate) .AsQueryable(); (PaginationMetadata PagingMeta, REvent[] Items)paginatedResult = await QueryablePaginator <REvent> .Paginate(source, paging); return(new RServiceResult <(PaginationMetadata PagingMeta, REvent[] Items)>(paginatedResult)); } catch (Exception exp) { return(new RServiceResult <(PaginationMetadata PagingMeta, REvent[] Items)>((PagingMeta: null, Items: null), exp.ToString())); } }
/// <summary> /// Get User Notifications (paginated version) /// </summary> /// <param name="paging"></param> /// <param name="userId"></param> /// <returns></returns> public async Task <RServiceResult <(PaginationMetadata PagingMeta, RUserNotificationViewModel[] Items)> > GetUserNotificationsPaginated(PagingParameterModel paging, Guid userId) { var source = _context.Notifications .Where(notification => notification.UserId == userId) .OrderByDescending(notification => notification.DateTime) .Select(notification => new RUserNotificationViewModel() { Id = notification.Id, DateTime = notification.DateTime, Status = notification.Status, Subject = notification.Subject, HtmlText = notification.HtmlText }); (PaginationMetadata PagingMeta, RUserNotificationViewModel[] Items)paginatedResult = await QueryablePaginator <RUserNotificationViewModel> .Paginate(source, paging); return(new RServiceResult <(PaginationMetadata PagingMeta, RUserNotificationViewModel[] Items)> ( paginatedResult )); }