Пример #1
0
        public HttpResponseMessage add(Language 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 && languageId != 0)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The translation language does not exist"));
            }

            // Make sure that the data is valid
            post.name          = AnnytabDataValidation.TruncateString(post.name, 50);
            post.language_code = AnnytabDataValidation.TruncateString(post.language_code, 2);
            post.country_code  = AnnytabDataValidation.TruncateString(post.country_code, 2);

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

            post.id = Convert.ToInt32(insertId);

            // Set the translation language to the same as the language
            if (languageId == 0)
            {
                languageId = post.id;
            }

            // Add the language post
            Language.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 HttpResponseMessage translate(Language 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 translation language does not exist"));
            }
            else if (Language.MasterPostExists(post.id) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The language does not exist"));
            }

            // Make sure that the data is valid
            post.name          = AnnytabDataValidation.TruncateString(post.name, 50);
            post.language_code = AnnytabDataValidation.TruncateString(post.language_code, 2);
            post.country_code  = AnnytabDataValidation.TruncateString(post.country_code, 2);

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

            // Check if we should add or update the post
            if (savedPost == null)
            {
                Language.AddLanguagePost(post, languageId);
            }
            else
            {
                Language.UpdateLanguagePost(post, languageId);
            }

            // Return the success response
            return(Request.CreateResponse <string>(HttpStatusCode.OK, "The translate was successful"));
        } // End of the translate method
Пример #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"]);
            Int32 id = Convert.ToInt32(collection["hiddenLanguageId"]);
            string name = collection["txtTranslatedName"];

            // Create the translated language
            Language translatedLanguage = new Language();
            translatedLanguage.id = id;
            translatedLanguage.name = name;

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

            // Check for errors in the language
            if (translatedLanguage.name.Length > 50)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_length"), tt.Get("name"), "50") + "<br/>";
            }

            // Check if there is errors
            if (errorMessage == string.Empty)
            {
                // Get the language
                Language language = Language.GetOneById(id, translationLanguageId);

                if (language == null)
                {
                    // Add a new translated language
                    Language.AddLanguagePost(translatedLanguage, translationLanguageId);
                }
                else
                {
                    // Update the translated language
                    language.name = translatedLanguage.name;
                    Language.UpdateLanguagePost(language, translationLanguageId);

                }

                // Redirect the user to the list
                return Redirect("/admin_languages" + returnUrl);
            }
            else
            {
                // Set form values
                ViewBag.LanguageId = translationLanguageId;
                ViewBag.Languages = Language.GetAll(adminLanguageId, "name", "ASC");
                ViewBag.StandardLanguage = Language.GetOneById(id, adminLanguageId);
                ViewBag.TranslatedLanguage = translatedLanguage;
                ViewBag.ErrorMessage = errorMessage;
                ViewBag.TranslatedTexts = tt;
                ViewBag.ReturnUrl = returnUrl;

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

        } // End of the translate method
Пример #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 all the form values
            Int32 languageId = Convert.ToInt32(collection["txtId"]);
            string name = collection["txtName"];
            string languageCode = collection["txtLanguageCode"];
            string countryCode = collection["txtCountryCode"];
            
            // Get the default admin language id
            Int32 adminLanguageId = currentDomain.back_end_language;

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

            // Get the language
            Language language = Language.GetOneById(languageId, adminLanguageId);
            bool postExists = true;

            // Check if the language exists
            if (language == null)
            {
                // Create an empty language post
                language = new Language();
                language.id = languageId;
                postExists = false;
            }

            // Update values for the language
            language.name = name;
            language.language_code = languageCode;
            language.country_code = countryCode;
            
            // Create a error message
            string errorMessage = string.Empty;

            // Check for errors in the language
            if (language.name.Length > 50)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_length"), tt.Get("name"), "50") + "<br/>";
            }
            if (language.language_code.Length > 2)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_length"), tt.Get("language_code"), "2") + "<br/>";
            }
            if (language.country_code.Length > 2)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_length"), tt.Get("country_code"), "2") + "<br/>";
            }
            
            // Check if there is errors
            if (errorMessage == string.Empty)
            {
                // Check if we should add or update the language
                if (postExists == false)
                {
                    // Add the language
                    long insertId = Language.AddMasterPost(language);
                    language.id = Convert.ToInt32(insertId);
                    Language.AddLanguagePost(language, adminLanguageId);
                }
                else
                {
                    // Update the language
                    Language.UpdateMasterPost(language);
                    Language.UpdateLanguagePost(language, adminLanguageId);
                }

                // Redirect the user to the list
                return Redirect("/admin_languages" + returnUrl);
            }
            else
            {
                // Set form values
                ViewBag.ErrorMessage = errorMessage;
                ViewBag.Language = language;
                ViewBag.TranslatedTexts = tt;
                ViewBag.ReturnUrl = returnUrl;

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

        } // End of the edit method