コード例 #1
0
 public static void Configure(IUmbracoMapper umbracoMapper, IUmbracoHelperService umbracoHelperService)
 {
     UmbracoHelperService = umbracoHelperService;
     umbracoMapper.AddCustomMapping(typeof(BaseWebPage).FullName, MapBaseWebPage);
     umbracoMapper.AddCustomMapping(typeof(MediaFile).FullName, MapMediaFile);
     umbracoMapper.AddCustomMapping(typeof(IEnumerable<MediaFile>).FullName, MapMediaFiles);
 }
コード例 #2
0
        protected BaseHandler(IUmbracoMapper mapper, IPublishedContent rootNode)
        {
            Mapper = mapper;
            Mapper.AddCustomMapping(typeof(MediaFile).FullName, MediaFileMapping.Map);

            Umbraco = new UmbracoHelper(UmbracoContext.Current);

            _routeNode = rootNode;
        }
コード例 #3
0
        private FeedbackViewModel GetFeedbackViewModel()
        {
            //TODO move and reuse logic in AssessmentController
            object            feedbackFormId  = Umbraco.AssignedContentItem.GetPropertyValue <Picker>(nameof(Course.FeedbackForm)).SavedValue;
            IPublishedContent feedbackContent = Umbraco.TypedContent(feedbackFormId);

            var feedbackViewModel = new FeedbackViewModel();
            List <QuestionViewModel>        questionViewModel = new List <QuestionViewModel>();
            IEnumerable <IPublishedContent> questions         = feedbackContent.Descendants(1).OrderBy(x => Guid.NewGuid()).ToList();

            _mapper.AddCustomMapping(
                typeof(IEnumerable <QuestionAnswer>).FullName,
                UmbracoMapperMappings.MapQuestionAnswer)
            .MapCollection(questions, questionViewModel)
            .Map(feedbackContent, feedbackViewModel);

            feedbackViewModel.Questions = questionViewModel;
            return(feedbackViewModel);
        }
コード例 #4
0
        public ActionResult RenderCoursesGrid(int numberOfCourses, bool shouldHideFilters)
        {
            IEnumerable <IPublishedContent> coursesContentCollection = Umbraco.TypedContentAtRoot().DescendantsOrSelf(nameof(Course));

            if (numberOfCourses != default(int))
            {
                coursesContentCollection = coursesContentCollection.Take(numberOfCourses);
            }

            List <Course> coursesContentViewModels = new List <Course>();

            _mapper.AddCustomMapping(typeof(ImageViewModel).FullName, UmbracoMapperMappings.MapMediaFile)
            .AddCustomMapping(typeof(PageLink).FullName, UmbracoMapperMappings.MapPageLink)
            .AddCustomMapping(typeof(int).FullName, UmbracoMapperMappings.MapPicker, nameof(Course.CourseId))
            .MapCollection(coursesContentCollection, coursesContentViewModels);

            IEnumerable <AcademyPlatform.Models.Courses.Course> courses = _courses.GetActiveCourses().ToList();

            List <CoursesListViewModel> coursesViewModels = coursesContentViewModels.Join(
                courses,
                coursesContent => coursesContent.CourseId,
                course => course.Id,
                (coursesContent, course) => new CoursesListViewModel
            {
                Title            = course.Title,
                CourseUrl        = coursesContent.Url,
                ImageUrl         = coursesContent.CoursePicture.Url,
                ShortDescription = coursesContent.ShortDescription,
                Category         = course.Category,
                IsJoined         = User.Identity.IsAuthenticated && _subscriptions.HasActiveSubscription(User.Identity.Name, course.Id),
                JoinCourseUrl    = Url.RouteUrl("JoinCourse", new { courseNiceUrl = coursesContent.UrlName }),
                PartnerPageUrl   = coursesContent.PartnerPage.Url,
                PartnerLogoUrl   = coursesContent.PartnerLogo.Url,
                Status           = course.Status
            }).ToList();

            //TODO Find out why(if) distinct works without implementing IEquitable<T>
            ViewBag.Categories        = coursesViewModels.Select(x => x.Category).Distinct();
            ViewBag.ShouldHideFilters = shouldHideFilters;
            return(PartialView(coursesViewModels));
        }
