public List <Contact> SortListWithParameter(List <Contact> oldList, SortEnum parameter) { List <Contact> list = null; if (oldList != null || oldList.Count() > 1) { switch ((int)parameter) { case 0: { list = oldList.OrderBy(x => x.FullName).ToList(); break; } case 1: { list = oldList.OrderBy(x => x.NickName).ToList(); break; } case 2: { list = oldList.OrderBy(x => x.AddTime).ToList(); break; } } } return(list); }
private static XslCompiledTransform GetCompiledTransform(SortEnum sort) { string xsltFile = ""; switch (sort) { case SortEnum.ALPHABETICALLY_ASCENDING: xsltFile = "Sort-a.xsl"; break; case SortEnum.ALPHABETICALLY_DESCENDENTLY: xsltFile = "Sort-ad.xsl"; break; case SortEnum.LENGTH_ASCENDING: xsltFile = "Sort-l.xsl"; break; case SortEnum.LENGTH_DESCENDENTLY: xsltFile = "Sort-ld.xsl"; break; } var xslt = new XslCompiledTransform(); var assembly = Assembly.GetExecutingAssembly(); using (var stream = assembly.GetManifestResourceStream("dotnet_sort." + xsltFile)) { using (var reader = XmlReader.Create(stream)) { xslt.Load(reader); return(xslt); } } }
/// <summary> /// Sort the transfers from a model. /// </summary> /// <returns>List of sorted transfers</returns> /// <param name="m">Model from which to sort transfers</param> /// <param name="how">Sort method</param> /// <param name="descend">True for descending sort, false for ascending</param> public static List <TransferModel> SortTransfers(AstrogationModel m, SortEnum how, bool descend) { List <TransferModel> transfers = new List <TransferModel>(m.transfers); switch (how) { case SortEnum.Name: transfers.Sort((a, b) => a?.destination?.GetName().CompareTo(b?.destination?.GetName()) ?? 0); break; case SortEnum.Position: // Use the natural/default ordering in the model break; case SortEnum.Time: transfers.Sort((a, b) => a?.ejectionBurn?.atTime?.CompareTo(b?.ejectionBurn?.atTime ?? 0) ?? 0); break; case SortEnum.DeltaV: transfers.Sort((a, b) => a?.ejectionBurn?.totalDeltaV.CompareTo(b?.ejectionBurn?.totalDeltaV) ?? 0); break; default: DbgFmt("Bad sort argument: {0}", how.ToString()); break; } if (descend) { transfers.Reverse(); } return(transfers); }
public static Dictionary <int, List <T> > PageOrderToDic <T, TK>(IQueryable <T> source, int pageSize, Expression <Func <T, TK> > orderByExpression, SortEnum sortOrder = SortEnum.Original, Expression <Func <T, bool> > filter = null) { var dic = new Dictionary <int, List <T> >(); //筛选 if (filter != null) { source = source.Where(filter); } //排序 if (orderByExpression != null) { source = Order(source, orderByExpression, sortOrder); } int pageCount = source.Count() / pageSize + 1; for (int pageIndex = 1; pageIndex <= pageCount; pageIndex++) { int skipCount = pageSize * (pageIndex - 1);//跳过条数 dic.Add(pageIndex, source.Skip(skipCount).Take(pageSize).ToList()); } return(dic); }
/// <summary> /// 获取排序SQL语句 /// </summary> /// <param name="sort">排序</param> /// <param name="prop">排序的属性名</param> /// <param name="pfx">前辍</param> /// <returns>排序SQL语句</returns> protected string GetSortSql(SortEnum sort, string prop, string pfx = null) { if (string.IsNullOrWhiteSpace(prop)) { return(null); } if (string.IsNullOrWhiteSpace(pfx)) { pfx = Table + "."; } string field = GetFieldByProp(prop); if (string.IsNullOrWhiteSpace(field)) { field = prop; } StringBuilder sql = new StringBuilder($"ORDER BY {pfx}{field}"); if (sort == SortEnum.ASC) { sql.Append(" ASC"); } else { sql.Append(" DESC"); } return(sql.ToString()); }
public async Task <List <Contact> > GetListOfContacts(int userId, SortEnum parameter) { var items = await _repositoryC.GetItemsAsync <Contact>(); var list = items.Where(x => x.UserId == userId).ToList(); return(SortListWithParameter(list, parameter)); }
public IActionResult OnPost(SortEnum sortBy, SortDirectionEnum sortDirection) { return(RedirectToPage( "./TeamCompositionSummary", new { sortBy = sortBy, sortDirection = sortDirection })); }
public override void OnNavigatedTo(INavigationParameters parameters) { selectedSort = (SortEnum)CrossSettings.Current.GetValueOrDefault("Sort", 0); ChangeRadioButton(); selectedTheme = (ThemeEnum)CrossSettings.Current.GetValueOrDefault("Theme", 0); ChangeCheckBox(); selectedLocalization = (LocalizationEnum)CrossSettings.Current.GetValueOrDefault("Localization", 0); ChangePicker(); }
public async Task <Result <IEnumerable <Product> > > GetProducts(SortEnum sortOption, CancellationToken cancellationToken) { if (sortOption.Equals(SortEnum.Recommended)) { return(await GetRecommendedProducts(cancellationToken)); } return(await GetAllProducts(sortOption, cancellationToken)); }
/// <summary> /// 排序分页 /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="TK"></typeparam> /// <param name="source"></param> /// <param name="pageSize"></param> /// <param name="pageIndex"></param> /// <param name="orderByExpression"></param> /// <param name="sortOrder"></param> /// <param name="filter"></param> /// <returns></returns> public static PageResult <T> PageOrder <T, TK>(IEnumerable <T> source, int pageSize, int pageIndex, Expression <Func <T, TK> > orderByExpression, SortEnum sortOrder = SortEnum.Original, Expression <Func <T, bool> > filter = null) { return(PageOrder <T, TK>(source.AsQueryable(), pageSize, pageIndex, orderByExpression: orderByExpression, sortOrder: sortOrder, filter: filter)); }
/// <summary> /// Sorts input text based on a sortEnum value /// </summary> /// <param name="text">Input text to be used for sorting</param> /// <param name="sortEnum">Sorting algorithm of choice</param> /// <returns></returns> public SortResult Sort(string text, SortEnum sortEnum) { var sorterAlgorithm = _sortAlgorithmFactory.GetSorter(sortEnum); var sortedText = sorterAlgorithm.Sort(text, _stringSettings.Separators); return(new SortResult() { SortedList = sortedText }); }
public CircularSearchRequest(float latitude, float longitude, float radius, FuelEnum fuelType, SortEnum sortType) { _latitude = latitude; _longitude = longitude; _radius = radius; _fuelType = fuelType; _sort = sortType; EndpointUrl = "list.php"; Method = HttpMethod.Get; }
private void SortClicked(SortEnum which) { if (Settings.Instance.TransferSort == which) { Settings.Instance.DescendingSort = !Settings.Instance.DescendingSort; } else { Settings.Instance.TransferSort = which; Settings.Instance.DescendingSort = false; } resetCallback(); }
public AuthorsSortViewModel(SortEnum sortOrder) { NameSort = sortOrder == SortEnum.NAME_ASC ? SortEnum.NAME_DESC : SortEnum.NAME_ASC; SurnameSort = sortOrder == SortEnum.SURNAME_ASC ? SortEnum.SURNAME_DESC : SortEnum.SURNAME_ASC; Up = true; if (sortOrder == SortEnum.NAME_DESC || sortOrder == SortEnum.SURNAME_DESC) { Up = false; } Current = sortOrder; }
public UsersSortViewModel(SortEnum sortOrder) { EmailSort = sortOrder == SortEnum.EMAIL_ASC ? SortEnum.EMAIL_DESC : SortEnum.EMAIL_ASC; LoginNameSort = sortOrder == SortEnum.LOGINNAME_ASC ? SortEnum.LOGINNAME_DESC : SortEnum.LOGINNAME_ASC; Up = true; if (sortOrder == SortEnum.EMAIL_DESC || sortOrder == SortEnum.LOGINNAME_DESC) { Up = false; } Current = sortOrder; }
public virtual async Task <ActionResult <ProductDTO> > GetUser( [FromQuery][Required] SortEnum sortOption, CancellationToken token) { var response = await _productService.GetProducts(sortOption, token); if (response.IsSuccess) { var mappedResponse = _mapper.Map <IList <ProductDTO> >(response.Value); return(Ok(mappedResponse)); } return(StatusCode(500, "Error getting products")); }
private static void SortImports(string filePath, SortEnum sort) { Console.Write($"Sorting.. {filePath}"); var file = new StreamReader(filePath, Encoding.UTF8); var linesToSort = new List <string>(); var restOfFile = ""; string line; string pattern = @"^using.*;"; while ((line = file.ReadLine()) != null && Regex.Match(line, pattern).Success) { linesToSort.Add(line); } if (linesToSort.Count == 0) { Console.WriteLine("\t not necessary"); return; } restOfFile = line + "\r\n" + file.ReadToEnd(); file.Close(); switch (sort) { case SortEnum.ALPHABETICALLY_ASCENDING: linesToSort = linesToSort.OrderBy(x => x).ToList(); break; case SortEnum.ALPHABETICALLY_DESCENDENTLY: linesToSort = linesToSort.OrderByDescending(x => x).ToList(); break; case SortEnum.LENGTH_ASCENDING: linesToSort = linesToSort.OrderBy(x => x.Length).ToList(); break; case SortEnum.LENGTH_DESCENDENTLY: linesToSort = linesToSort.OrderByDescending(x => x.Length).ToList(); break; } //Write lines using (StreamWriter writer = new System.IO.StreamWriter(filePath, false, Encoding.UTF8)) { foreach (var strLine in linesToSort) { writer.WriteLine(strLine); } writer.Write(restOfFile); writer.Close(); } Console.WriteLine("\t done"); }
public static BeatmapEntry[] GetStringsBySortType(SortEnum sortEnum, IEnumerable <BeatmapEntry> list) { switch (sortEnum) { case SortEnum.Artist: default: return(list.Distinct().OrderBy(k => MetaSelect.GetUnicode(k.Artist, k.ArtistUnicode), StringComparer.InvariantCulture).ToArray()); case SortEnum.Title: return(list.Distinct().OrderBy(k => MetaSelect.GetUnicode(k.Title, k.TitleUnicode), StringComparer.InvariantCulture).ToArray()); } }
/// <summary> /// Converts a SortEnum value to a corresponding string value /// </summary> /// <param name="enumValue">The SortEnum value to convert</param> /// <returns>The representative string value</returns> public static string ToValue(SortEnum enumValue) { switch (enumValue) { //only valid enum elements can be used //this is necessary to avoid errors case SortEnum.ASC: case SortEnum.DESC: return(stringValues[(int)enumValue]); //an invalid enum value was requested default: return(null); } }
private void OnRadioButtonChange() { if (_isCheckedName) { selectedSort = SortEnum.ByName; } else if (_isCheckedNick) { selectedSort = SortEnum.ByNick; } else if (_isCheckedDate) { selectedSort = SortEnum.ByDate; } }
public IEnumerable <Product> SortedProducts(SortEnum sortOption, IEnumerable <Product> products) { switch (sortOption) { case SortEnum.Low: return(products.OrderBy(p => p.Price)); case SortEnum.High: return(products.OrderByDescending(p => p.Price)); case SortEnum.Ascending: return(products.OrderBy(p => p.Name)); case SortEnum.Descending: return(products.OrderByDescending(p => p.Name)); default: return(products); } }
public List <Feed> GetFeedList(SortEnum sortEnum) { List <Feed> list = new List <Feed>(); if (sortEnum == SortEnum.New) { list = this.GetFeedListWithFeedLikeOrderByDate(); } else if (sortEnum == SortEnum.Like) { list = this.GetFeedListWithFeedLikeOrderByLike(); } return(list); }
public async Task <Result <IEnumerable <Product> > > GetAllProducts(SortEnum sortOption, CancellationToken cancellationToken) { var httpResponse = await base.Get(_productAPISettings.ProductsUri, cancellationToken); try { var products = JsonConvert.DeserializeObject <IEnumerable <Product> >(httpResponse); var sortedProducts = SortedProducts(sortOption, products); return(Results.Ok(sortedProducts)); } catch (Exception ex) { return(Results.Fail <IEnumerable <Product> >(new Error(ex.Message))); } }
/// <summary> /// Returns a sorter algorithm instance based on sortEnum input /// </summary> /// <param name="sortEnum">Sort algorithm choice</param> /// <returns></returns> public virtual ISorterAlgorithm GetSorter(SortEnum sortEnum) { switch (sortEnum) { case SortEnum.AlphabeticalSortAlgorithm: return(_serviceProvider.GetRequiredService <AlphabeticalSorter>()); case SortEnum.WordSizeSortAlgorithm: return(_serviceProvider.GetRequiredService <WordSizeSorter>()); case SortEnum.CharacterWithinWordAlgorithm: return(_serviceProvider.GetRequiredService <CharacterWithinWordSorter>()); default: throw new NotImplementedException($"Sorter Algorithm is not implemented for SortEnum: {sortEnum}"); } }
/// <summary> /// 排序分页 /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="TK"></typeparam> /// <param name="source"></param> /// <param name="pageSize"></param> /// <param name="pageIndex"></param> /// <param name="orderByExpression"></param> /// <param name="sortOrder"></param> /// <param name="filter"></param> /// <returns></returns> public static PageResultDto <T> PageOrder <T, TK>(IQueryable <T> source, int pageSize, int pageIndex, Expression <Func <T, TK> > orderByExpression, SortEnum sortOrder = SortEnum.Original, Expression <Func <T, bool> > filter = null) { int skipCount; //跳过条数 int totalCount; //筛选后总条数 int totalPages; //筛选后总页数 //筛选 if (filter != null) { source = source.Where(filter); } totalCount = source.Count(); totalPages = totalCount > 0 ? (int)Math.Ceiling((double)totalCount / (double)pageSize) : 0; pageIndex = totalPages <= 0 ? 1 : pageIndex > totalPages ? totalPages : pageIndex; skipCount = pageSize * (pageIndex - 1); //排序 if (orderByExpression != null) { source = Order(source, orderByExpression, sortOrder); } //分页 source = source.Skip(skipCount).Take(pageSize); return(new PageResultDto <T> { List = source.ToList(), PageIndex = totalPages <= 0 ? 1 : (pageIndex > totalPages ? totalPages : pageIndex), PageSize = pageSize, TotalCount = totalCount, TotalPages = totalPages }); }
/// <summary> /// Initializes a new instance of the <see cref="Portfolio" /> class. /// </summary> /// <param name="createdTime">The time in ISO 8601 format when the portfolio was created. (required).</param> /// <param name="description">The portfolio's description. (required).</param> /// <param name="link">The link to the portfolio. (required).</param> /// <param name="metadata">metadata (required).</param> /// <param name="modifiedTime">The time in ISO 8601 format when the portfolio's data was last modified. (required).</param> /// <param name="name">The display name of the portfolio. (required).</param> /// <param name="sort">The default video sort order for the portfolio: Option descriptions: * `alphabetical` - The default sort order is alphabetical by name. * `clips` - The default sort order is video creation date. * `modified` - The default sort order is the order in which the videos were modified. * `recent` - The default sort order is the order in which the videos were added. (required).</param> /// <param name="uri">The canonical relative URI of the portfolio. (required).</param> public Portfolio(string createdTime = default(string), string description = default(string), string link = default(string), PortfolioMetadata metadata = default(PortfolioMetadata), string modifiedTime = default(string), string name = default(string), SortEnum sort = default(SortEnum), string uri = default(string)) { // to ensure "createdTime" is required (not null) this.CreatedTime = createdTime ?? throw new ArgumentNullException("createdTime is a required property for Portfolio and cannot be null"); // to ensure "description" is required (not null) this.Description = description ?? throw new ArgumentNullException("description is a required property for Portfolio and cannot be null"); // to ensure "link" is required (not null) this.Link = link ?? throw new ArgumentNullException("link is a required property for Portfolio and cannot be null"); // to ensure "metadata" is required (not null) this.Metadata = metadata ?? throw new ArgumentNullException("metadata is a required property for Portfolio and cannot be null"); // to ensure "modifiedTime" is required (not null) this.ModifiedTime = modifiedTime ?? throw new ArgumentNullException("modifiedTime is a required property for Portfolio and cannot be null"); // to ensure "name" is required (not null) this.Name = name ?? throw new ArgumentNullException("name is a required property for Portfolio and cannot be null"); this.Sort = sort; // to ensure "uri" is required (not null) this.Uri = uri ?? throw new ArgumentNullException("uri is a required property for Portfolio and cannot be null"); }
public BooksSortViewModel(SortEnum sortOrder) { NameSort = sortOrder == SortEnum.NAME_ASC ? SortEnum.NAME_DESC : SortEnum.NAME_ASC; YearSort = sortOrder == SortEnum.YEAR_ASC ? SortEnum.YEAR_DESC : SortEnum.YEAR_ASC; RateSort = sortOrder == SortEnum.RATE_ASC ? SortEnum.RATE_DESC : SortEnum.RATE_ASC; PriceSort = sortOrder == SortEnum.PRICE_ASC ? SortEnum.PRICE_DESC : SortEnum.PRICE_ASC; Up = true; if (sortOrder == SortEnum.NAME_DESC || sortOrder == SortEnum.YEAR_DESC || sortOrder == SortEnum.PRICE_DESC || sortOrder == SortEnum.RATE_DESC) { Up = false; } Current = sortOrder; }
/// <summary> ///当前排序 /// </summary> public void Sort(SortEnum pse) { List <string> listKeys = this.Keys.ToList(); listKeys.Sort(new SortCamparer(pse)); BaseDictionary pd = new BaseDictionary(); foreach (string r in listKeys) { pd.Add(r, this[r]); } this.Clear(); foreach (string r in listKeys) { this.Add(r, pd[r]); } pd.Clear(); pd = null; }
public BooksSortViewModel(SortEnum sortOrder) { TitleSort = sortOrder == SortEnum.TITLE_ASC ? SortEnum.TITLE_DESC : SortEnum.TITLE_ASC; YearSort = sortOrder == SortEnum.YEAR_ASC ? SortEnum.YEAR_DESC : SortEnum.YEAR_ASC; AuthorNameSort = sortOrder == SortEnum.AUTHOR_NAME_ASC ? SortEnum.AUTHOR_NAME_DESC : SortEnum.AUTHOR_NAME_ASC; AuthorSurnameSort = sortOrder == SortEnum.AUTHOR_SURNAME_ASC ? SortEnum.AUTHOR_SURNAME_DESC : SortEnum.AUTHOR_SURNAME_ASC; RateSort = sortOrder == SortEnum.RATE_ASC ? SortEnum.RATE_DESC : SortEnum.RATE_ASC; Up = true; if (sortOrder == SortEnum.TITLE_DESC || sortOrder == SortEnum.YEAR_DESC || sortOrder == SortEnum.AUTHOR_NAME_DESC || sortOrder == SortEnum.AUTHOR_SURNAME_DESC || sortOrder == SortEnum.RATE_DESC) { Up = false; } Current = sortOrder; }
private static IQueryable <T> Order <T, TK>(IQueryable <T> source, Expression <Func <T, TK> > orderByExpression, SortEnum sortOrder = SortEnum.Original) { //排序 switch (sortOrder) { case SortEnum.Original: break; case SortEnum.Asc: source = source.OrderBy(orderByExpression); break; case SortEnum.Desc: source = source.OrderByDescending(orderByExpression); break; } return(source); }
public OrderByAnalyser(String property, SortEnum sort) { this.Property = property; this.Sort = sort; }
PageData<UserData> IAccountService.GetUsers(SortEnum sortType, string term, int pageId, int pageSize, RoleEnum currentUserRole) { var pageData = new PageData<UserData> { PageId = pageId, PageSize = pageSize }; var data = !string.IsNullOrWhiteSpace(term) ? _userRepository.GetQueryableData(o => o.UserName.Contains(term)) : _userRepository.GetQueryableData(); data = data.Where(o => o.RoleId != (int)RoleEnum.MainAdministrator); if (currentUserRole == RoleEnum.Administrator) data = data.Where(o => o.RoleId != (int)RoleEnum.Administrator); pageData.Count = data.Count(); if (pageData.Count != 0) { switch (sortType) { case SortEnum.Default: data = data.OrderBy(o => !o.IsActive).ThenBy(o => o.IsBanned).ThenBy(o => o.UserName); break; case SortEnum.Name: data = data.OrderBy(o => o.UserName); break; case SortEnum.Email: data = data.OrderBy(o => o.Email); break; case SortEnum.Actived: data = data.OrderBy(o => !o.IsActive).ThenBy(o => o.IsBanned).ThenBy(o => o.UserName); break; case SortEnum.Banned: data = data.OrderBy(o => !o.IsBanned).ThenBy(o => !o.IsActive).ThenBy(o => o.UserName); break; } pageData.Data = data.Page(pageData.PageId, pageData.PageSize).Select(o => new UserData { Id = o.Id, UserName = o.UserName, Email = o.Email, IsActive = o.IsActive, PhotoPath = o.PhotoPath, IsBanned = o.IsBanned, RoleId = o.RoleId }).ToList(); } return pageData; }
public static OrderByAnalyser CreateSort(String property, SortEnum sort) { return new OrderByAnalyser(property, sort); }