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); } }
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); }
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()); }
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); }
public async Task <IHttpActionResult> Get([FromUri] BaseSearchParams searchParams) { var items = _valuesFcd.GetAll(searchParams); return(Ok(await items)); }
public EfSearchEngine(BaseSearchParams parameters) : base(parameters) { }
public SearchEngine(BaseSearchParams parameters) { this.parameters = parameters; sortAndFilter = parameters.SortAndFilter; defaultSortingField = parameters.DefaultSortingField; }
public FilteredResponse(BaseSearchParams searchParams) { Limit = searchParams.Limit; CurrentPage = searchParams.CurrentPage; }