public CertificationVM GetByUrlName(string urlName)
        {
            var certification = CertificationService.GetAll().ByUrlName(urlName);

            if (certification.IsNull())
            {
                return(null);
            }
            var tracks = certification.Exams.SelectMany(e => e.Courses)
                         .Where(c => c.IsTrack.GetValueOrDefault()).Distinct().ToList();


            var trainers = EmployeeCertificationService.GetAll(
                x => x.Certification_ID == certification.Certification_ID &&
                x.Certification.IsActive)
                           .Select(x => x.Employee).Where(x => x.SiteVisible).Take(20).ToList();


            var children = new List <Certification>();

            if (!certification.Exams.Any())
            {
                children = CertificationService.GetAll().IsActive()
                           .Where(c => c.UrlName.StartsWith(certification.UrlName) &&
                                  c.UrlName != certification.UrlName).OrderBy(x => x.SortOrder)
                           .ToList();
            }

            var groups = certification.Exams.Any()
                                ? GetCertificationGroups(_.List(certification.Certification_ID))
                                : GetCertificationGroups(children.Select(x => x.Certification_ID).ToList());

            var model = new CertificationVM
            {
                Certification = certification,
                Children      = children,
                Tracks        = TrackService.GetTrackDiscounts(tracks).ToList(),
                Groups        = groups,
                Trainers      = trainers
            };

            if (model.IsMicrosoft)
            {
                model.Actions = MarketingActionService.GetAll(x => x.Type == MarketingActionType.Microsoft &&
                                                              !x.IsSecret && x.IsActive).ToList();
            }

            return(model);
        }
        private List <Group> GetCertificationGroups(List <decimal> certifictionIds)
        {
            if (!certifictionIds.Any())
            {
                return(new List <Group>());
            }
            var courseTCs = CertificationService.GetAll(x =>
                                                        certifictionIds.Contains(x.Certification_ID))
                            .SelectMany(y => y.CertificationExams.SelectMany(z =>
                                                                             z.Exam.ExamCourses.Select(x => x.Course_TC))).ToList().Distinct()
                            .ToList();

            return(courseTCs.SelectMany(c => GroupService.GetGroupsForCourse(c))
                   .OrderBy(x => x.DateBeg).Take(30).ToList());
        }
Exemple #3
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);
        }