コード例 #1
0
        public HttpResponseMessage add(StaticPage post, Int32 languageId = 0)
        {
            // Check for errors
            if (post == null)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The post is null"));
            }
            else if (Language.MasterPostExists(languageId) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The language does not exist"));
            }

            // Make sure that the data is valid
            post.link_name        = AnnytabDataValidation.TruncateString(post.link_name, 100);
            post.title            = AnnytabDataValidation.TruncateString(post.title, 200);
            post.meta_description = AnnytabDataValidation.TruncateString(post.meta_description, 200);
            post.meta_keywords    = AnnytabDataValidation.TruncateString(post.meta_keywords, 200);
            post.meta_robots      = AnnytabDataValidation.TruncateString(post.meta_robots, 20);
            post.page_name        = AnnytabDataValidation.TruncateString(post.page_name, 100);

            // Get a static page on page name
            StaticPage staticPageOnPageName = StaticPage.GetOneByPageName(post.page_name, languageId);

            // Check if the page name exists
            if (staticPageOnPageName != null && post.id != staticPageOnPageName.id)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The page name is not unique for the language"));
            }

            // Add the post
            Int64 insertId = StaticPage.AddMasterPost(post);

            post.id = Convert.ToInt32(insertId);
            StaticPage.AddLanguagePost(post, languageId);

            // Return the success response
            return(Request.CreateResponse <string>(HttpStatusCode.OK, "The post has been added"));
        } // End of the add method
コード例 #2
0
        public ActionResult edit(FormCollection collection)
        {
            // Get the current domain
            Domain currentDomain = Tools.GetCurrentDomain();
            ViewBag.CurrentDomain = currentDomain;

            // Get all the form values
            Int32 id = Convert.ToInt32(collection["txtId"]);
            string title = collection["txtTitle"];
            string linkname = collection["txtLinkname"];
            string description = collection["txtDescription"];
            string metaDescription = collection["txtMetaDescription"];
            string metaKeywords = collection["txtMetaKeywords"];
            string pageName = collection["txtPageName"];
            string metaRobots = collection["selectMetaRobots"];
            byte connectionId = Convert.ToByte(collection["selectConnectionId"]);
            bool inactive = Convert.ToBoolean(collection["cbInactive"]);
            string keywords = collection["txtSearch"];
            Int32 currentPage = Convert.ToInt32(collection["hiddenPage"]);
            string returnUrl = collection["returnUrl"];

            // Get query parameters
            ViewBag.QueryParams = new QueryParams(returnUrl);

            // Check if the administrator is authorized
            if (Administrator.IsAuthorized(new string[] { "Administrator", "Editor" }) == true)
            {
                ViewBag.AdminSession = true;
            }
            else if (Administrator.IsAuthorized(Administrator.GetAllAdminRoles()) == true)
            {
                ViewBag.AdminSession = true;
                ViewBag.AdminErrorCode = 1;
                ViewBag.TranslatedTexts = StaticText.GetAll(currentDomain.back_end_language, "id", "ASC");
                return View("index");
            }
            else
            {
                // Redirect the user to the start page
                return RedirectToAction("index", "admin_login");
            }

            // Get the default admin language id
            Int32 adminLanguageId = currentDomain.back_end_language;

            // Get translated texts
            KeyStringList tt = StaticText.GetAll(adminLanguageId, "id", "ASC");

            // Get the static page
            StaticPage staticPage = StaticPage.GetOneById(id, adminLanguageId);

            // Check if the static page exists
            if (staticPage == null)
            {
                // Create an empty static page
                staticPage = new StaticPage();
            }

            // Update values
            staticPage.title = title;
            staticPage.link_name = linkname;
            staticPage.main_content = description;
            staticPage.meta_description = metaDescription;
            staticPage.meta_keywords = metaKeywords;
            staticPage.page_name = pageName;
            staticPage.meta_robots = metaRobots;
            staticPage.connected_to_page = connectionId;
            staticPage.inactive = inactive;

            // Check if the user wants to do a search
            if (collection["btnSearch"] != null)
            {
                // Set form values
                ViewBag.Keywords = keywords;
                ViewBag.CurrentPage = 1;
                ViewBag.StaticPage = staticPage;
                ViewBag.TranslatedTexts = tt;
                ViewBag.ReturnUrl = returnUrl;

                // Return the edit view
                return View("edit");
            }

            // Check if the user wants to do a search
            if (collection["btnPreviousPage"] != null)
            {
                // Set form values
                ViewBag.Keywords = keywords;
                ViewBag.CurrentPage = currentPage - 1;
                ViewBag.StaticPage = staticPage;
                ViewBag.TranslatedTexts = tt;
                ViewBag.ReturnUrl = returnUrl;

                // Return the edit view
                return View("edit");
            }

            // Check if the user wants to do a search
            if (collection["btnNextPage"] != null)
            {
                // Set form values
                ViewBag.Keywords = keywords;
                ViewBag.CurrentPage = currentPage + 1;
                ViewBag.StaticPage = staticPage;
                ViewBag.TranslatedTexts = tt;
                ViewBag.ReturnUrl = returnUrl;

                // Return the edit view
                return View("edit");
            }

            // Create a error message
            string errorMessage = string.Empty;

            // Get a static page on page name
            StaticPage pageOnPageName = StaticPage.GetOneByPageName(staticPage.page_name, adminLanguageId);

            // Check for errors
            if (pageOnPageName != null && staticPage.id != pageOnPageName.id)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_language_unique"), tt.Get("page_name")) + "<br/>";
            }
            if (staticPage.page_name == string.Empty)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_required"), tt.Get("page_name")) + "<br/>";
            }
            if (AnnytabDataValidation.CheckPageNameCharacters(staticPage.page_name) == false)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_bad_chars"), tt.Get("page_name")) + "<br/>";
            }
            if (staticPage.page_name.Length > 100)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_length"), tt.Get("page_name"), "100") + "<br/>";
            }
            if (staticPage.title.Length > 200)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_length"), tt.Get("title"), "200") + "<br/>";
            }
            if (staticPage.link_name.Length > 100)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_length"), tt.Get("link_name"), "100") + "<br/>";
            }
            if (staticPage.meta_description.Length > 200)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_length"), tt.Get("meta_description"), "200") + "<br/>";
            }
            if (staticPage.meta_keywords.Length > 200)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_length"), tt.Get("keywords"), "200") + "<br/>";
            }

            // Check if there is errors
            if (errorMessage == string.Empty)
            {
                // Check if we should add or update the static page
                if (staticPage.id == 0)
                {
                    // Add the static page
                    Int64 insertId = StaticPage.AddMasterPost(staticPage);
                    staticPage.id = Convert.ToInt32(insertId);
                    StaticPage.AddLanguagePost(staticPage, adminLanguageId);
                }
                else
                {
                    // Update the static page
                    StaticPage.UpdateMasterPost(staticPage);
                    StaticPage.UpdateLanguagePost(staticPage, adminLanguageId);
                }

                // Redirect the user to the list
                return Redirect(returnUrl);
            }
            else
            {
                // Set form values
                ViewBag.Keywords = keywords;
                ViewBag.CurrentPage = currentPage;
                ViewBag.ErrorMessage = errorMessage;
                ViewBag.StaticPage = staticPage;
                ViewBag.TranslatedTexts = tt;
                ViewBag.ReturnUrl = returnUrl;

                // Return the edit view
                return View("edit");
            }

        } // End of the edit method