public Course GetCourseByNiceUrl(string niceUrl) { IPublishedContent coursePublishedContent = GetCoursePublishedContentByNiceUrl(niceUrl); if (coursePublishedContent == null) { return(null); } int courseId = GetCourseId(coursePublishedContent); Course course = _courses.GetById(courseId); return(course); }
public ActionResult Course(RenderModel model) { Course coursePublishedContentViewModel = new Course(); _mapper.AddCustomMapping(typeof(ImageViewModel).FullName, UmbracoMapperMappings.MapMediaFile) .AddCustomMapping(typeof(int).FullName, UmbracoMapperMappings.MapPicker, nameof(Models.Umbraco.DocumentTypes.Course.CourseId)) .Map(model.Content, coursePublishedContentViewModel); List <FileViewModel> files = new List <FileViewModel>(); string[] fileIds = model.Content.GetPropertyValue <string>(nameof(Models.Umbraco.DocumentTypes.Course.Files)).Split(','); IEnumerable <IPublishedContent> fileContent = Umbraco.TypedMedia(fileIds); _mapper.MapCollection(fileContent, files, new Dictionary <string, PropertyMapping> { { nameof(FileViewModel.Size), new PropertyMapping { SourceProperty = global::Umbraco.Core.Constants.Conventions.Media.Bytes } }, { nameof(FileViewModel.FileExtension), new PropertyMapping { SourceProperty = global::Umbraco.Core.Constants.Conventions.Media.Extension } } }); AcademyPlatform.Models.Courses.Course course = _courses.GetById(coursePublishedContentViewModel.CourseId); string joinCourseUrl = Url.RouteUrl("JoinCourse", new { courseNiceUrl = model.Content.UrlName }); string assessmentUrl = Url.RouteUrl("Assessment", new { courseNiceUrl = model.Content.UrlName }); string profileUrl = Url.RouteUrl("Profile"); CourseDetailsViewModel courseDetailsViewModel = new CourseDetailsViewModel { CourseId = course.Id, Category = course.Category, Title = course.Title, ImageUrl = coursePublishedContentViewModel.CoursePicture.Url, Files = files, CoursesPageUrl = model.Content.Parent.Url, JoinCourseUrl = joinCourseUrl, AssessmentUrl = assessmentUrl, ProfileUrl = profileUrl, AssessmentEligibilityStatus = _assessmentsService.GetEligibilityStatus(User.Identity.Name, coursePublishedContentViewModel.CourseId), DetailedDescription = coursePublishedContentViewModel.DetailedDescription, ShortDescription = coursePublishedContentViewModel.ShortDescription, Features = coursePublishedContentViewModel.Features, SampleCertificate = coursePublishedContentViewModel.SampleCertificate, Status = course.Status }; //======================================================================================== List <Module> modulesPublishedContent = new List <Module>(); List <IPublishedContent> modulesContent = model.Content.DescendantsOrSelf(nameof(Module)).ToList(); _mapper.Map(model.Content, coursePublishedContentViewModel) .MapCollection(modulesContent, modulesPublishedContent); foreach (IPublishedContent moduleContent in modulesContent) { ModuleViewModel module = new ModuleViewModel { Name = moduleContent.Name }; List <IPublishedContent> lecturesContent = moduleContent.DescendantsOrSelf(nameof(Lecture)).ToList(); foreach (IPublishedContent lectureContent in lecturesContent) { LectureLinkViewModel lecture = new LectureLinkViewModel(); _mapper.Map(lectureContent, lecture); lecture.IsVisited = _lectures.IsLectureVisited(User.Identity.Name, lectureContent.Id); module.LectureLinks.Add(lecture); } courseDetailsViewModel.Modules.Add(module); } //==================================================================== courseDetailsViewModel.HasActiveSubscription = User.Identity.IsAuthenticated && _subscriptions.HasActiveSubscription( User.Identity.Name, courseDetailsViewModel.CourseId); if (TempData.ContainsKey("ErrorMessage")) { courseDetailsViewModel.ErrorMessage = (string)TempData["ErrorMessage"]; } return(CurrentTemplate(courseDetailsViewModel)); }