Ejemplo n.º 1
0
        //
        // GET: /Blog/

        public ActionResult Index(string slug = "")
        {
            // get the latest blog posts
            BlogViewModel BVM = new BlogViewModel();

            BVM.Blogs = context.Blogs.OrderByDescending(a => a.Date).Take(10).ToList();

            // check if there is any blog posts. if not, redirect to the home page
            if (BVM.Blogs.Count == 0)
            {
                return(RedirectToAction("Index", "Home"));
            }

            // get a specific blog post that matches the slug
            if (!String.IsNullOrEmpty(slug))
            {
                BVM.Blog = (from s in context.Blogs.AsEnumerable()
                            where CustomHelpers.CreateSlug(s.Headline) == slug
                            select s).SingleOrDefault();
            }

            // show the last blog post if the id isn't there, or if the requested id doesn't exist
            if (BVM.Blog == null)
            {
                // redirect to the most recent blog post
                return(RedirectToAction("Index", new { slug = CustomHelpers.CreateSlug(BVM.Blogs.FirstOrDefault().Headline) }));
            }

            // return the blog post
            return(View(BVM));
        }
Ejemplo n.º 2
0
        public ActionResult Details(string slug)
        {
            var storeItem = (from s in context.StoreItems.AsEnumerable()
                             where CustomHelpers.CreateSlug(s.Title) == slug
                             select s).FirstOrDefault();

            if (storeItem == null)
            {
                TempData["ErrorMessage"] = "Item not found.";

                return(RedirectToAction("Index"));
            }

            return(View(storeItem));
        }
Ejemplo n.º 3
0
        public static string RecentBlogs(string input, IEnumerable <Blog> blogs)
        {
            string insertCode = "<div class='blog-recent'>";

            foreach (var item in blogs)
            {
                insertCode += String.Format("<a href='/blog/{0}'>{1} <span class='blog-date'>({2}/{3})</span></a><br />",
                                            CustomHelpers.CreateSlug(item.Headline), item.Headline, item.Date.Day, item.Date.Month);
            }

            insertCode += "</div>";

            // insert the code
            input = input.Replace("[widget=recentblogs]", insertCode);

            return(input);
        }
Ejemplo n.º 4
0
        public ActionResult Index(string slug, string subPageSlug)
        {
            HomeViewModel HVM = new HomeViewModel();

            // try to fetch a sub page, if there is a sub page slug supplied
            if (!String.IsNullOrEmpty(subPageSlug))
            {
                HVM.Page = (from s in context.Pages.AsEnumerable()
                            where CustomHelpers.CreateSlug(s.Title) == subPageSlug
                            select s).SingleOrDefault();
            }
            else
            {
                // no slug supplied, use the page set as home
                if (String.IsNullOrEmpty(slug))
                {
                    // get the page that is set to home
                    HVM.Page = context.Pages.SingleOrDefault(a => a.HomePage);

                    // get the image slider settings to find out if we should output an image slider
                    var imageSliderSettings = context.ImageSliderSettings.FirstOrDefault();
                    if (imageSliderSettings != null && imageSliderSettings.ImageSliderOnHomepage != 0)
                    {
                        // add the images in the viewbag
                        var imageSliderImages = context.ImageSliderImages
                                                .Where(a => a.ImageSliderId == imageSliderSettings.ImageSliderOnHomepage)
                                                .OrderBy(a => a.Order).ToList();
                        if (imageSliderImages.Count > 0)
                        {
                            ViewBag.ImageSliderImages = imageSliderImages;
                        }
                    }

                    // if the page is a special page (blog, shop etc), we need to redirect instead of returning the page
                    if (!String.IsNullOrEmpty(HVM.Page.CustomPage))
                    {
                        return(RedirectToRoute(HVM.Page.CustomPage));
                    }
                }
                else
                {
                    // try to fetch a page that matches the slug
                    HVM.Page = (from s in context.Pages.AsEnumerable()
                                where CustomHelpers.CreateSlug(s.Title) == slug
                                select s).SingleOrDefault();
                }
            }

            // if the page isn't found, display error msg and redirect to home
            if (HVM.Page == null)
            {
                TempData["ErrorMessage"] = "Page not found. The page has probably been removed, or the link was incorrect.";

                // clear the slugs and redirect to index
                return(RedirectToAction("Index", new { slug = String.Empty, subPageSlug = String.Empty }));
            }

            // populate the sub pages to show in a menu
            // show the menus both on the main page, but also on all the sub pages
            // SubPageToPageId = 0 means that it is a main page
            if (HVM.Page.SubPageToPageId == 0)
            {
                HVM.MainPageTitle = HVM.Page.Title;
                HVM.SubPages      = context.Pages.Where(a => a.ShowOnMenu && a.SubPageToPageId == HVM.Page.PageId).OrderBy(a => a.Order).ToList();
            }
            else
            {
                HVM.MainPageTitle = context.Pages.Where(a => a.PageId == HVM.Page.SubPageToPageId).FirstOrDefault().Title;
                HVM.SubPages      = context.Pages.Where(a => a.ShowOnMenu && a.SubPageToPageId == HVM.Page.SubPageToPageId).OrderBy(a => a.Order).ToList();
            }



            // return the view model
            return(View(HVM));
        }