Пример #1
0
        GetAllSectionGroups(this NearestGroupSet nearestGroupSet)
        {
            var result = new List <SectionGroups>();

            result.Add(Tuple.New("sectionall", nearestGroupSet.All));
            result.AddRange(nearestGroupSet.DayShiftGroups
                            .Select(ds => Tuple.New("section" + ds.Entity.DayShift_TC, ds.List)));
            result.Add(Tuple.New("sectionweekend", nearestGroupSet.Weekend));
            if (nearestGroupSet.Webinars.Any())
            {
                result.Add(Tuple.New("sectionwebinars", nearestGroupSet.Webinars));
            }
            return(result);
        }
Пример #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);
        }
Пример #3
0
        public string GetCsv()
        {
            var allPrices = PriceViewService.GetAll(x => x.Track_TC == null).ToList()
                            .GroupByToDictionary(x => x.Course_TC, x => x);
            var allGroups = GroupService.GetAll().PlannedAndNotBegin()
                            .Where(x => x.Color_TC == Colors.Yellow && x.Course.IsActive)
                            .OrderBy(x => x.DateBeg).ToList().GroupByToDictionary(x => x.Course_TC, x => x);
            var result = new List <List <string> >();

            CourseService.LoadWith(x => x.CourseContents, x => x.AuthorizationType);
            var courses = CourseService.GetAll().Where(x => x.IsActive &&
                                                       !CourseTC.HalfTrackCourses.Contains(x.Course_TC) &&
                                                       !x.IsTrack.Value).OrderBy(x => x.Course_ID).ToList();

            foreach (var course in courses)
            {
                var courseTC  = course.Course_TC;
                var row       = new List <string>();
                var prices    = allPrices.GetValueOrDefault(courseTC) ?? new List <PriceView>();
                var isWebinar = GetPrice(PriceTypes.Webinar, prices) > 0;
                var groupList = allGroups.GetValueOrDefault(courseTC) ?? new List <Group>();
                row.Add(courseTC);
                row.Add(course.Name);
                row.Add(((int)course.BaseHours) + " ак.ч.");
                row.Add(course.AuthorizationType.GetOrDefault(x => x.AuthorizationName));
                row.Add(course.IsProjectAllowed ? "П" : "");
                row.Add(isWebinar ? "В" : "");
                var description = course.Description;
                row.Add(ClearnText(description));
                var prerequisete = course.CoursePrerequisites.Select(
                    x => (x.Text + " " + x.RequiredCourse.GetOrDefault(z => z.Name)).Trim()).Where(x => x != null).JoinWith(";");
                row.Add(ClearnText(prerequisete));
                row.Add(ClearnText(course.OnComplete));
                var contents = course.CourseContents.OrderBy(x => x.ModuleNumber)
                               .Select(x => "Модуль " + x.ModuleNumber + ". " + x.ModuleName)
                               .JoinWith(";");
                row.Add(ClearnText(contents));
                Func <string, bool> addPrice =
                    type => {
                    var price = GetPrice(type, prices);
                    if (type == PriceTypes.PrivatePersonWeekend)
                    {
                        var discount     = NearestGroupSet.HasMorningDiscount(groupList);
                        var morningPrice = discount.HasValue ? OrderDetail.FloorToFifty(
                            (price * (100 - discount.Value)) / 100) : price;
                        row.Add(morningPrice > 0 ? morningPrice.ToString() : "");
                    }

                    row.Add(price > 0 ? ((int)price).ToString() : "");

                    return(price > 0);
                };
                var types = _.List(PriceTypes.PrivatePersonWeekend,
                                   PriceTypes.Corporate);
                var hasPrice = false;
                foreach (var prefix in _.List(""))
                {
                    foreach (var type in types)
                    {
                        hasPrice |= addPrice(prefix + type);
                    }
                }
                addPrice(PriceTypes.Webinar);



                if (hasPrice)
                {
                    var groups = groupList
                                 .Select(DateInterval).Distinct().JoinWith(" ");
                    row.Add(groups);
                    row.Add(groupList.Any(x => x.IsOpenLearning) ? "О" : "");
                    var certs = new CourseVM {
                        Course = course
                    }
                    .Certificates.Select(x => x.Name)
                    .JoinWith(";");
                    row.Add(certs);
                    result.Add(row);
                }
            }

            var csv = result.Select(x => x.Select(y => y
                                                  .GetOrDefault(z => z.Replace('\t', ' ').Trim())));

            return(CsvUtil.Render(csv));
        }