コード例 #5
0
        public CertificateGenerationInfo GetByCourseId(int courseId)
        {
            IPublishedContent courseContent = _coursesContentService.GetCoursePublishedContentById(courseId);
            int certificateId = (int)courseContent.GetPropertyValue <Picker>(nameof(Course.Certificate)).SavedValue;
            IPublishedContent         certificateContent        = UmbracoContext.Current.ContentCache.GetById(certificateId);
            CertificateGenerationInfo certificateGenerationInfo = new CertificateGenerationInfo();

            IPublishedContent certificateTemplate = UmbracoContext.Current.MediaCache.GetById(
                certificateContent.GetPropertyValue <int>(
                    nameof(AcademyPlatform.Web.Models.Umbraco.DocumentTypes.Certificate.CertificateTemplate)));

            _mapper.AddCustomMapping(
                typeof(PlaceholderInfo).FullName,
                UmbracoMapperMappings.MapPlaceholder)
            .Map(certificateContent, certificateGenerationInfo);

            certificateGenerationInfo.TemplateFilePath = HttpContext.Current.Server.MapPath(certificateTemplate.Url);
            certificateGenerationInfo.BaseFilePath     = HttpContext.Current.Server.MapPath("/");

            return(certificateGenerationInfo);
        }
コード例 #6
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));
        }
コード例 #7
0
        public ActionResult Assessment()
        {
            int    courseId = _coursesContentService.GetCourseId(Umbraco.AssignedContentItem);
            string username = User.Identity.Name;

            if (!_feedbackService.UserHasSentFeedback(username, courseId))
            {
                return(RedirectToRoute("Feedback", new { courseNiceUrl = Umbraco.AssignedContentItem.UrlName }));
            }

            if (_assessments.GetEligibilityStatus(username, courseId) != AssessmentEligibilityStatus.Eligible)
            {
                TempData["ErrorMessage"] = $"В момента нямате достъп до изпита за този курс. Моля посетете <a href=\"{Url.RouteUrl("Profile")}\" title=\"Профил\">Вашия профил </a> за повече информация.";
                return(Redirect(Umbraco.AssignedContentItem.Url));
            }

            object            assessmentId      = Umbraco.AssignedContentItem.GetPropertyValue <Picker>(nameof(Course.Assessment)).SavedValue;
            IPublishedContent assessmentContnet = Umbraco.TypedContent(assessmentId);
            var user = _users.GetByUsername(username);
            AssessmentViewModel             assessment        = new AssessmentViewModel();
            List <QuestionViewModel>        questionViewModel = new List <QuestionViewModel>();
            IEnumerable <IPublishedContent> questions;
            var assessmentRequest = _assessments.GetLatestForUser(user.Username, assessmentContnet.Id);

            if (assessmentRequest == null)
            {
                var numberOfQuestions =
                    assessmentContnet.GetPropertyValue <int>(
                        nameof(Models.Umbraco.DocumentTypes.Assessment.NumberOfQuestions));
                if (numberOfQuestions == default(int))
                {
                    throw new ArgumentException($"Number of questions is not set for assessment with ID: {assessmentId}");
                }

                questions = assessmentContnet.Descendants(1).OrderBy(x => Guid.NewGuid()).Take(numberOfQuestions).ToList();

                assessmentRequest = new AssessmentRequest
                {
                    AssessmentExternalId = assessmentContnet.Id,
                    QuestionIds          = string.Join(",", questions.Select(x => x.Id)),
                    IsCompleted          = false,
                    UserId = user.Id
                };
                _assessments.CreateAssesmentRequest(assessmentRequest);
            }
            else
            {
                questions = Umbraco.TypedContent(assessmentRequest.QuestionIds.Split(',')).ToList();
            }

            _mapper.AddCustomMapping(
                typeof(IEnumerable <QuestionAnswer>).FullName,
                UmbracoMapperMappings.MapQuestionAnswer)
            .MapCollection(questions, questionViewModel)
            .Map(assessmentContnet, assessment);

            assessment.Questions           = questionViewModel;
            assessment.AssessmentRequestId = assessmentRequest.Id;

            return(View(assessment));
        }