Exemple #1
0
        public async Task <IntegrationReadListResponse> GetIntegrations(IntegrationReadListRequest request)
        {
            var response = new IntegrationReadListResponse();

            var currentUser = _cacheManager.GetCachedCurrentUser(request.CurrentUserId);

            Expression <Func <Integration, bool> >   filter        = x => x.OrganizationId == currentUser.OrganizationId;
            Expression <Func <Integration, object> > orderByColumn = x => x.Id;

            if (request.SearchTerm.IsNotEmpty())
            {
                filter = x => x.OrganizationId == currentUser.OrganizationId && x.Name.Contains(request.SearchTerm);
            }

            List <Integration> entities;

            if (request.PagingInfo.Skip < 1)
            {
                entities = await _integrationRepository.SelectAfter(filter, request.PagingInfo.LastUid, request.PagingInfo.Take, orderByColumn, request.PagingInfo.IsAscending);
            }
            else
            {
                entities = await _integrationRepository.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    = _integrationFactory.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 _integrationRepository.Count(filter);

            response.Status = ResponseStatus.Success;
            return(response);
        }