Beispiel #1
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");
        }
 partial void Updatepage(page instance);
 partial void Deletepage(page instance);
 partial void Insertpage(page instance);