public HttpResponseMessage add(Country 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.country_code = AnnytabDataValidation.TruncateString(post.country_code, 2);
            post.name         = AnnytabDataValidation.TruncateString(post.name, 50);

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

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

            // Return the success response
            return(Request.CreateResponse <string>(HttpStatusCode.OK, "The post has been added"));
        } // End of the add method
        public HttpResponseMessage translate(Country 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"));
            }
            else if (Country.MasterPostExists(post.id) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The country does not exist"));
            }

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

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

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

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

            // Get the return url
            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["hiddenCountryId"]);
            string name = collection["txtTranslatedName"];

            // Create the translated Country
            Country translatedCountry = new Country();
            translatedCountry.id = id;
            translatedCountry.name = name;

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

            // Check the translated country name
            if (translatedCountry.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 saved country
                Country country = Country.GetOneById(id, translationLanguageId);

                if (country == null)
                {
                    // Add a new translated country
                    Country.AddLanguagePost(translatedCountry, translationLanguageId);
                }
                else
                {
                    // Update the translated country
                    country.name = translatedCountry.name;
                    Country.UpdateLanguagePost(country, translationLanguageId);
                }

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

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

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

            // Get the return url
            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 id = Convert.ToInt32(collection["txtId"]);
            string name = collection["txtName"];
            string countryCode = collection["txtCountryCode"];
            byte vatCode = Convert.ToByte(collection["selectVatCode"]);

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

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

            // Get the country
            Country country = Country.GetOneById(id, adminLanguageId);

            // Check if the country exists (haha)
            if (country == null)
            {
                // Create a empty country
                country = new Country();
            }
            
            // Update values
            country.name = name;
            country.country_code = countryCode;
            country.vat_code = vatCode;

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

            // Check for errors in the country
            if (country.name.Length > 50)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_length"), tt.Get("name"), "50") + "<br/>";
            }
            if (country.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 country
                if (country.id == 0)
                {
                    // Add the country
                    Int64 insertId = Country.AddMasterPost(country);
                    country.id = Convert.ToInt32(insertId);
                    Country.AddLanguagePost(country, adminLanguageId);
                }
                else
                {
                    // Update the country
                    Country.UpdateMasterPost(country);
                    Country.UpdateLanguagePost(country, adminLanguageId);
                }

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

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

        } // End of the edit method