Example #1
0
        /// <summary>
        /// Maps data to an empty view model for a custom entity page.
        /// </summary>
        /// <param name="displayModelType">The type information of the display model to apply to the generic view model.</param>
        /// <param name="viewModel">The view model to map data to.</param>
        /// <param name="mappingParameters">The data passed through to map to the view model.</param>
        public virtual async Task MapCustomEntityViewModelAsync <TDisplayModel>(
            ICustomEntityPageViewModel <TDisplayModel> viewModel,
            CustomEntityPageViewModelBuilderParameters mappingParameters
            ) where TDisplayModel : ICustomEntityPageDisplayModel
        {
            await MapAsync(viewModel, mappingParameters);

            if (mappingParameters.CustomEntityModel == null)
            {
                throw new ArgumentNullException(nameof(mappingParameters.CustomEntityModel));
            }

            var customEntityRenderDetails = mappingParameters.CustomEntityModel;
            var publishStatusQuery        = mappingParameters.VisualEditorMode.ToPublishStatusQuery();

            var customModel = new CustomEntityRenderDetailsViewModel <TDisplayModel>();

            customModel.CustomEntityId        = customEntityRenderDetails.CustomEntityId;
            customModel.CustomEntityVersionId = customEntityRenderDetails.CustomEntityVersionId;
            customModel.Locale         = customEntityRenderDetails.Locale;
            customModel.Regions        = customEntityRenderDetails.Regions;
            customModel.Title          = customEntityRenderDetails.Title;
            customModel.UrlSlug        = customEntityRenderDetails.UrlSlug;
            customModel.WorkFlowStatus = customEntityRenderDetails.WorkFlowStatus;
            customModel.PublishDate    = customEntityRenderDetails.PublishDate;
            customModel.PublishStatus  = customEntityRenderDetails.PublishStatus;
            customModel.CreateDate     = customEntityRenderDetails.CreateDate;
            customModel.PageUrls       = customEntityRenderDetails.PageUrls;

            customModel.Model = await _customEntityDisplayModelMapper.MapDisplayModelAsync <TDisplayModel>(customEntityRenderDetails, publishStatusQuery);

            viewModel.CustomEntity = customModel;
        }
Example #2
0
        private async Task <IEditablePageViewModel> GenericBuildCustomEntityModelAsync <TDisplayModel>(
            CustomEntityPageViewModelBuilderParameters mappingParameters
            ) where TDisplayModel : ICustomEntityPageDisplayModel
        {
            var result = await _pageViewModelBuilder.BuildCustomEntityPageViewModelAsync <TDisplayModel>(mappingParameters);

            return(result);
        }
Example #3
0
        /// <summary>
        /// Creates and maps data to a view model for a custom entity details page.
        /// </summary>
        /// <typeparam name="TDisplayModel">The type of display model to apply to the generic view model.</typeparam>
        /// <param name="mappingParameters">The data passed through to map to the view model.</param>
        public virtual async Task <ICustomEntityPageViewModel <TDisplayModel> > BuildCustomEntityPageViewModelAsync <TDisplayModel>(
            CustomEntityPageViewModelBuilderParameters mappingParameters
            ) where TDisplayModel : ICustomEntityPageDisplayModel
        {
            var viewModel = _pageViewModelFactory.CreateCustomEntityPageViewModel <TDisplayModel>();

            await _pageViewModelMapper.MapCustomEntityViewModelAsync(viewModel, mappingParameters);

            return(viewModel);
        }
Example #4
0
        private async Task <IEditablePageViewModel> BuildCustomEntityViewModelAsync(
            Type displayModelType,
            CustomEntityPageViewModelBuilderParameters mappingParameters
            )
        {
            var task = (Task <IEditablePageViewModel>)_methodInfo_GenericBuildCustomEntityModelAsync
                       .MakeGenericMethod(displayModelType)
                       .Invoke(this, new object[] { mappingParameters });

            return(await task);
        }
Example #5
0
        private async Task <ActionResult> GetPageViewResult(Controller controller, PageActionRoutingState state)
        {
            IEditablePageViewModel vm;
            var pageRoutingInfo = state.PageRoutingInfo;

            // Some page types have thier own specific view models which custom data
            switch (pageRoutingInfo.PageRoute.PageType)
            {
            case PageType.NotFound:
                controller.Response.StatusCode = (int)HttpStatusCode.NotFound;
                // Not sure why we're not using a NotFoundViewModel here, but this is old
                // and untested functionality. Content managable not found pages will need to be looked at at a later date
                var notFoundPageParams = new PageViewModelBuilderParameters(state.PageData, state.VisualEditorMode);
                vm = await _pageViewModelBuilder.BuildPageViewModelAsync(notFoundPageParams);

                break;

            case PageType.CustomEntityDetails:
                var model = await GetCustomEntityModel(state);

                var customEntityParams = new CustomEntityPageViewModelBuilderParameters(state.PageData, state.VisualEditorMode, model);

                vm = await BuildCustomEntityViewModelAsync(state.PageData.Template.CustomEntityModelType, customEntityParams);

                break;

            //case PageType.Error:
            //    Response.StatusCode = (int)HttpStatusCode.InternalServerError;
            //    vm = _pageViewModelMapper.MapPage(page, siteViewerMode);
            //    break;
            default:
                var pageParams = new PageViewModelBuilderParameters(state.PageData, state.VisualEditorMode);
                vm = await _pageViewModelBuilder.BuildPageViewModelAsync(pageParams);

                break;
            }


            // set cache
            await SetCacheAsync(vm, state);

            var result = controller.View(state.PageData.Template.FullPath, vm);

            return(result);
        }