//Sorteren private IQueryable <Potplant> SorteerResultaten(SortParam sort, IQueryable <Potplant> planten) { switch (sort.OrderBy) { case Order.Naam_Aflopend: return(planten = planten.OrderByDescending(p => p.Naam)); case Order.Planthoogte: return(planten = planten.OrderBy(p => p.Planthoogte)); case Order.Planthoogte_Aflopend: return(planten = planten.OrderByDescending(p => p.Planthoogte)); case Order.Groep: return(planten = planten.OrderBy(p => p.Productgroep)); case Order.Groep_Aflopend: return(planten = planten.OrderByDescending(p => p.Productgroep)); case Order.Potmaat: return(planten = planten.OrderBy(p => p.Productgroep)); case Order.Potmaat_Aflopend: return(planten = planten.OrderByDescending(p => p.Productgroep)); default: return(planten = planten.OrderBy(p => p.Naam)); } }
/// <summary> /// Loads the sort parameters. /// </summary> private void LoadSortParams() { string[] sortParamArray = SortParam.Split(ParameterDelimiter); if (sortParamArray.Length == 7) { InventoryParamFromDate = sortParamArray[5] == string.Empty ? (DateTime?)null : Utils.GetDatetime(sortParamArray[5], false).Value; InventoryParamToDate = sortParamArray[6] == string.Empty ? (DateTime?)null : Utils.GetDatetime(sortParamArray[6], false).Value; } }
public PagedViewModel <UserPlace> GetMine(int skip, int take, SortParam sort) { return(_db.UserPlaces.Build() .Active() .Where(x => x.OwnerId == _requestInformation.UserId) .PageAndSort(skip, take, sort, new SortParam() { ColumnName = "CreateDate", Ascending = true })); }
public PagedViewModel <Trip> GetForCar(long carId, int skip, int take, SortParam sort) { if (string.IsNullOrWhiteSpace(sort?.ColumnName)) { sort = new SortParam() { ColumnName = "StartDate", Ascending = false }; } return(_db.Trips.Build().Where(t => t.CarId == carId).PageAndSort(skip, take, sort)); }
public PagedViewModel <Car> GetAllPaged(int skip = 0, int take = 10, SortParam sortParam = null) { if (string.IsNullOrWhiteSpace(sortParam?.ColumnName)) { sortParam = new SortParam() { ColumnName = "Vin", Ascending = true }; } return(_db.Cars.PageAndSort(skip, take, sortParam)); }
public PagedViewModel <ReaderLog> GetAllPaged(int skip = 0, int take = 10, SortParam sortParam = null, IEnumerable <FilterParam> filters = null) { if (string.IsNullOrWhiteSpace(sortParam?.ColumnName)) { sortParam = new SortParam() { ColumnName = "Date", Ascending = false }; } return(_db.ReaderLogs.Filter(filters).PageAndSort(skip, take, sortParam)); }
public async Task <ActionResult <IEnumerable <MessageOption> > > GetOptions( [FromQuery] string filter, [FromQuery] string sort, [FromQuery] string range) { var filterParam = FilterParam.ParseParam(filter); var sortParam = SortParam.ParseParam(sort); var rangeParam = RangeParam.ParseParam(range); var query = _context.MessageOptions .AsQueryable() .Filter(filterParam); var total = await query.CountAsync(); var rst = await query.OrderBy(sortParam).Range(rangeParam).ToListAsync(); Response.Headers.AddContentRange("MessageOptions", rangeParam, total, rst.Count); return(rst); }
public static PagedViewModel <T> PageAndSort <T>(this IQueryable <T> query, int skip, int take, SortParam sortParam, SortParam defaultSortParam = null) where T : ITrackedEntity { if (string.IsNullOrWhiteSpace(sortParam?.ColumnName)) { if (null == defaultSortParam) { sortParam = new SortParam { ColumnName = "CreateDate", Ascending = false }; } else { sortParam = defaultSortParam; } } if (sortParam.Ascending) { query = query.OrderBy(sortParam.ColumnName); } else { query = query.OrderByDescending(sortParam.ColumnName); } int count = query.Count(); if (take <= 0 || take > 100) { throw new EntityValidationException("Invalid page size. Take must be between 1 and 100."); } if (skip < 0) { throw new EntityValidationException("Invalid skip. Skip must be >= 0."); } return(new PagedViewModel <T>() { Data = query.Skip(skip).Take(take), Total = count, Skip = skip, Take = take }); }
public async Task <ActionResult <IEnumerable <Message> > > GetMessages( [FromQuery] string sort, [FromQuery] string range, [FromQuery] string filter ) { var sortParam = SortParam.ParseParam(sort); var rangeParam = RangeParam.ParseParam(range); var filterParam = FilterParam.ParseParam(filter); var query = Messages.Filter(filterParam); var totalCount = await query.CountAsync(); query = query.OrderBy(sortParam).Range(rangeParam); var rst = await query.AsNoTracking().ToListAsync(); Response.Headers.AddContentRange("StaticMessages", rangeParam, totalCount, rst.Count); Response.Headers.Add("Access-Control-Expose-Headers", "Content-Range"); return(rst); }
public PagedViewModel <TripPossiblePlace> GetForTripOfTypePaged(long tripId, TripPossiblePlaceType type, int skip = 0, int take = 10, SortParam sortParam = null) { if (string.IsNullOrWhiteSpace(sortParam?.ColumnName)) { sortParam = new SortParam() { ColumnName = "Distance", Ascending = true }; } return (_db.TripPossiblePlaces .Active() .Build() .Where(x => x.TripId == tripId && x.PlaceType == type) .PageAndSort(skip, take, sortParam)); }
public Task BindModelAsync(ModelBindingContext bindingContext) { if (bindingContext == null) { throw new ArgumentNullException(nameof(bindingContext)); } var city = bindingContext.ValueProvider.GetValue(nameof(GetWeatherDto.City)).FirstValue; var metrics = bindingContext.ValueProvider.GetValue(nameof(GetWeatherDto.Metrics)).FirstValue; var lang = bindingContext.ValueProvider.GetValue(nameof(GetWeatherDto.Lang)).FirstValue; var rawSortBy = bindingContext.ValueProvider.GetValue(nameof(GetWeatherDto.SortBy)).FirstValue; SortParam sortBy = null; if (!string.IsNullOrEmpty(rawSortBy)) { var sarr = rawSortBy.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (sarr.Length == 1) { sortBy = new SortParam { Field = sarr[0], Asc = true }; } else if (sarr.Length == 2) { sortBy = new SortParam { Field = sarr[0], Asc = sarr[1].EqualsIgnoreCase("asc") }; } } bindingContext.Result = ModelBindingResult.Success( new GetWeatherDto { City = string.IsNullOrEmpty(city) ? "Kyiv" : city, Metrics = string.IsNullOrEmpty(metrics) ? "Celsius" : metrics, Lang = string.IsNullOrEmpty(lang) ? "En" : lang, SortBy = sortBy }); return(Task.CompletedTask); }
public List <ActorDetailsDto> GetActorBySearchString(string searchString, SortParam sortParam, SortOrder sortOrder) { var actorsList = _uow.ActorRepository.GetActorsBySearchString(searchString); switch (sortParam) { case SortParam.Name: actorsList = sortOrder == SortOrder.Asc ? actorsList.OrderBy(p => p.Name) : actorsList.OrderByDescending(p => p.Name); break; case SortParam.Date: actorsList = sortOrder == SortOrder.Asc ? actorsList.OrderBy(p => p.Birthdate) : actorsList.OrderByDescending(p => p.Birthdate); break; } return(BusinessMapper.Mapper.Map <List <ActorDetailsDto> >(actorsList)); }
public async Task <ActionResult <IEnumerable <Question> > > GetQuestions( [FromQuery] string sort, [FromQuery] string range, [FromQuery] string filter) { var sortParam = SortParam.ParseParam(sort); var rangeParam = RangeParam.ParseParam(range); var filterParam = FilterParam.ParseParam(filter); var query = _context.Questions.Where(q => !q.Deleted).AsQueryable(); query = query.Filter(filterParam); var totalEntryCount = await query.CountAsync(); var topicList = await query.OrderBy(sortParam).Range(rangeParam).AsNoTracking().ToListAsync(); var count = topicList.Count; Response.Headers.AddContentRange("Questions", rangeParam, totalEntryCount, count); Response.Headers.Add("Access-Control-Expose-Headers", "Content-Range"); return(topicList); }
///// <summary> ///// 用於查詢日期 ///// </summary> ///// <param name="circleKey"></param> ///// <param name="memberId"></param> ///// <param name="maxResult"></param> ///// <param name="pageToken"></param> ///// <param name="queryDate"></param> ///// <returns></returns> public ReadMarkResult <ActivitysViewModel> GetQueryDateList(string circleKey, int memberId, int maxResult, Guid pageToken, DateTime?queryDate = null) { var result = new ReadMarkResult <ActivitysViewModel>(); var list = new List <ActivitysViewModel>(); try { // 取出最新的 maxResult 筆資料 list = _uow.ActivitysRepo.GetQueryDateList(circleKey, memberId, maxResult, pageToken).ToList(); foreach (var item in list) { item.sOuterKey = Utility.OuterKeyHelper.GuidToPageToken(item.OuterKey); } // 更新接口資訊 result.Success = true; } catch (Exception ex) { result.Success = false; result.Message = string.Format("{0}\n\n{1}", ex.Message, ex.StackTrace); result.Data = default(ActivitysViewModel[]); } bool goback = false; //是否往前取得活動 var param = new SortParam() { MaxResult = maxResult, MemberId = memberId, CircleKey = circleKey, Goback = goback }; if (queryDate != null) { param.QueryDateTime = queryDate.Value; } return(SortList(result, list, param)); }
public static PagedViewModel <T> PageAndSort <T>(this IQueryable <T> query, int skip, int take, SortParam sortParam, SortParam defaultSortParam = null) where T : ITrackedEntity { if (string.IsNullOrWhiteSpace(sortParam?.SortBy)) { if (null == defaultSortParam) { sortParam = new SortParam { SortBy = "CreateDate", Ascending = false }; } else { sortParam = defaultSortParam; } } query = query.Sort(sortParam); int count = query.Count(); if (take <= 0) { throw new EntityValidationException("Invalid page size. Take must be at least 1."); } if (skip < 0) { throw new EntityValidationException("Invalid skip. Skip must be >= 0."); } return(new PagedViewModel <T>() { Data = query.Skip(skip).Take(take), Total = count, Skip = skip, Take = take }); }
public IActionResult GetPossiblePlacesForTrip(long tripId, string type, int skip = DefaultSkip, int take = DefaultTake, SortParam sort = null) { var typeEnum = TripPossiblePlaceTypeExtentions.FromString(type); return(Ok(_tripPossiblePlaceService.GetForTripOfTypePaged(tripId, typeEnum, skip, take, sort) .ToViewModel())); }
public bool FilterTo <T1>(SortParam <T1> param) { int _ret = System.Array.IndexOf(m_Filters, param.m_Param); return((_ret != -1) ? true : false); }
static void SortFromParam(SortParam param) { //merge sort vs. dot net sort Array.Sort(param.buffer, 0, param.len); ArrayToFile(param.buffer, param.byteBuffer, param.len, param.name); }
private static void SortOnThread(SortParam param) { param.mre.WaitOne();//wait for previous thread to complete param.mre.Reset(); ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc), param); }
public async Task <ActionResult <IEnumerable <Potplant> > > GetPotplant([FromQuery] FilterParam filter, [FromQuery] SortParam sort) { var planten = from p in _context.Potplant select p; //filteren op invoer (naam, kleur, minimale en maximale potmaat en productgroep) planten = FilterResultaten(filter, planten); //sorteren op volgorde van de gekozen parameter (bijvoorbeeld naam of productgroep) planten = SorteerResultaten(sort, planten); return(await planten.ToListAsync()); }
public static IQueryable <T> OrderBy <T>(this IQueryable <T> query, SortParam param) => param == null ? query : query.OrderBy(param.Column, param.Desc);
public IActionResult GetActiveForUser(int skip = DefaultSkip, int take = DefaultTake, SortParam sort = null) { return(Ok(_tokenService.GetActiveForUser(GetCurrentUserId(), skip, take, sort))); }
public PagedViewModel <ServerLog> GetForEvent(string eventId, int skip, int take, SortParam sort, IEnumerable <FilterParam> filters) { var guid = new Guid(eventId); return(_db.ServerLogs.Where(l => l.RequestUuid == guid).Filter(filters).PageAndSort(skip, take, sort)); }
public PagedViewModel <ServerLog> GetAll(int skip, int take, SortParam sort, IEnumerable <FilterParam> filters) { return(_db.ServerLogs.Filter(filters).PageAndSort(skip, take, sort)); }
public IActionResult GetAll(int skip = DefaultSkip, int take = DefaultTake, SortParam sort = null, Dictionary <string, string> filters = null) { return(Ok(_readerLogService.GetAllPaged(skip, take, sort, filters.ConvertToFilterParams()).ToViewModel())); }
public PagedViewModel <CarMaintenance> GetForCarPaged(long carId, int skip = 0, int take = 10, SortParam sort = null) { return(_db.CarMaintenances.Active().Where(cm => cm.CarId == carId).PageAndSort(skip, take, sort)); }
private ReadMarkResult <ActivitysViewModel> SortList(ReadMarkResult <ActivitysViewModel> result, IEnumerable <ActivitysViewModel> list, SortParam param) { //以id排序(時間序才不會錯亂) var temp = result.Data.ToList(); if (param.Goback) { result.Data = temp.OrderByDescending(x => x.Publish_Date).ToArray();//舊訊息:前端UI會往上長,因此是由大到小排序(最後長的是最舊的訊息) } else { result.Data = temp.OrderBy(x => x.Publish_Date).ToArray();//新訊息:前端UI是往下長,因此是由小到大排序 } return(result); }
private static string[] InitialSort(string inputFile, string tempDir, Options opt) { List<string> tempFiles = new List<string>(); var sw = new System.Diagnostics.Stopwatch(); sw.Start(); //read a chunk, sort it, then write it to file using (StreamReader reader = new StreamReader(inputFile)) { using (ManualResetEvent mre = new ManualResetEvent(true)) { NameGen nameGen = new NameGen(tempDir); string line; int lineNo = 0; int maxSortSize = opt.MaxSortSize; SortParam[] parameters = new SortParam[2]; parameters[0] = new SortParam(maxSortSize, mre, 0); parameters[1] = new SortParam(maxSortSize, mre, 1); int currentParam = 0; int[] buffer = parameters[currentParam].buffer; int j = 0; while ((line = reader.ReadLine()) != null) { lineNo++; int data; //if (Int32.TryParse(line, out data)) //slow if (StringToInt(line, out data)) { buffer[j++] = data; if (j >= maxSortSize) { string name = nameGen.NewName(); tempFiles.Add(name); parameters[currentParam].Reset(j, name); SortOnThread(parameters[currentParam]); //swap currentParam = (currentParam + 1) % 2; buffer = parameters[currentParam].buffer; j = 0; } } else Warn("Skipping line " + lineNo.ToString()); } if (j > 0) { string name = nameGen.NewName(); tempFiles.Add(name); parameters[currentParam].Reset(j, name); SortOnThread(parameters[currentParam]); } mre.WaitOne(); parameters[0].mre = null; parameters[1].mre = null; } reader.Close(); } sw.Stop(); Console.WriteLine("Time to sort intermediate files: {0}", sw.Elapsed.ToString()); return tempFiles.ToArray(); }
public PagedViewModel <UserRegistrationKey> GetAll(int skip, int take, SortParam sort) { return(GetRegistrationKeysIncluding().PageAndSort(skip, take, sort)); }
public PagedViewModel <RequestLog> GetAll(int skip, int take, SortParam sort, IEnumerable <FilterParam> filters) { return(_db.RequestLogs.Build().Filter(filters).PageAndSort(skip, take, sort)); }
public async Task <Weather[]> GetForecastAsync(string city, Units units, Langs lang, SortParam sortBy) { var reqUrl = WeatherRequestBuilder.GetForecastUri(city, units, lang); var forecastDto = await RestClient.GetAllAsync <ForecastDto>(reqUrl); var list = forecastDto.List .Select(dto => new Weather { City = city, Date = DateTime.Parse(dto.Day), Temperature = dto.Main.Temperature, TempMin = dto.Main.TempMin, TempMax = dto.Main.TempMax, Pressure = dto.Main.Pressure, Humidity = dto.Main.Humidity, Wind = dto.Wind.Speed, Clouds = dto.Clouds.All, Description = dto.Weather[0]?.Description }); var orderedList = list; if (sortBy != null) { var propertyInfo = typeof(Weather).GetProperties() .FirstOrDefault(x => x.Name.EqualsIgnoreCase(sortBy.Field)); orderedList = sortBy.Asc ? list.OrderBy(x => propertyInfo.GetValue(x, null)) : list.OrderByDescending(x => propertyInfo.GetValue(x, null)); } return(orderedList.ToArray()); }
public IActionResult GetAllPaged(int skip = DefaultSkip, int take = DefaultTake, SortParam sort = null) { return(Ok(_carService.GetAllPaged(skip, take, sort).ToViewModel())); }
/// <inheritdoc/> public IQuery <T> OrderBy(SortParam param) { Parameter.SortItems.Add(param); return(this); }