Example #1
0
        public GroupListVM GetAllGroups(GroupFilter filter, int pageIndex)
        {
            var cityTC         = UserSettingsService.CityTC;
            var leftBeginDate  = filter.BeginDate;
            var rightBeginDate = filter.EndDate;
            var courseTCs      = new List <string>();

            if (!filter.CourseTC.IsEmpty())
            {
                courseTCs.Add(filter.CourseTC);
            }
            else
            {
                if (filter.SectionId.HasValue)
                {
                    var mainSection =
                        SectionService.GetSectionsTree()
                        .FirstOrDefault(x => x.Section_ID
                                        == filter.SectionId.Value);
                    var sectionIds = new List <int>();
                    if (mainSection != null && mainSection.SubSections.Any())
                    {
                        sectionIds = mainSection.SubSections.Select(x => x.Section_ID).ToList();
                    }
                    else
                    {
                        sectionIds.Add(filter.SectionId.Value);
                    }
                    courseTCs.AddRange(CourseService.GetCourseTCListForSections(sectionIds));
                }
            }
            var groupQuery = GroupService.GetGroupsForCourse(courseTCs,
                                                             cityTC, leftBeginDate, rightBeginDate, filter.DayShiftTC, filter.ComplexTC,
                                                             filter.DaySequenceTC);

            switch (filter.StudyTypeId)
            {
            case GroupFilter.StudyType.Intramural:
                groupQuery = groupQuery.Where(x => !x.ForWebinarOnly);
                break;

            case GroupFilter.StudyType.Webinar:
                groupQuery = groupQuery.Where(x => x.WebinarExists);
                break;

            case GroupFilter.StudyType.OpenLearning:
                groupQuery = groupQuery.Where(x => x.MegaGroup_ID != null);
                break;

            case GroupFilter.StudyType.IntraExtra:
                groupQuery = groupQuery.Where(x => x.IsIntraExtramural);
                break;
            }
            if (!filter.EmployeeTC.IsEmpty())
            {
                groupQuery = groupQuery.Where(x => x.Teacher_TC == filter.EmployeeTC);
            }
            groupQuery = groupQuery.NotSpecial();
            var groups = groupQuery.ToPagedList(pageIndex);
            var result =
                new GroupListVM {
                Groups = groups,
                Filter = filter,
            };

            if (!filter.CourseTC.IsEmpty())
            {
                var course = CourseService.GetByPK(filter.CourseTC);
                filter.CourseName = course.GetOrDefault(x => x.Name);
                result.Course     = course;
            }


            return(result);
        }
Example #2
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 #3
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(),
            });
        }