Example #1
0
        public HttpResponseMessage add(StaticText 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.id    = AnnytabDataValidation.TruncateString(post.id, 100);
            post.value = AnnytabDataValidation.TruncateString(post.value, 200);

            // Check if the id exists
            if (StaticText.MasterPostExists(post.id) == true)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The id already exists"));
            }

            // Make sure that the id contains valid characters
            if (AnnytabDataValidation.CheckPageNameCharacters(post.id) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The id contains characters that not are allowed"));
            }

            // Add the post
            StaticText.Add(post, languageId);

            // Return the success response
            return(Request.CreateResponse <string>(HttpStatusCode.OK, "The post has been added"));
        } // End of the add method
Example #2
0
        public HttpResponseMessage translate(StaticText 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.id    = AnnytabDataValidation.TruncateString(post.id, 100);
            post.value = AnnytabDataValidation.TruncateString(post.value, 200);

            // Make sure that the id contains valid characters
            if (AnnytabDataValidation.CheckPageNameCharacters(post.id) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The id contains characters that not are allowed"));
            }

            // Get the saved post
            StaticText savedPost = StaticText.GetOneById(post.id, languageId);

            // Check if the post exists
            if (savedPost == null)
            {
                StaticText.Add(post, languageId);
            }
            else
            {
                StaticText.Update(post, languageId);
            }

            // Return the success response
            return(Request.CreateResponse <string>(HttpStatusCode.OK, "The translate was successful"));
        } // End of the translate method
Example #3
0
        public ActionResult translate(FormCollection collection)
        {
            // Get the current domain
            Domain currentDomain = Tools.GetCurrentDomain();
            ViewBag.CurrentDomain = currentDomain;

            // Get query parameters
            string returnUrl = collection["returnUrl"];
            ViewBag.QueryParams = new QueryParams(returnUrl);

            // Check if the administrator is authorized
            if (Administrator.IsAuthorized(new string[] { "Administrator", "Editor", "Translator" }) == 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 admin default language
            Int32 adminLanguageId = currentDomain.back_end_language;

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

            // Get all the form values
            Int32 translationLanguageId = Convert.ToInt32(collection["selectLanguage"]);
            string staticTextId = collection["hiddenStaticTextId"];
            string staticTextText = collection["txtTranslatedText"];

            // Create the translated static text
            StaticText translatedStaticText = new StaticText();
            translatedStaticText.id = staticTextId;
            translatedStaticText.value = staticTextText;

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

            // Check for errors in the static text
            if (translatedStaticText.value.Length > 200)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_length"), tt.Get("text"), "200") + "<br/>";
            }

            // Check if there is errors
            if (errorMessage == string.Empty)
            {
                // Get the static text
                StaticText staticText = StaticText.GetOneById(staticTextId, translationLanguageId);

                if (staticText == null)
                {
                    // Add a new translated static text
                    StaticText.Add(translatedStaticText, translationLanguageId);
                }
                else
                {
                    // Update the translated static text
                    staticText.value = translatedStaticText.value;
                    StaticText.Update(staticText, translationLanguageId);
                }

                // Redirect the user to the list
                return Redirect(returnUrl);
            }
            else
            {
                // Set form values
                ViewBag.LanguageId = translationLanguageId;
                ViewBag.Languages = Language.GetAll(adminLanguageId, "name", "ASC");
                ViewBag.StandardStaticText = StaticText.GetOneById(staticTextId, adminLanguageId);
                ViewBag.TranslatedStaticText = translatedStaticText;
                ViewBag.ErrorMessage = errorMessage;
                ViewBag.TranslatedTexts = tt;
                ViewBag.ReturnUrl = returnUrl;

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

        } // End of the translate method
Example #4
0
        public ActionResult edit(FormCollection collection)
        {
            // Get the current domain
            Domain currentDomain = Tools.GetCurrentDomain();
            ViewBag.CurrentDomain = currentDomain;

            // Get query parameters
            string returnUrl = collection["returnUrl"];
            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 all the form values
            string staticTextId = collection["txtId"];
            string staticTextText = collection["txtText"];

            // Get the static text
            StaticText staticText = StaticText.GetOneById(staticTextId, adminLanguageId);
            bool postExists = true;

            // Check if the static text exists
            if (staticText == null)
            {
                // Create an empty static text
                staticText = new StaticText();
                staticText.id = staticTextId;
                postExists = false;
            }

            // Update values
            staticText.value = staticTextText;

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

            // Check for errors in the static text
            if (AnnytabDataValidation.CheckPageNameCharacters(staticText.id) == false)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_bad_chars"), tt.Get("id")) + "<br/>";
            }
            if (staticText.id.Length == 0 || staticText.id.Length > 100)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_certain_length"), tt.Get("id"), "1", "100") + "<br/>";
            }
            if (staticText.value.Length > 200)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_length"), tt.Get("text"), "200") + "<br/>";
            }

            // Check if there is errors
            if (errorMessage == string.Empty)
            {
                // Check if we should add or update the static text
                if (postExists == false)
                {
                    // Add the static text
                    StaticText.Add(staticText, adminLanguageId);
                }
                else
                {
                    // Update the static text
                    StaticText.Update(staticText, adminLanguageId);
                }

                // Redirect the user to the list
                return Redirect(returnUrl);
            }
            else
            {
                // Set form values
                ViewBag.ErrorMessage = errorMessage;
                ViewBag.StaticText = staticText;
                ViewBag.TranslatedTexts = tt;
                ViewBag.ReturnUrl = returnUrl;

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

        } // End of the edit method