예제 #1
0
        private void lbCurrency_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Abbreviation abb = e.RemovedItems.Count == 0 ? (Abbreviation)(int)e.AddedItems[0] : (Abbreviation)(int)e.RemovedItems[0];

            if (e.RemovedItems.Count != 0)
            {
                rates.Remove(abb);
            }

            if (e.AddedItems.Count != 0 && !rates.Any(item => item.Key == abb))
            {
                rates.Add(abb, RatesHelper.GetRatesForPeriod(abb, DateTime.Now.AddYears(-1), DateTime.Now));
            }
            RefreshChart();
        }
예제 #2
0
        public CurrencyChart()
        {
            InitializeComponent();
            chart.ChartAreas.Add(new ChartArea("Default"));

            lbCurrency.SelectedItem = Abbreviation.USD;
            dpDateFrom.SelectedDate = DateTime.Now.AddMonths(-1);
            dpDateTo.SelectedDate   = DateTime.Now;
            leftButtonPressed       = false;
            rightButtonPressed      = false;
            dateChangeInAction      = false;
            rates = new Dictionary <Abbreviation, List <Rate> >();

            lbCurrency.SelectionChanged    += lbCurrency_SelectionChanged;
            dpDateFrom.SelectedDateChanged += dpDate_SelectedDateChanged;
            dpDateTo.SelectedDateChanged   += dpDate_SelectedDateChanged;

            rates[Abbreviation.USD] = RatesHelper.GetRatesForPeriod(Abbreviation.USD, DateTime.Now.AddYears(-1), DateTime.Now);
            RatesHelper.GetCurrenciesData().OrderBy(item => item.Abbreviation).ToList().ForEach(item => lbCurrency.Items.Add(AbbreviationHelper.ToAbbreviation(item.Abbreviation)));
        }
예제 #3
0
        private void RefreshRates()
        {
            var           rates     = RatesHelper.GetLastDailyRates();
            var           prevRates = RatesHelper.GetPrevDailyRates();
            StringBuilder sb        = new StringBuilder();

            sb.AppendLine(String.Format("Rates for {0}", rates.First().Date.AddDays(DateTime.Now.DayOfWeek == DayOfWeek.Friday ? -3 : -1).ToShortDateString()));

            rates = rates.
                    Where(item => (item.Abbreviation & (Abbreviation.USD | Abbreviation.EUR | Abbreviation.RUB)) != Abbreviation.NONE).ToList();
            prevRates = prevRates.
                        Where(item => (item.Abbreviation & (Abbreviation.USD | Abbreviation.EUR | Abbreviation.RUB)) != Abbreviation.NONE).ToList();

            foreach (var rate in rates)
            {
                double prev = prevRates.First(item => item.Abbreviation == rate.Abbreviation).OfficialRate;
                sb.AppendLine(String.Format("{0} {1} -> {2} | {3}", rate.Abbreviation.ToString(), prev, rate.OfficialRate, rate.OfficialRate - prev > 0 ? "+" + (rate.OfficialRate - prev) : (rate.OfficialRate - prev).ToString()));
            }

            Rates = sb.ToString();
        }
예제 #4
0
        /// <summary>
        /// Maps each hero entity to their respective view model
        /// </summary>
        /// <returns>A list of Hero view models</returns>
        public List <HeroViewModel> MapHeroes()
        {
            var modelList = new List <HeroViewModel>();

            foreach (var hero in Context.Hero)
            {
                var model = new HeroViewModel();
                model.HeroId   = hero.HeroId;
                model.HeroName = hero.Name;
                model.Age      = hero.Age;
                model.City     = hero.City;
                model.Image    = hero.Picture;
                model.Rating   = hero.Rating;
                // Get rating historial for by hero Id
                var ratingsForHero = GetRatingHistorialsByHero(hero.HeroId);
                // Fill up the rating history
                model.RatingHistory.AddRange(GetRatingViewModels(ratingsForHero));
                // Get rating average of hero
                model.RateAverage = RatesHelper.GetRatingAverage(ratingsForHero, hero.Rating);
                modelList.Add(model);
            }
            return(modelList);
        }