public async Task <ActionResult> AddTranslation(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var doc = await db.GetByIdAsync(id);

            if (doc == null)
            {
                return(HttpNotFound());
            }

            var translations = doc.Translations
                               .Select(dt => dt.LanguageCode)
                               .ToList();

            if (translations.Count() == LanguageDefinitions.Languages.Count)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var model = new DocumentTranslation
            {
                DocumentId = doc.Id
            };

            ViewBag.Languages =
                LanguageDefinitions.GenerateAvailableLanguageDDL(doc.Translations.Select(t => t.LanguageCode).ToList());

            return(View(model));
        }
        private void save_Click(object sender, ImageClickEventArgs e)
        {
            if (DocumentTranslation.GetTranslationFolderContentType(_nodeId) != null)
            {
                var saved = "ok";
                try
                {
                    if (!DocumentTranslation.TranslationFolderExists(_nodeId))
                    {
                        if (!DocumentTranslation.TranslationFolderCreate(_nodeId))
                        {
                            throw new Exception();
                        }
                    }

                    if (CheckBoxList1.Items.Cast <ListItem>().Where(li => li.Selected).Any(li => !DocumentTranslation.TranslationNodeCreate(_nodeId, li.Value)))
                    {
                        throw new Exception();
                    }

                    DocumentTranslation.SortTranslationNodes(_nodeId);
                }
                catch (Exception ex)
                {
                    saved = ex.Message == "NoLangProp" ? "NoLangProp" : "failed";
                }

                Response.Redirect(_queryString.BeforeUrl + "?NodeID=" + _nodeId.ToStr() + "&saved=" + saved);
            }
        }
        public async Task <ActionResult> AddTranslation(DocumentTranslation translation)
        {
            if (ModelState.IsValid)
            {
                db.AddTranslation(translation);

                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(translation));
        }
        private void CheckBoxMultiLanguageSelect_CheckedChanged(object sender, EventArgs e)
        {
            if (DocumentTranslation.GetTranslationFolderContentType(_nodeId) != null)
            {
                var s = sender as CheckBox;

                foreach (ListItem li in CheckBoxList1.Items)
                {
                    if (li.Enabled)
                    {
                        li.Selected = s.Checked ? true : false;
                    }
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            _queryString = new QueryString(Page);
            _nodeId      = _queryString["NodeID"].ToInt();
            var currentDocument = new Document(_nodeId);

            DocumentDescription.Text = currentDocument.Text;

            var status = DocumentTranslation.CheckTranslationInfrastructure(_nodeId);

            if (status == "ok")
            {
                if (!IsPostBack)
                {
                    var languagesToDisplay = Languages.GetLanguages(true);

                    var hideDefaultLanguage = ConfigurationManager.AppSettings["PolyglotHideDefaultLanguageCheckbox"];

                    if (!string.IsNullOrEmpty(hideDefaultLanguage) && hideDefaultLanguage.ToLower() == "true")
                    {
                        languagesToDisplay.Remove(
                            languagesToDisplay.Single(x => x.CultureAlias == Languages.GetDefaultCulture()));
                    }

                    CheckBoxList1.DataSource     = languagesToDisplay;
                    CheckBoxList1.DataValueField = "ISOCode";
                    CheckBoxList1.DataTextField  = "Description";
                    CheckBoxList1.DataBind();

                    foreach (ListItem li in CheckBoxList1.Items)
                    {
                        if (DocumentTranslation.TranslationNodeExists(_nodeId, li.Value))
                        {
                            li.Selected = false;
                            li.Enabled  = false;
                        }
                        else
                        {
                            if (li.Value.ToLower() != Languages.GetDefaultLanguage().ToLower())
                            {
                                li.Selected = true;
                            }
                            li.Enabled = true;
                        }
                    }
                }

                var savedParam = _queryString["saved"].ToStr();
                if (!string.IsNullOrEmpty(savedParam))
                {
                    switch (savedParam)
                    {
                    case "ok":
                    {
                        ((BasePage)HttpContext.Current.Handler).ClientTools.ShowSpeechBubble(
                            speechBubbleIcon.save, "Successful creation",
                            "Translation documents created. Please reload nodes.");
                        break;
                    }

                    case "NoLangProp":
                    {
                        ((BasePage)HttpContext.Current.Handler).ClientTools.ShowSpeechBubble(
                            speechBubbleIcon.error, "Error",
                            "Creation failed because there is no Label field with the alias 'language' in the translation document type");
                        break;
                    }

                    default:
                    {
                        ((BasePage)HttpContext.Current.Handler).ClientTools.ShowSpeechBubble(
                            speechBubbleIcon.error, "Error",
                            "There was an error creating the translation documents");
                        break;
                    }
                    }
                }
            }
            else
            {
                PropertyPanel1.Visible = false;
                PropertyPanel2.Visible = true;
                ((BasePage)HttpContext.Current.Handler).ClientTools.ShowSpeechBubble(speechBubbleIcon.warning,
                                                                                     "Infrastructure issue", status);
            }
        }