Example #1
0
        Dictionary <string, decimal?> GetCourseSum(List <string> courses)
        {
            var prices = courses.Distinct().ToDictionary(x => x,
                                                         x => PriceService.GetAllPricesForCourse(x, null)
                                                         .GroupBy(z => z.PriceType_TC)
                                                         .ToDictionary(z => z.Key, z => (decimal?)z.First().Price));

            return(PriceTypes.CourseTable.ToDictionary(x => x, x => courses.Select(c =>
                                                                                   prices.GetValueOrDefault(c).GetValueOrDefault(x)).Sum()));
        }
Example #2
0
        public List <string> GetElearningNames(string namePart)
        {
            var elearningCourses = PriceService.GetElearningCourses();
            var courseNames      =
                from pair in GetAllActiveCourseNames()
                where elearningCourses.Contains(pair.Key) &&
                pair.Value.ToLower().Contains(namePart.ToLower())
                select pair;

            return(courseNames.Take(CommonConst.CourseNameCount)
                   .Select(c => c.Value).ToList());
        }
Example #3
0
        public List <ElearningCourse> ElearningCourses(string name)
        {
            var elearningCourses = PriceService.GetElearningCourses();
            var courses          = CourseService.GetCourseLinkList(elearningCourses)
                                   .Where(c => c.Name.Contains(name)).Take(50).ToList()
                                   .Select(c => new ElearningCourse {
                CourseLink = c,
                Prices     =
                    PriceService.GetAllPricesForCourse(c.CourseTC, null).ToList()
            }).ToList();

            return(courses);
        }
Example #4
0
 public List <Group> DiscountGroups()
 {
     return(MethodBase.GetCurrentMethod().Cache(() => {
         var special = _.List <decimal>(140447, 149505, 172845, 159670);
         var maxDate = DateTime.Today.AddDays(8);
         var groups = GroupService.GetPlannedAndNotBegin()
                      .Where(g => g.Discount > 0 && (g.GroupCalc.NumOfStudents < 8 ||
                                                     special.Contains(g.Group_ID)) &&
                             g.DateBeg <= maxDate).NotSpecial().ToList();
         var courses = groups.Select(x => x.Course_TC).Distinct().ToList();
         var courseIndexes = courses.OrderByDescending(x =>
                                                       PriceService.CoursePriceIndex().GetValueOrDefault(x)).ToList();
         return groups.OrderBy(x => x.DateBeg)
         .ThenBy(x => courseIndexes.IndexOf(x.Course_TC)).ToList();
     }));
 }
Example #5
0
        public MobileCourseVM GetMobileByUrlName(string urlName)
        {
            var course = CourseService.GetByUrlName(urlName);

            if (course == null)
            {
                return(null);
            }
            var section = SiteObjectService.GetSingleRelation <Section>(course)
                          .IsActive().OrderBy(x => x.IsMain).FirstOrDefault();
            var model = new MobileCourseVM {
                Course  = course,
                Groups  = GroupService.GetGroupsForCourse(course.Course_TC).ToList(),
                Section = section
            };

            model.Prices = PriceService.GetAllPricesForCourse(course.Course_TC, null);
            return(model);
        }
Example #6
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;
            }));
        }
Example #7
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);
        }
Example #8
0
        private List <Announce> GetAnnouncesForCourses(IEnumerable <string> courseTCs,
                                                       List <decimal> excludeGroupIds = null)
        {
            excludeGroupIds = excludeGroupIds ?? new List <decimal>();
            var groups = GroupService.GetGroupsForCourses(courseTCs, true, true).ToList();

            if (excludeGroupIds.Any())
            {
                groups = groups.Where(x => !excludeGroupIds.Contains(x.Group_ID)).ToList();
            }
            if (!groups.Any())
            {
                groups = GroupService.GetGroupsForCourses(courseTCs, true)
                         .Where(g => g.DateBeg < DateTime.Today.AddMonths(3)).ToList();
            }

            return(GetAnnounces(groups.OrderByDescending(x => x.IsBlazing)
                                .ThenBy(x => x.IsBlazing ? null : x.DateBeg)
                                .ThenByDescending(x => PriceService.CoursePriceIndex()
                                                  .GetValueOrDefault(x.Course_TC)).Take(20).AsQueryable()).ToList());
        }
Example #9
0
        public Course GetByUrlName(string urlName)
        {
            var loadOptions = new DataLoadOptions();

            loadOptions.LoadWith <Course>(c => c.CourseContents);
            loadOptions.LoadWith <Course>(c => c.CoursePrerequisites);
            loadOptions.AssociateWith <Course>(c =>
                                               c.CourseContents.OrderBy(cc => cc.ModuleNumber));

            context.LoadOptions = loadOptions;
            var course = GetAll().
                         Where(c => c.IsActive && c.UrlName == urlName)
                         .OrderBy(x => x.Course_ID).FirstOrDefault();

            if (course != null)
            {
                course.Prices = PriceService.GetAllPricesForCourse(course.Course_TC, null);
            }

            return(course);
        }
