Пример #1
0
        public MediatorResponse <RecommendedPagesViewModel> CreateRecommendedPagesViewModel()
        {
            var dataSource = _recommendedService.GetRecommendedPages();

            if (dataSource == null)
            {
                return(_mediatorService.GetMediatorResponse <RecommendedPagesViewModel>(Constants.MediatorCodes.RecommendedPagesResponse.DataSourceError, message: Constants.Logging.Error.DataSourceError));
            }

            var renderingParameters = _recommendedService.GetRecommendedPagesRenderingParameters();

            if (renderingParameters == null)
            {
                return(_mediatorService.GetMediatorResponse <RecommendedPagesViewModel>(Constants.MediatorCodes.RecommendedPagesResponse.RenderingParamError, message: Constants.Logging.Error.RenderingParametersError));
            }

            var viewModel = new RecommendedPagesViewModel
            {
                Title = new HtmlString(_glassHtml.Editable(dataSource, i => i.Title, new { EnclosingTag = "h1" })),
                Cards = dataSource.Cards != null && dataSource.Cards.Any()
                    ? dataSource.Cards.Select(MapRecommendedItemToRecommendedCardViewModel).ToList()
                    : new List <RecommendedCardViewModel>(),
                CssClass = renderingParameters.DisplayType?.CssClass,

                IsExperienceEditor = _recommendedService.IsExperienceEditor
            };

            return(_mediatorService.GetMediatorResponse(Constants.MediatorCodes.RecommendedPagesResponse.Ok, viewModel));
        }
Пример #2
0
        /// <summary>
        ///     Mediator pattern is overkill in this instance, but here as an example to return response codes to a controller, and
        ///     keep the controller dumb as a result
        /// </summary>
        /// <returns>A mediator response with the result of the view model instantiation</returns>
        public MediatorResponse <NavViewModel> RequestNavViewModel()
        {
            var NavItemDataSource = _NavService.GetNavItems();

            if (NavItemDataSource == null)
            {
                return(_mediatorService.GetMediatorResponse <NavViewModel>(MediatorCodes.NavResponse.DataSourceError));
            }
            var viewModel =
                _NavViewModelFactory.CreateNavViewModel(NavItemDataSource, _NavService.IsExperienceEditor);

            if (viewModel == null)
            {
                return(_mediatorService.GetMediatorResponse <NavViewModel>(MediatorCodes.NavResponse.ViewModelError));
            }
            return(_mediatorService.GetMediatorResponse(MediatorCodes.NavResponse.Ok, viewModel));
        }
Пример #3
0
        /// <summary>
        ///     Mediator pattern is overkill in this instance, but here as an example to return response codes to a controller, and
        ///     keep the controller dumb as a result
        /// </summary>
        /// <returns>A mediator response with the result of the view model instantiation</returns>
        public MediatorResponse <HeaderViewModel> RequestHeaderViewModel()
        {
            var HeaderItemDataSource = _HeaderService.GetHeaderItems();

            if (HeaderItemDataSource == null)
            {
                return(_mediatorService.GetMediatorResponse <HeaderViewModel>(MediatorCodes.HeaderResponse.DataSourceError));
            }
            var viewModel =
                _HeaderViewModelFactory.CreateHeaderViewModel(HeaderItemDataSource, _HeaderService.IsExperienceEditor);

            if (viewModel == null)
            {
                return(_mediatorService.GetMediatorResponse <HeaderViewModel>(MediatorCodes.HeaderResponse.ViewModelError));
            }
            return(_mediatorService.GetMediatorResponse(MediatorCodes.HeaderResponse.Ok, viewModel));
        }
        /// <summary>
        ///     Mediator pattern is overkill in this instance, but here as an example to return response codes to a controller, and
        ///     keep the controller dumb as a result
        /// </summary>
        /// <returns>A mediator response with the result of the view model instantiation</returns>
        public MediatorResponse <HackViewModel> RequestHackViewModel()
        {
            var hackItemDataSource = _hackService.GetHackItems();

            if (hackItemDataSource == null)
            {
                return(_mediatorService.GetMediatorResponse <HackViewModel>(MediatorCodes.HackResponse.DataSourceError));
            }

            var viewModel =
                _hackViewModelFactory.CreateHeroViewModel(hackItemDataSource, _hackService.IsExperienceEditor);

            if (viewModel == null)
            {
                return(_mediatorService.GetMediatorResponse <HackViewModel>(MediatorCodes.HackResponse.ViewModelError));
            }

            return(_mediatorService.GetMediatorResponse(MediatorCodes.HackResponse.Ok, viewModel));
        }
Пример #5
0
        public MediatorResponse <HeroViewModel> CreateHeroViewModel()
        {
            var heroItemDataSource = _heroService.GetHeroItems();

            if (heroItemDataSource == null)
            {
                return(_mediatorService.GetMediatorResponse <HeroViewModel>(MediatorCodes.HeroResponse.DataSourceError));
            }

            var viewModel = new HeroViewModel
            {
                HeroImages = heroItemDataSource.HeroImages,
                HeroTitle  = new HtmlString(_glassHtml.Editable(heroItemDataSource, i => i.HeroTitle,
                                                                new { EnclosingTag = "h2" })),
                IsExperienceEditor = _heroService.IsExperienceEditor
            };

            return(_mediatorService.GetMediatorResponse(MediatorCodes.HeroResponse.Ok, viewModel));
        }
        /// <summary>
        ///     Mediator pattern is overkill in this instance, but here as an example to return response codes to a controller, and
        ///     keep the controller dumb as a result
        /// </summary>
        /// <returns>A mediator response with the result of the view model instantiation</returns>
        public MediatorResponse <PackagesViewModel> RequestPackageViewModel(string query)
        {
            var packageItemDataSource = _packageService.GetPackagesSearch(query);

            if (packageItemDataSource == null && !packageItemDataSource.Any())
            {
                return(_mediatorService.GetMediatorResponse <PackagesViewModel>(Constants.MediatorCodes.PackageSearchResponse.DataSourceError));
            }

            var viewModel =
                _packageViewModelFactory.CreatePackageViewModel(packageItemDataSource, _packageService.IsExperienceEditor);

            if (viewModel == null)
            {
                return(_mediatorService.GetMediatorResponse <PackagesViewModel>(Constants.MediatorCodes.PackageSearchResponse.ViewModelError));
            }

            return(_mediatorService.GetMediatorResponse(Constants.MediatorCodes.PackageSearchResponse.Ok, viewModel));
        }