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; })); }
public CourseBaseVM.SecondCourseDiscount SecondCourse(string courseTC, CourseLink course) { if (course == null) { return(null); } var price = PriceService.GetPriceByType(courseTC, PriceTypes.Main, null); var secondPrice = PriceService.GetPriceByType(course.CourseTC, PriceTypes.Main, null); if (!secondPrice.HasValue || !price.HasValue) { return(null); } var authTypeTC = CourseService.GetValues(course.CourseTC, x => x.AuthorizationType_TC); var discountPercent = AuthorizationTypes.GetSecondCourseDiscount(authTypeTC); var secondpriceWithDiscount = OrderDetail.FloorToFifty(secondPrice.Value * (1.0m - discountPercent / 100.0m)); return(new CourseVM.SecondCourseDiscount { SecondCourse = course, Discount = (secondPrice.Value - secondpriceWithDiscount), SumWithDiscount = secondpriceWithDiscount + price.Value }); }