Exemple #1
0
        public static VATRatesVM MapToViewModel(this VATRatesJsonModel model)
        {
            if (model == null)
            {
                return(null);
            }

            VATRatesVM           VATRatesViewModel = new VATRatesVM();
            List <RateJsonModel> topThreeRates     = new List <RateJsonModel>();
            List <RateJsonModel> bottomThreeRates  = new List <RateJsonModel>();

            GetTopAndBottomRates(ref topThreeRates, ref bottomThreeRates, model);
            MapThreeRatesToViewModel(VATRatesViewModel, topThreeRates, true);
            MapThreeRatesToViewModel(VATRatesViewModel, bottomThreeRates, false, true);

            return(VATRatesViewModel);
        }
Exemple #2
0
        private static void GetTopAndBottomRates(ref List <RateJsonModel> topThreeRates, ref List <RateJsonModel> bottomThreeRates, VATRatesJsonModel model)
        {
            var topThreeRatePeriods = model.VATRates.Select(r => r.Periods.First()).Select(p => p.PeriodRates)
                                      .OrderByDescending(pr => pr.Standard)
                                      .ThenByDescending(pr => pr.Reduced != 0 ? pr.Reduced : pr.Reduced1)
                                      .ThenByDescending(pr => pr.Reduced2)
                                      .ThenByDescending(pr => pr.SuperReduced)
                                      .ThenByDescending(pr => pr.Parking)
                                      .Take(3).ToList();

            var bottomThreeRatePeriods = model.VATRates.Select(r => r.Periods.First()).Select(p => p.PeriodRates)
                                         .OrderBy(pr => pr.Standard)
                                         .ThenBy(pr => pr.Reduced != 0 ? pr.Reduced : pr.Reduced1)
                                         .ThenBy(pr => pr.Reduced2)
                                         .ThenBy(pr => pr.SuperReduced)
                                         .ThenBy(pr => pr.Parking)
                                         .Take(3).ToList();

            topThreeRates = model.VATRates.Select(r => r)
                            .Where(r => topThreeRatePeriods.Contains(r.Periods.First().PeriodRates))
                            .ToList();

            bottomThreeRates = model.VATRates.Select(r => r)
                               .Where(r => bottomThreeRatePeriods.Contains(r.Periods.First().PeriodRates))
                               .ToList();
        }