예제 #1
0
 /// <summary>
 /// Maps data to an empty view model for a generic page.
 /// </summary>
 /// <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 Task MapPageViewModelAsync(
     IPageViewModel viewModel,
     PageViewModelBuilderParameters mappingParameters
     )
 {
     return(MapAsync(viewModel, mappingParameters));
 }
예제 #2
0
 /// <summary>
 /// Maps data to an empty view model for a generic page.
 /// </summary>
 /// <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 void MapPageViewModel(
     IPageViewModel viewModel,
     PageViewModelBuilderParameters mappingParameters
     )
 {
     Map(viewModel, mappingParameters);
 }
예제 #3
0
        /// <summary>
        /// Creates and maps data to a view model for a generic page.
        /// </summary>
        /// <param name="mappingParameters">The data passed through to map to the view model.</param>
        public virtual Task <IPageViewModel> BuildPageViewModelAsync(
            PageViewModelBuilderParameters mappingParameters
            )
        {
            var viewModel = _pageViewModelFactory.CreatePageViewModel();

            _pageViewModelMapper.MapPageViewModel(viewModel, mappingParameters);

            return(Task.FromResult(viewModel));
        }
예제 #4
0
        /// <summary>
        /// Creates and maps data to a view model for a generic page.
        /// </summary>
        /// <param name="mappingParameters">The data passed through to map to the view model.</param>
        public virtual async Task <IPageViewModel> BuildPageViewModelAsync(
            PageViewModelBuilderParameters mappingParameters
            )
        {
            var viewModel = _pageViewModelFactory.CreatePageViewModel();

            await _pageViewModelMapper.MapPageViewModelAsync(viewModel, mappingParameters);

            return(viewModel);
        }
예제 #5
0
        private void Map <T>(
            T vm,
            PageViewModelBuilderParameters mappingParameters
            )
            where T : IEditablePageViewModel, IPageRoutableViewModel
        {
            Condition.Requires(mappingParameters).IsNotNull();
            Condition.Requires(mappingParameters.PageModel).IsNotNull();

            vm.Page = mappingParameters.PageModel;
            vm.PageRoutingHelper = CreatePageRoutingHelper(mappingParameters);
            vm.IsPageEditMode    = mappingParameters.VisualEditorMode == VisualEditorMode.Edit;
        }
예제 #6
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 CustomEntityDetailsPageViewModelBuilderParameters(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
            SetCache(vm, state);

            var result = new ViewResult()
            {
                ViewData = new ViewDataDictionary(vm),
                ViewName = state.PageData.Template.FullPath
            };

            return(result);
        }
예제 #7
0
        private PageRoutingHelper CreatePageRoutingHelper(
            PageViewModelBuilderParameters mappingParameters
            )
        {
            var allRoutes      = _queryExecutor.GetAll <PageRoute>();
            var allDirectories = _queryExecutor.GetAll <WebDirectoryRoute>();
            var currentRoute   = allRoutes.Single(p => p.PageId == mappingParameters.PageModel.PageId);

            var router = new PageRoutingHelper(
                allRoutes,
                allDirectories,
                currentRoute,
                mappingParameters.VisualEditorMode,
                mappingParameters.PageModel.PageVersionId
                );

            return(router);
        }
예제 #8
0
        private async Task <PageRoutingHelper> CreatePageRoutingHelperAsync(
            PageViewModelBuilderParameters mappingParameters
            )
        {
            var allRoutes = await _queryExecutor.ExecuteAsync(new GetAllPageRoutesQuery());

            var allDirectories = await _queryExecutor.ExecuteAsync(new GetAllPageDirectoryRoutesQuery());

            var currentRoute = allRoutes.Single(p => p.PageId == mappingParameters.PageModel.PageId);

            var router = new PageRoutingHelper(
                allRoutes,
                allDirectories,
                currentRoute,
                mappingParameters.VisualEditorMode,
                mappingParameters.PageModel.PageVersionId
                );

            return(router);
        }
예제 #9
0
        private async Task MapAsync <T>(
            T vm,
            PageViewModelBuilderParameters mappingParameters
            )
            where T : IEditablePageViewModel, IPageRoutableViewModel
        {
            if (mappingParameters == null)
            {
                throw new ArgumentNullException(nameof(mappingParameters));
            }
            if (mappingParameters.PageModel == null)
            {
                throw new ArgumentNullException(nameof(mappingParameters.PageModel));
            }

            vm.Page = mappingParameters.PageModel;
            vm.PageRoutingHelper = await CreatePageRoutingHelperAsync(mappingParameters);

            vm.IsPageEditMode = mappingParameters.VisualEditorMode == VisualEditorMode.Edit;
        }