Exemplo n.º 1
0
        public ActionResult addtemplate()
        {
            Admin admin = new Admin();
            ViewData["parentPages"] = admin.getParentPages(0);
            ViewData["isPublished"] = false;

            return View();
        }
Exemplo n.º 2
0
        public ActionResult addtemplate(string pageTitle, int? parentPageID, bool? isPublished, string pageContent)
        {
            if (string.IsNullOrEmpty(pageContent))
            {
                ModelState.AddModelError("page_text", "Text cannot be empty");
            }
            if (string.IsNullOrEmpty(pageTitle))
            {
                ModelState.AddModelError("page_title", "Title cannot be empty");
            }
            if (!ModelState.IsValid)
            {
                Admin admin = new Admin();
                ViewData["parentPages"] = admin.getParentPages((int)parentPageID);
                ViewData["isPublished"] = false;
                ViewData["page_title"] = pageTitle;
                ViewData["page_text"] = pageContent;
                ViewData["isPublished"] = isPublished;
                return View();
            }

            var parentPage = db.pages.Single(d => d.pageID == (int)parentPageID);

            string pageURL = parentPage.pageURL + createPageURL(pageTitle) + "/";

            page pageToAdd = new page
            {
                lastUpdate = DateTime.Now,
                parent = (int)parentPageID,
                isPublished = (bool)isPublished,
                isContent = true,
                isStatic = false,
                pageContent = pageContent,
                pageTitle = pageTitle,
                pageURL = pageURL,
                author = (Guid) Membership.GetUser().ProviderUserKey
            };

            db.pages.InsertOnSubmit(pageToAdd);
            db.SubmitChanges();

            return RedirectToAction("Index");
        }
Exemplo n.º 3
0
        public ActionResult EditTemplate(int id, Models.AdminPageModel pagetoedit)
        {
            var pageoriginal = (from p in db.pages where p.pageID == id select p).First();
            Admin admin = new Admin();
            ViewData["parentPages"] = admin.getParentPages((int)pageoriginal.parent);

            if (string.IsNullOrEmpty(pagetoedit.page.pageContent))
            {
                ModelState.AddModelError("page_text", "Text cannot be empty");
            }
            if (string.IsNullOrEmpty(pagetoedit.page.pageTitle))
            {
                ModelState.AddModelError("page_title", "Title cannot be empty");
            }
            if (pageoriginal.pageTitle.Length < pageoriginal.pageTitle.Length)
            {
                ModelState.AddModelError("press_link", "Your link cannot be longer than " + pageoriginal.pageTitle.Length + " characters. Currently it is " + pagetoedit.page.pageTitle.Length);
            }
            if (!ModelState.IsValid)
            {
                return View(pagetoedit);
            }

            var parentPage = db.pages.Single(d => d.pageID == (int)pagetoedit.parentPageID);

            string pageURL = parentPage.pageURL + createPageURL(pagetoedit.page.pageTitle) + "/";

            var cachedPages = from p in db.pages
                              where p.pageURL == pageoriginal.pageURL && p.isPublished == false
                              orderby p.lastUpdate descending
                              select p;
            foreach (var cachedPage in cachedPages)
            {
                cachedPage.pageURL = pageURL;
            }

            var user = Membership.GetUser();

            var pagetocache = new Models.page();
            pagetocache.lastUpdate = pageoriginal.lastUpdate;
            pagetocache.pageContent = pageoriginal.pageContent;
            pagetocache.pageTitle = pageoriginal.pageTitle;
            pagetocache.pageURL = pageURL;
            pagetocache.isPublished = false;
            pagetocache.pageOrder = pageoriginal.pageOrder;
            pagetocache.parent = (int)pagetoedit.parentPageID;
            pagetocache.author = pageoriginal.author;

            db.pages.InsertOnSubmit(pagetocache);

            pageoriginal.pageTitle = pagetoedit.page.pageTitle;
            pageoriginal.pageContent = pagetoedit.page.pageContent;
            pageoriginal.pageURL = pageURL;
            pageoriginal.isPublished = (bool)pagetoedit.isPublished;
            pageoriginal.parent = (int)pagetoedit.parentPageID;
            pageoriginal.pageOrder = pagetoedit.page.pageOrder;
            pageoriginal.lastUpdate = DateTime.Now;
            pageoriginal.author = (Guid) user.ProviderUserKey;

            db.SubmitChanges();

            return RedirectToAction("Index");
        }
Exemplo n.º 4
0
        public ActionResult EditTemplate(int id)
        {
            AdminPageModel pagewithcache = new AdminPageModel();
            pagewithcache.page = db.pages.Single(d => d.pageID == id);
            pagewithcache.pages = from p in db.pages
                                  where p.pageURL == pagewithcache.page.pageURL && p.isPublished == false
                                  orderby p.lastUpdate descending
                                  select p;

            int parentPageID = (from ppu in db.pages where ppu.pageID == pagewithcache.page.parent select ppu.pageID).FirstOrDefault();

            Admin admin = new Admin();
            ViewData["parentPages"] = admin.getParentPages(parentPageID);

            return View(pagewithcache);
        }