Exemple #1
0
        public async Task <JournalReadListResponse> GetJournalsOfUser(UserJournalReadListRequest request)
        {
            var response = new JournalReadListResponse();

            var user = _cacheManager.GetCachedUser(request.UserUid);

            if (user == null)
            {
                response.SetInvalidBecauseNotFound("user");
                return(response);
            }

            Expression <Func <Journal, bool> > filter = x => x.UserId == user.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);
        }
Exemple #3
0
        public async Task <JournalReadListResponse> GetJournalsOfOrganization(OrganizationJournalReadListRequest request)
        {
            var response = new JournalReadListResponse();

            var organization = _cacheManager.GetCachedOrganization(request.OrganizationUid);

            if (organization == null)
            {
                response.SetInvalidBecauseEntityNotFound();
                return(response);
            }

            Expression <Func <Journal, bool> >   filter        = x => x.OrganizationId == organization.Id;
            Expression <Func <Journal, object> > orderByColumn = x => x.Id;

            var 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);
        }