コード例 #1
0
        public void Initialize()
        {
            var blogPages = new List <BlogPage.BlogPage>();

            using (var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext())
            {
                var contentCache = umbracoContextReference.UmbracoContext.Content;

                var blogPagePublishedContentType = contentCache.GetContentType(DocumentTypeAlias.BlogPage);
                var blogPagesAsPublishedContent  = contentCache.GetByContentType(blogPagePublishedContentType);

                if (blogPagesAsPublishedContent == null)
                {
                    return;
                }

                umbracoMapper.MapCollection(blogPagesAsPublishedContent, blogPages);
            }

            var blogPageControllerName = nameof(BlogPageController).Replace("Controller", string.Empty);

            foreach (var blogPage in blogPages)
            {
                RouteTable.Routes.MapUmbracoRoute($"BlogPageRoute{blogPage.Name}",
                                                  $"blogs/{blogPage.Name.ToFirstLower()}/{nameof(BlogPageController.Feed)}/{{id}}", new
                {
                    controller = blogPageControllerName,
                    action     = nameof(BlogPageController.Feed),
                    id         = UrlParameter.Optional
                }, new BlogPageRouteHandler(blogPage.Id));
            }
        }
コード例 #2
0
        public static object MapCallouts(IUmbracoMapper mapper, IPublishedContent contentToMapFrom, string propName, bool isRecursive)
        {
            var result = new List <CalloutViewModel>();

            ArchetypeModel archetypeModel = contentToMapFrom.GetPropertyValue <ArchetypeModel>(propName, isRecursive, null);

            if (archetypeModel != null)
            {
                var archetypeAsDictionary = archetypeModel
                                            .Select(item => item.Properties.ToDictionary(m => m.Alias, m => GetTypedValue(m), StringComparer.InvariantCultureIgnoreCase))
                                            .ToList();
                mapper.MapCollection(archetypeAsDictionary, result);
            }

            return(result);
        }
コード例 #3
0
        public static IEnumerable <T> GetCollection <T>(IUmbracoMapper mapper, IPublishedContent contentToMapFrom, string propertyAlias, bool recursive)
            where T : BaseModuleViewModel, new()
        {
            var contentList       = contentToMapFrom.GetPropertyValue <IEnumerable <IPublishedContent> >(propertyAlias, recursive);
            var publishedContents = contentList as IPublishedContent[] ?? contentList.ToArray();

            if (!publishedContents.IsAndAny())
            {
                return(null);
            }

            var model = new List <T>();

            mapper.MapCollection(publishedContents, model);

            return(model);
        }
コード例 #4
0
        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));
        }