public void SetFilter(PairViewFilter filter) { IPairModel model = this; if (model.SelectedMarket == null) { OnPairsChanged(null); return; } var token = filter.PairToken; var allPairs = model.SelectedMarket.Pairs; var filtered = filter.IsActiveOnly ? allPairs.ActiveOnly() : allPairs; filtered = string.IsNullOrEmpty(token) ? filtered : filtered.Where(p => p.Pair.BaseCurrency.Name.IndexOf(token, StringComparison.OrdinalIgnoreCase) >= 0 || p.Pair.QuoteCurrency.Name.IndexOf(token, StringComparison.OrdinalIgnoreCase) >= 0); var result = new List <PairOfMarket>(); foreach (var pair in filtered) { if (Statistics == null) { result.Add(pair); continue; } var stats = Statistics.FirstOrDefault(s => s.Pair.Equals(pair.Pair)); switch (filter.DailyChange) { case DailyChangePairEnum.PositiveOnly: if (stats != null && stats.DailyChangeOfLastPrice() > 0) { result.Add(pair); } break; case DailyChangePairEnum.NegativeOnly: if (stats != null && stats.DailyChangeOfLastPrice() < 0) { result.Add(pair); } break; default: result.Add(pair); break; } } OnPairsChanged(result); }
public PairPresenter(IPairView view, IPairModel model) : base(view) { Model = model; Model.PairsChanged += Model_PairsChanged; Model.StatisticsChanged += Model_StatisticsChanged; View.SetMarkets(Model.Markets); View.MarketChanged += View_MarketChanged; View.ViewClosed += View_ViewClosed; View.FilterChanged += View_FilterChanged; View.InitFilter(); }