Exemplo n.º 1
0
 public Dictionary <string, Dictionary <string, decimal?> > TrackFullPrices()
 {
     return(MethodBase.GetCurrentMethod().CacheDay(() => {
         var tracks = CourseService.GetActiveTrackCourses();
         return tracks.ToDictionary(x => x.Key, x => GetCourseSum(x.Value));
     }));
 }
Exemplo n.º 2
0
        public Dictionary <string, Dictionary <string, Tuple <decimal, decimal> > > TrackLastCourseDiscounts()
        {
            return(MethodBase.GetCurrentMethod().CacheDay(() => {
                var tracks = CourseService.GetActiveTrackCourses();
                var discounts = tracks.Select(x => {
                    var trackTC = x.Key;
                    var lastCourseTC = x.Value.LastOrDefault();
                    if (lastCourseTC == null)
                    {
                        return null;
                    }
                    var fullPrices = TrackFullPrices().GetValueOrDefault(trackTC);
                    if (fullPrices == null)
                    {
                        return null;
                    }
                    var trackDiscounts = fullPrices.Select(price => {
                        var fullTrackPrice = price.Value;
                        var type = price.Key;
                        var trackPrice = PriceService.GetPriceByType(trackTC, type, null);
                        if (fullTrackPrice == null || trackPrice == null)
                        {
                            return Tuple.Create(type, decimal.Zero, decimal.Zero);
                        }
                        var save = fullTrackPrice.Value - trackPrice.Value;
                        var coursePrice = PriceService.GetPriceByType(lastCourseTC, type, null);
                        if (coursePrice == null)
                        {
                            return Tuple.Create(type, decimal.Zero, decimal.Zero);
                        }
                        var discount = save * 100 / coursePrice.Value;
                        if (discount <= 0)
                        {
                            return Tuple.Create(type, decimal.Zero, decimal.Zero);
                        }
                        return Tuple.Create(type, discount, save);
                    }).ToDictionary(z => z.Item1, z => Tuple.Create(z.Item2, z.Item3));

                    return Tuple.Create(trackTC, trackDiscounts);
                }).Where(x => x != null).ToDictionary(x => x.Item1, x => x.Item2);
                return discounts;
            }));
        }
Exemplo n.º 3
0
        public TrackDiscount GetTrackDiscount(Course track)
        {
            var cityTC = UserSettingsService.CityTC;

            if (cityTC == null)
            {
                cityTC = Cities.Moscow;
            }
            var result = new TrackDiscount {
                Track = track,
            };
            var trackCourses = CourseService.GetActiveTrackCourses().GetValueOrDefault(track.Course_TC);

            if (trackCourses == null)
            {
                return(result);
            }
            var firstCourseTC = trackCourses.First();
            var coursePrice   = PriceService.GetAllPricesForCourse(firstCourseTC, null)
                                .FirstOrDefault(p => p.CommonPriceTypeTC == PriceTypes.PrivatePersonWeekend);

            if (coursePrice != null)
            {
                var trackPrices = PriceService.GetTrackCoursesPrices(track.Course_TC, PriceTypes.PrivatePersonWeekend);
                if (!trackPrices.Any())
                {
                    trackPrices = PriceService.GetTrackCoursesPrices(track.Course_TC, PriceTypes.IntraExtra);
                }

                if (trackPrices.Count > 0)
                {
                    result.DiscountPrice = trackPrices.Sum(p => p.Price);
                    var trackCoursePrice = trackPrices
                                           .FirstOrDefault(p => p.Course_TC == firstCourseTC);
                    if (trackCoursePrice != null)
                    {
                        result.Price = result.DiscountPrice *
                                       coursePrice.Price / trackCoursePrice.Price;
                    }
                }
            }
            return(result);
        }