Example #10
0
        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
            });
        }
Example #11
0
        public CourseVM GetByUrlName(string urlName)
        {
            var cityTC = UserSettingsService.CityTC;
            var course = CourseService.GetByUrlName(urlName);

            if (course == null)
            {
                return(null);
            }

            var courseTC = course.Course_TC;

            var nextCourseTCList = CourseService.GetNextCourseTCs(_.List(course.ParentCourse_TC));

            var nextCourses = CourseService.GetCourseLinkList(nextCourseTCList).ToList()
                              .OrderBy(x => nextCourseTCList.IndexOf(x.CourseTC)).ToList();
            var notSecondCourseDiscount = CourseService.NotSecondCourses();
            var secondCourse            = SecondCourse(courseTC, nextCourses.Where(x => !notSecondCourseDiscount.Contains(x.CourseTC)).FirstOrDefault());
            var successStories          = SuccessStoryService.GetAll(x => x.Course_TC == courseTC).Take(1)
                                          .OrderByDescending(x => x.SuccessStoryID).ToList();
            var responceCount = successStories.Any() ? 1 : 2;
            var responseQuery = ResponseService.GetAllForCourse(courseTC);
            var responses     = responseQuery
                                .Where(x => x.Rating >= ResponseRating.Good)
                                .GetRandom(responceCount).ToList();

            if (responses.Count < responceCount)
            {
                responses.AddRange(responseQuery
                                   .Where(x => x.Rating == ResponseRating.Common)
                                   .GetRandom(responceCount - responses.Count));
            }
            if (!responses.Any())
            {
                responses = ResponseService.GetAll(x => x.IsActive &&
                                                   x.Type == RawQuestionnaireType.OrganizingComment)
                            .Take(responceCount).ToList();
            }
            var responseTotalCount = responseQuery.Count();
            var nearestGroups      = GroupService.GetNearestGroups(course, cityTC);


            var trainers = nearestGroups.All
                           .Select(x => x.Teacher).Where(e => e != null && e.SiteVisible)
                           .Distinct(x => x.Employee_TC).ToList();
            var morningDiscount = NearestGroupSet.HasMorningDiscount(nearestGroups.All);
            var product         = SiteObjectService.GetSingleRelation <Product>(course)
                                  .IsActive().OrderByDescending(x => x.WebSortOrder).FirstOrDefault();
            var prices         = PriceService.GetAllPricesForCourse(course.Course_TC, null);
            var certifications = CertificationService.GetAllForCourse(courseTC);
            var vacancies      = SuperJobService.GetVacancies(
                SiteObjectRelationService.GetRelation(
                    typeof(Course), _.List(courseTC),
                    typeof(Profession))
                .Select(sor => (int)sor.RelationObject_ID)
                .ToList(), cityTC);
            var withWebinar = PriceService.CourseWithWebinar();
            var discount30  = Discount30Courses();
            var actions     = GetActionOnCoursePages().Where(x => {
                var courseTCList = EntityUtils.GetCourseTCs(x, withWebinar);
                return(!courseTCList.Any() || courseTCList.Contains(courseTC) ||
                       (x.MarketingAction_ID == 150 && discount30.Contains(courseTC)));
            }).OrderBy(x => x.WebSortOrder).ToList();

            if (course.IsExpensive)
            {
                actions = actions.Where(x => !x.CourseTCList.IsEmpty()).ToList();
            }
            var preTestIds = course.CoursePrerequisites.Select(x => x
                                                               .Test_ID.GetValueOrDefault())
                             .Where(x => x > 0).ToList();

            var preTests = preTestIds.Any()
                        ? TestService.GetAll(x =>
                                             preTestIds.Contains(x.Id)).ToList()
                        : new List <Test>();

            var sections = SiteObjectService.GetSingleRelation <Section>(course)
                           .IsActive().Where(x => !Sections.NotImportant.Contains(x.Section_ID)).ByWebOrder().ToList();

            var tests = SiteObjectService.GetByRelationObject <Test>(course)
                        .Where(x => x.Status == TestStatus.Active).ToList();
            var visitedCourseTCs = UserSettingsService.VisitedCourses.Except(_.List(courseTC)).ToList();
            var visitedCourses   = CourseService.GetCourseLinkList(visitedCourseTCs).ToList();

            visitedCourseTCs.Insert(0, courseTC);
            UserSettingsService.VisitedCourses = visitedCourseTCs;
            var courseContentTC = courseTC == "сопсв-ю" && Htmls.IsSecond ? CourseTC.WebText : courseTC;
            var courseContents  = CourseContentService.GetAll(x => x.Course_TC == courseContentTC).ToList();
            var certTypes       = course.CourseCertificates.Select(cc => cc.CertType).Where(x => x.IsVisible).ToList();
            var hasTracks       = TrackService.GetAllTracksWithCourse(courseTC).Any();
            var courseDetailsVM =
                new CourseVM {
                Course            = course,
                SecondCourse      = secondCourse,
                CourseInDiplom    = CourseService.CoursesInDiploms().Contains(courseTC),
                PrerequisiteTests = preTests,
                HasPaperBook      = ExtrasService.CoursesWithPaperBook().Contains(courseTC),
                Actions           = actions,
                HasTracks         = hasTracks,
                CourseContents    = courseContents,
                Tests             = tests,
                MaxDiscount       = GroupService.GetGroupsForCourse(courseTC)
                                    .Where(x => !x.IsOpenLearning).Select(x => x.Discount).Max(),
                CompleteCourseCount = CompleteCountForCourses().GetValueOrDefault(courseTC),
                Responses           = responses.ToList(),
                SuccessStories      = successStories,
                NextCourses         = nextCourses.ToList(),
                WebinarDiscount     = PriceService.WebinarDiscouns().GetValueOrDefault(courseTC),
                NearestGroups       = nearestGroups,
                Certifications      = certifications,
                Prices             = prices,
                MorningDiscount    = morningDiscount,
                Trainers           = trainers.ToList(),
                Vacancies          = vacancies.ToList(),
                ResponseTotalCount = responseTotalCount,
                UnlimitPrice       = PriceService.GetUnlimitPrice(courseTC),
                Sections           = sections,
                Product            = product,
                VisitedCourses     = visitedCourses,
                CertTypeList       = certTypes,
                WebinarDiscounts   = PriceService.WebinarDiscouns()
            };

            return(courseDetailsVM);
        }
