public ActionResult PageDetails(int id)
        {
            // view pageVM
            PagesVM model;

            using (Db db = new Db())
            {
                //get the page
                PageDTO dto = db.Pages.Find(id);

                //confirm page exixt
                if (dto == null)
                {
                    return(Content("page does not exist"));
                }

                //init the pageVm
                model = new PagesVM(dto);
            }
            //return view of model
            return(View(model));
        }
コード例 #2
0
        public ActionResult AddPage(PagesVM model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            using (Db db = new Db())
            {
                string  slug;
                PageDTO dto = new PageDTO();
                dto.Title = model.Title;
                if (string.IsNullOrWhiteSpace(model.Slug))
                {
                    slug = model.Title.Replace(" ", "-").ToLower();
                }
                else
                {
                    slug = model.Slug.Replace(" ", "-").ToLower();
                }
                if (db.Pages.Any(x => x.Title == model.Title) || db.Pages.Any(x => x.Slug == model.Slug))
                {
                    ModelState.AddModelError("", "That Title or Slug already exists");
                    return(View(model));
                }

                dto.Slug       = slug;
                dto.Body       = model.Body;
                dto.HasSideBar = model.HasSideBar;
                dto.Sorting    = 100;

                db.Pages.Add(dto);
                db.SaveChanges();
            }

            TempData["SM"] = "You have added a page!";
            return(RedirectToAction("AddPage"));
        }
コード例 #3
0
        // GET: Admin/pages/PageDetails/id
        public ActionResult PageDetails(int id)
        {
            //declare pagevm
            PagesVM model;

            using (Db db = new Db())
            {
                //get the page
                PageDTO dto = db.Pages.Find(id);

                //confirm page exists
                if (dto == null)
                {
                    return(Content("Page cannot be found!!!"));
                }
                //init pagevm
                model = new PagesVM(dto);
            }


            //return view with model
            return(View(model));
        }
        public ActionResult EditPage(int id)
        {
            // declare pageVm
            PagesVM model;

            using (Db db = new Db())
            {
                //Get the page
                PageDTO dto = db.Pages.Find(id);

                //confirm page exists
                if (dto == null)
                {
                    return(Content("Page does not exists"));
                }

                //Initialize the pageVm model
                model = new PagesVM(dto);
            }

            // return view with model
            return(View(model));
        }
コード例 #5
0
        // GET: Pages
        public ActionResult Index(string page = "")
        {
            if (page == "")
            {
                page = "home";
            }

            PagesVM model;
            PageDTO dto;

            using (Db db = new Db())
            {
                if (!db.Pages.Any(x => x.Slug.Equals(page)))
                {
                    return(RedirectToAction("Index", new { page = "" }));
                }
            }

            using (Db db = new Db())
            {
                dto = db.Pages.Where(x => x.Slug == page).FirstOrDefault();
            }

            ViewBag.PageTitle = dto.Title;
            if (dto.HasSidebar == true)
            {
                ViewBag.Sidebar = "Yes";
            }

            else
            {
                ViewBag.Sidebar = "No";
            }

            model = new PagesVM(dto);
            return(View(model));
        }