Beispiel #1
0
        public ActionResult Index()
        {
            try
            {
                string culture  = "en-us";
                string siteName = SiteContext.CurrentSiteName;

                // Retrieves the properties as a strongly typed object
                var properties = GetProperties();

                // Get the collection of MVC Widgets
                IEnumerable <MVCWidget> mvcwidgets = MVCWidgetProvider.GetMVCWidgets()
                                                     .OnSite(siteName)
                                                     .Culture(culture)
                                                     .TopN(properties.SelectTopN)
                                                     .OrderByDescending("DocumentPublishFrom")
                                                     .TypedResult; // Ensures that the result of the query is saved, not the query itself

                // Creates a new model and sets its value
                var model = new MVCWidgetListWidgetViewModel
                {
                    HeaderText  = properties.HeaderText,
                    IntroText   = properties.IntroText,
                    MVCWidgets  = mvcwidgets,
                    ShowAllLink = properties.ShowAllLink
                };

                return(PartialView("Widgets/_MVCWidgetListWidget", model));
            }
            catch (Exception ex)
            {
                EventLogProvider.LogException("MVCWidgetListWidgetController", "ERROR", ex);
                return(null);
            }
        }
Beispiel #2
0
        // GET: MVCWidgets/Show/{guid}
        public ActionResult Show(Guid guid, string pageAlias)
        {
            // Gets the latest version of a single article using the generated provider
            MVCWidgetsPage page = MVCWidgetsPageProvider.GetMVCWidgetsPage("/mvcwidgets", "en-us", "KenticoMVCWidgetShowcase");

            // Returns a 404 error when the retrieving is unsuccessful
            if (page == null)
            {
                return(HttpNotFound());
            }

            // Initializes the page builder with the DocumentID of the page
            HttpContext.Kentico().PageBuilder().Initialize(page.DocumentID);

            var mvcwidget = MVCWidgetProvider.GetMVCWidget(guid, "en-us", "KenticoMVCWidgetShowcase");

            if (mvcwidget == null)
            {
                return(HttpNotFound());
            }

            return(View(MVCWidgetViewModel.GetViewModel(mvcwidget)));
        }