public Task <CustomFieldListGetResponse[]> GetArray(CustomFieldListGetRequest dto)
        {
            var query = DbSession.Query <CustomFieldIndexedForList, CustomFields_ForList>();

            query = ApplyFilters(query, dto);

            return(query.OrderBy(cf => cf.Name)
                   .ProjectInto <CustomFieldListGetResponse>()
                   .ToArrayAsync());
        }
Пример #2
0
        public Task <CustomFieldListGetResponse[]> GetArray(CustomFieldListGetRequest dto)
        {
            var query = DbSession.Query <CustomFieldIndexedForList, CustomFields_ForList>()
                        .OrderBy(cf => cf.Name);

            if (dto.Ids?.Any() == true)
            {
                IEnumerable <string> fullIds = dto.Ids.Select(GetFullId);

                query = query.Where(cf => cf.Id.In(fullIds));
            }

            return(query.ProjectInto <CustomFieldListGetResponse>().ToArrayAsync());
        }
        public async Task <ListResponse <CustomFieldListGetResponse> > GetList(CustomFieldListGetRequest dto)
        {
            var query = DbSession.Query <CustomFieldIndexedForList, CustomFields_ForList>();

            query = ApplyFilters(query, dto);

            var totalRecords = await query.CountAsync();

            query = ApplySorting(query, dto);
            query = query.Skip(dto.PageIndex * dto.PageSize).Take(dto.PageSize);

            var ret = await(from cf in query
                            select new CustomFieldListGetResponse
            {
                Id               = cf.Id,
                Name             = cf.Name,
                FieldType        = cf.FieldType,
                IsMandatory      = cf.IsMandatory,
                BacklogItemTypes = cf.BacklogItemTypes
            }
                            ).ToListAsync();

            return(new ListResponse <CustomFieldListGetResponse>(ret, totalRecords, dto.PageIndex, dto.PageSize));
        }
Пример #4
0
 public Task <ListResponse <CustomFieldListGetResponse> > GetList([FromServices] ICustomFieldListQueryService service,
                                                                  [FromQuery] CustomFieldListGetRequest dto)
 => service.GetList(dto);
        private IRavenQueryable <CustomFieldIndexedForList> ApplySorting(IRavenQueryable <CustomFieldIndexedForList> query, CustomFieldListGetRequest dto)
        {
            if (dto.OrderBy == CustomFieldOrderColumns.Default)
            {
                dto.OrderBy        = CustomFieldOrderColumns.Name;
                dto.OrderDirection = OrderDirections.Asc;
            }

            return(dto.OrderBy switch
            {
                CustomFieldOrderColumns.Name
                or CustomFieldOrderColumns.Default => dto.OrderDirection == OrderDirections.Asc ? query.OrderBy(t => t.Name)               : query.OrderByDescending(t => t.Name),
                CustomFieldOrderColumns.Type => dto.OrderDirection == OrderDirections.Asc ? query.OrderBy(t => t.FieldType)  : query.OrderByDescending(t => t.FieldType),
                _ => throw new ArgumentOutOfRangeException($"Unsupported 'order by' - {dto.OrderBy}")
            });
        private IRavenQueryable <CustomFieldIndexedForList> ApplyFilters(IRavenQueryable <CustomFieldIndexedForList> query, CustomFieldListGetRequest dto)
        {
            if (dto.Ids?.Any() == true)
            {
                IEnumerable <string> fullIds = dto.Ids.Select(GetFullId);
                query = query.Where(cf => cf.Id.In(fullIds));
            }
            if (dto.BacklogItemType.HasValue)
            {
                query = query.Where(cf => cf.BacklogItemTypes !.Any() == false || cf.BacklogItemTypes !.Contains(dto.BacklogItemType));
            }

            return(query);
        }
Пример #7
0
 public Task <CustomFieldListGetResponse[]> GetList([FromServices] ICustomFieldQueryService service,
                                                    [FromQuery] CustomFieldListGetRequest dto
                                                    )
 => service.GetArray(dto);