public virtual MainCoursesVM GetMainCourses() { var allRootSections = SectionVMService.GetSectionWithEntityTree(); var professions = ProfessionService.GetAll() .OrderByName().IsActive().ToDictionary(x => x.Profession_ID, x => x); var professionSections = SiteObjectRelationService.GetRelation(typeof(Profession), Enumerable.Empty <object>(), typeof(Section)).ToList(); var sectionIds = new HashSet <int>(professionSections.Select(x => x.RelationObject_ID).Cast <int>()); var sectionForProfession = allRootSections.Select(x => x.Entity.As <Section>()).Where(x => sectionIds.Contains(x.Section_ID)); return (new MainCoursesVM { Products = ProductService.GetAll() .OrderByName().IsActive().ToList(), SiteTerms = SiteTermService.GetAll() .OrderByName().IsActive().ToList(), Professions = sectionForProfession.Select(x => EntityWithList.New(x, professionSections.Where(sor => sor.RelationObject_ID.Equals(x.Section_ID)) .Select(y => professions.GetValueOrDefault((int)y.Object_ID)) .Cast <IEntityCommonInfo>().Where(p => p != null))).ToList(), RootSections = allRootSections, Vendors = VendorService.GetAll() .OrderByName().IsActive().ToList(), }); }
public ActionResult GuideFor(object obj) { var model = new List <Guide>(); var track = obj.As <Course>(); var ids = new List <object>(); if (track != null && track.IsTrackBool) { var courseTCs = CourseService.GetActiveTrackCourses() .GetValueOrDefault(track.Course_TC) ?? new List <string>(); ids = courseTCs.Cast <object>().ToList(); } else { ids = _.List(LinqToSqlUtils.GetPK(obj)); } if (ids.Any()) { var guideIds = SiteObjectRelationService .GetRelation(typeof(Guide), Enumerable.Empty <object>(), obj.GetType()).Where(x => ids.Contains(x.RelationObject_ID)) .OrderBy(x => x.RelationOrder) .Select(x => x.Object_ID).ToList().Cast <int>().ToList(); model = GuideService.GetAll(x => guideIds.Contains(x.GuideID) && x.IsActive).Distinct().ToList() .OrderBy(x => guideIds.IndexOf(x.GuideID)).ToList(); } return(View(PartialViewNames.GuidesBlock, model.ToList())); }
GetSectionWithEntityTree() { var mainSections = SectionService.GetAll(x => x.IsMain && x.IsActive) .OrderBy(x => x.WebSortOrder).ToList(); return(mainSections.Select(x => EntityWithList.New((IEntityCommonInfo)x, SiteObjectRelationService.GetMenuTree(x).Select(e => e.Entity) .Where(e => e is Section || e.As <IForMainPage>() .GetOrDefault(z => z.ForMainPage)))).ToList()); }
public ActionResult WithoutTag(int count) { var courseTCs = SiteObjectRelationService.GetRelation(typeof(Course), Enumerable.Empty <object>()) .GroupBy(x => x.Object_ID) .Where(x => x.Count() == count) .Select(x => x.Key.ToString()).Distinct().ToList(); return(CourseTable("Курсы без связей", c => courseTCs.Contains(c.Course_TC))); }
// private Dictionary<Tuple<string, string>, string> _names; public Dictionary <Tuple <string, string>, int> Counts() { if (_counts == null) { _counts = SiteObjectRelationService.GetAll(x => x.ObjectType == SiteObject.TypeTableNames[typeof(Course)]) .Where(x => x.Object.IsActive).Select(x => new { x.RelationObject_ID, x.RelationObjectType }).ToList() .Select(x => Tuple.Create(x.RelationObjectType, x.RelationObject_ID.ToString())) .GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count()); } return(_counts); }
public ActionResult MainPageResponse() { var courseTableName = LinqToSqlUtils.GetTableName(typeof(Course)); var courseTCs = GroupService.GetPlannedAndNotBegin().Where(g => g.Discount > 0) .Take(CommonConst.GroupForMainCount) .Select(x => x.Course_TC).Distinct().ToList(); var courseTCsForResponse = CacheUtils.Get("courseTCsForMainResponses", () => SiteObjectRelationService.GetRelation(typeof(Course), courseTCs) .SelectMany(x => x.RelationObject.RelationObjectRelations.Where(sor => sor.ObjectType == courseTableName).Select(y => y.Object_ID)).Select(x => x.ToString()).Distinct().ToList()); var response = ResponseService.GetRandomForMainPage(courseTCsForResponse); var orgResponse = ResponseService.GetOrgRandomResponseForMainPage(); return(PartialView(Tuple.Create(response, orgResponse))); }
List <IGrouping <bool, Tuple <string, decimal> > > Section(int sectionId) { var courseTCs = SiteObjectRelationService .GetByRelation(typeof(Section), sectionId, typeof(Course)).Select(x => x.Object_ID.ToString()) .ToList(); var parents = CourseService.GetAll(x => courseTCs.Contains(x.Course_TC) && x.IsTrack != true) .Select(x => x.ParentCourse_TC).Distinct().ToList(); var context = new RecRepository().GetContext(); var coefs = parents.SelectMany(x => GetCoefs(context, x)) .GroupBy(x => x.Item1, x => x.Item2).Select(x => Tuple.Create(x.Key, x.Sum() / x.Count())); var zero = parents.Except(coefs.Select(x => x.Item1)).Select(x => Tuple.Create(x, decimal.Zero)); coefs = coefs.Concat(zero); var coefs2 = coefs .GroupBy(x => parents.Contains(x.Item1)); return(coefs2.ToList()); }
private List <string> RecomendCourseTCs(UserTest userTest) { var courseTCs = new List <string>(); var isEnglishTest = TestRecomendations.IsEnglishTest(userTest.TestId); if (userTest.IsPrerequisite && !isEnglishTest) { if (userTest.IsPass) { courseTCs.Add(userTest.Course_TC); } else { courseTCs.AddRange( EntityUtils.GetCoursePreCourses(CoursePrerequisiteService, userTest.Course_TC).Select(x => x.RequiredCourse_TC)); } } else { var recomendations = TestRecomendations.Tests.GetValueOrDefault(userTest.TestId); if (recomendations == null) { courseTCs = SiteObjectRelationService.GetRelation(typeof(Test), _.List <object>(userTest.TestId), typeof(Course)).Select(x => x.RelationObject_ID) .Cast <string>().ToList(); if (courseTCs.Any() && userTest.IsPass) { var parentCourseTCs = CourseService.GetAll(x => courseTCs.Contains(x.Course_TC)) .Select(x => x.ParentCourse_TC).ToList(); courseTCs = CourseService.GetNextCourseTCs(parentCourseTCs); } } else { courseTCs = recomendations.First(x => x.Key <= userTest.RightCount.GetValueOrDefault()).Value; } } return(courseTCs); }
// public Dictionary<Tuple<string, string>, int> Names() { // if (_names == null) { // _names = SiteObjectService.ge; // } // return _names; // } public ActionResult Sections() { var r = MethodBase.GetCurrentMethod().CacheInFileDay(() => { var tree = SiteObjectRelationService.GetAllMenuTree(); var withoutChildren = _.List(typeof(Course), typeof(Product), typeof(Profession), typeof(SiteTerm)); var json = tree.Where(x => !withoutChildren.Contains(x.Key.Item1) && x.Value.Any()).Select(x => { var type = SiteObject.TypeTableNames[x.Key.Item1]; var id = x.Key.Item2; var count = Counts().GetValueOrDefault(Tuple.Create(type, id.ToString())); return(new JsonRootSection(type, id, "", x.Value.Select(y => EntityJson(y.Entity)).ToList(), count, GetName(type, id) )); }); return(JsonConvert.SerializeObject(json)); }); return(Content(r)); }
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); }
public ActionResult Recommendations(RecommendationsVM model) { var courses = new List <Course>(); var completeCourseTC = new List <string>(); var testCourseTC = new List <string>(); foreach (var key in ModelState.Keys) { ModelState[key].Errors.Clear(); } if (System.Web.HttpContext.Current.Request.IsPost()) { var user = UserService.GetAll(x => x.Email == model.Email).FirstOrDefault(); if (user == null) { var student = StudentService.FirstOrDefault(x => x.StudentEmails.Any(z => z.Email == model.Email)); if (student != null) { user = new User { Student = student } } ; } if (user == null) { this.ModelState.AddModelError("", "Слушатель не существует"); } else { if ((model.ProductId == 0 && model.ProfessionId == 0) || (model.ProductId > 0 && model.ProfessionId > 0)) { this.ModelState.AddModelError("", "Выберите профессию или продукт"); } else { var entityCourseTCList = EntityStudySetService.GetByPK( Math.Max(model.ProductId, model.ProfessionId)).CourseTCList; completeCourseTC = GetCompleteCourses(user); courses = GetCourses(entityCourseTCList, completeCourseTC); if (user.UserID > 0) { var testIds = UserTestService.GetAll(x => x.UserId == user.UserID && UserTestStatus.PassStatuses.Contains(x.Status)) .Select(x => x.TestId).Distinct().ToList(); testCourseTC = SiteObjectRelationService.GetRelation(typeof(Test), testIds.Cast <object>(), typeof(Course)) .Select(x => x.RelationObject_ID).ToList().Cast <string>() .ToList(); } } } } else { model = new RecommendationsVM(); } var sets = EntityStudySetService.GetAll().ToList(); model.Professions = sets.Where(x => x.Type == 1).OrderBy(x => x.EntityName).ToList(); model.Products = sets.Where(x => x.Type == 2).OrderBy(x => x.EntityName).ToList(); model.Courses = courses; model.TestCourseTCs = testCourseTC; model.CompleteCourseTCs = completeCourseTC; return(View(model)); }