public async Task <JournalReadListResponse> GetJournalsOfOrganization(OrganizationJournalReadListRequest request) { var response = new JournalReadListResponse(); var organization = _cacheManager.GetCachedOrganization(request.OrganizationUid); if (organization == null) { response.SetInvalidBecauseNotFound("organization"); return(response); } Expression <Func <Journal, bool> > filter = x => x.OrganizationId == organization.Id; var entities = await _journalRepository.SelectMany(filter, request.PagingInfo.Skip, request.PagingInfo.Take, x => x.Id, request.PagingInfo.IsAscending); if (entities != null) { for (var i = 0; i < entities.Count; i++) { var entity = entities[i]; var dto = _journalFactory.CreateDtoFromEntity(entity); response.Items.Add(dto); } } response.PagingInfo.Skip = request.PagingInfo.Skip; response.PagingInfo.Take = request.PagingInfo.Take; response.PagingInfo.LastUid = request.PagingInfo.LastUid; response.PagingInfo.IsAscending = request.PagingInfo.IsAscending; response.PagingInfo.TotalItemCount = await _journalRepository.Count(filter); response.Status = ResponseStatus.Success; return(response); }
public async Task <JournalReadListResponse> GetJournals(AllJournalReadListRequest request) { var response = new JournalReadListResponse(); var currentUser = _cacheManager.GetCachedCurrentUser(request.CurrentUserId); if (!currentUser.IsSuperAdmin) { response.SetInvalid(); return(response); } Expression <Func <Journal, object> > orderByColumn = x => x.Id; Expression <Func <Journal, bool> > filter = null; if (request.SearchTerm.IsNotEmpty()) { filter = x => x.Name.Contains(request.SearchTerm); } List <Journal> entities; if (request.PagingInfo.Skip < 1) { entities = await _journalRepository.SelectAfter(filter, request.PagingInfo.LastUid, request.PagingInfo.Take, orderByColumn, request.PagingInfo.IsAscending); } else { entities = await _journalRepository.SelectMany(filter, request.PagingInfo.Skip, request.PagingInfo.Take, orderByColumn, request.PagingInfo.IsAscending); } if (entities != null) { for (var i = 0; i < entities.Count; i++) { var entity = entities[i]; var dto = _journalFactory.CreateDtoFromEntity(entity); response.Items.Add(dto); } } response.PagingInfo.Skip = request.PagingInfo.Skip; response.PagingInfo.Take = request.PagingInfo.Take; response.PagingInfo.LastUid = request.PagingInfo.LastUid; response.PagingInfo.IsAscending = request.PagingInfo.IsAscending; response.PagingInfo.TotalItemCount = await _journalRepository.Count(filter); response.Status = ResponseStatus.Success; return(response); }