Example #12
0
        public AllCourseListVM GetAll(object obj)
        {
            var courses = obj == null
                                ? CourseService.AllCoursesForList()
                                : CourseService.GetAllFor(obj);

            var track         = obj as Course;
            var isTrack       = track != null;
            var isTrackDiplom = track != null && courses.FirstOrDefault(x => x.Course_TC == track.Course_TC)
                                .GetOrDefault(x => x.IsDiplom);
            var trackList              = obj as TrackListVM;
            var siteTerm               = obj as SiteTerm;
            var isIntraExtraTerm       = siteTerm != null && siteTerm.SiteTerm_ID == Sections.Terms.IntraExtra;
            var isOpenClassesTerm      = siteTerm != null && siteTerm.SiteTerm_ID == Sections.Terms.OpenClasses;
            var isDiplomPage           = trackList != null && trackList.IsDiplomPage;
            var isTrainingProgramsPage = trackList != null && trackList.IsTrainingProgramsPage;

            if (isDiplomPage || isTrainingProgramsPage)
            {
                courses = courses.Where(x => trackList.Courses.Contains(x.Course_TC)).ToList();
            }
            var isIntraExtraTrackPage = (isTrack && CourseService.IntraExtraTracks().Contains(track.Course_TC)) ||
                                        isDiplomPage;
            var trackFullPrices = TrackService.TrackFullPrices();
            var items           =
                courses.Select(c => {
                var nearestGroupAndWebinar = GroupService.GetNearestGroupAndWebinar(c,
                                                                                    isIntraExtraTrackPage || isIntraExtraTerm, isOpenClassesTerm);
                var coefficient = isTrack
                                                ? null
                                                : GroupService.GetGroupsForCourse(c.Course_TC).Where(x => !x.IsIntraExtramural)
                                  .Select(x => PriceUtils.GetCoefficient(x)).Min();

                var prices      = PriceService.GetAllPricesForCourse(c.Course_TC, null);
                var trackPrices = c.IsTrackBool
                                ? trackFullPrices.GetValueOrDefault(c.Course_TC)
                                : null;
                return(new CommonCourseListItemVM
                {
                    Course = c,
                    IsIntraExtraTrackPage = isIntraExtraTrackPage,
                    IsTrackPage = isTrack,
                    TrackFullPrices = trackPrices,
                    NearestGroup = nearestGroupAndWebinar.Item1,
                    NearestWebinar = nearestGroupAndWebinar.Item2,
                    Prices = prices,
                    PriceCoefficent = coefficient
                });
            })
                .ToList();
            var commonCourseListVM = new CommonCourseListVM
            {
                Items                  = items,
                IsTrackPage            = isTrack,
                IsDiplomPage           = isDiplomPage,
                IsTrainingProgramsPage = isTrainingProgramsPage
            };

            return
                (new AllCourseListVM
            {
                MainList = courses,
                TrackCounts = CourseService.TrackCourseCounts(),
                TrackLastCourseDiscounts = TrackService.TrackLastCourseDiscounts(),
                Common = commonCourseListVM,
                IsTrack = isTrack,
                IsDiplomPage = isDiplomPage,
                IsTrainingProgramsPage = isTrainingProgramsPage,
                IsIntraExtra = isIntraExtraTrackPage,
                IsTrackDiplom = isTrackDiplom,
                HideIntraGroup = isIntraExtraTerm || isOpenClassesTerm,
                IsOpenClasses = isOpenClassesTerm,
                CourseWithUnlimit = PriceService.CourseWithUnlimite(),
            });
        }