コード例 #1
0
ファイル: ValuesService.cs プロジェクト: andnied/public
        public ApiCollection GetDtoCollection(ApiCollection entityCollection, BaseSearchParams searchParams)
        {
            if (searchParams.Fields == null)
            {
                var items = _mapper.Map <IEnumerable <ValueReadDto> >(entityCollection.Items);

                return(new ApiCollection(items)
                {
                    TotalCount = entityCollection.TotalCount
                });
            }
            else
            {
                var newItems = new List <object>();

                foreach (var item in entityCollection.Items)
                {
                    newItems.Add(_mapper.DynamicMap(item, searchParams.Fields));
                }

                var result = new ApiCollection(newItems);
                result.TotalCount = entityCollection.TotalCount;

                return(result);
            }
        }
コード例 #2
0
ファイル: ValuesFcd.cs プロジェクト: andnied/public
        public async Task <ApiCollection> GetAll(BaseSearchParams searchParams)
        {
            if (searchParams.Fields != null && !(Helper.AreFieldsValid <Value>(searchParams.Fields)))
            {
                searchParams.Fields = null;
            }

            var items = await _repo.Get(searchParams);

            var result = _service.GetDtoCollection(items, searchParams);

            return(result);
        }
コード例 #3
0
ファイル: BaseHelpers.cs プロジェクト: joffarex/Sharporum
        public static bool IsPaginatonSearchParamsValid(BaseSearchParams searchParams,
                                                        out ErrorResponse errorResponse)
        {
            errorResponse = new ErrorResponse();
            var errors = new List <ErrorModel>();

            if ((searchParams.Limit > 50) || (searchParams.Limit <= 0))
            {
                errors.Add(new ErrorModel
                {
                    Message = "Limit must be between 0 and 50",
                    Name    = nameof(searchParams.Limit),
                });
            }

            if (searchParams.CurrentPage <= 0)
            {
                errors.Add(new ErrorModel
                {
                    Message = "Current Page must not be negative",
                    Name    = nameof(searchParams.CurrentPage),
                });
            }

            if (!string.IsNullOrEmpty(searchParams.SortBy) && !searchParams.SortBy.Equals("CreatedAt") &&
                !searchParams.SortBy.Equals("VoteCount"))
            {
                errors.Add(new ErrorModel
                {
                    Message = "Can not sort by other values than \"CreatedAt\" or \"VoteCount\"",
                    Name    = nameof(searchParams.SortBy),
                });
            }

            foreach (ErrorModel errorModel in errors.Select(error => new ErrorModel
            {
                Name = error.Name,
                Message = error.Message,
            }))
            {
                errorResponse.Errors.Add(errorModel);
            }

            return(!errors.Any());
        }
コード例 #4
0
        public async Task <ApiCollection> Get(BaseSearchParams s)
        {
            var items = _context.Values.Include(v => v.Children);
            var count = items.Count();

            items = items.DynamicSort(s.Sort);
            items = items.Page(s.Page.Value, s.Items.Value);

            IQueryable result = items;

            if (s.Fields != null)
            {
                result = await items.SelectAsync(string.Format("new ({0})", s.Fields));
            }

            var apiCollection = new ApiCollection(await result.ToListAsync())
            {
                TotalCount = count
            };

            return(apiCollection);
        }
コード例 #5
0
        public async Task <IHttpActionResult> Get([FromUri] BaseSearchParams searchParams)
        {
            var items = _valuesFcd.GetAll(searchParams);

            return(Ok(await items));
        }
コード例 #6
0
 public EfSearchEngine(BaseSearchParams parameters) : base(parameters)
 {
 }
コード例 #7
0
 public SearchEngine(BaseSearchParams parameters)
 {
     this.parameters     = parameters;
     sortAndFilter       = parameters.SortAndFilter;
     defaultSortingField = parameters.DefaultSortingField;
 }
コード例 #8
0
 public FilteredResponse(BaseSearchParams searchParams)
 {
     Limit       = searchParams.Limit;
     CurrentPage = searchParams.CurrentPage;
 }