예제 #1
0
 public void SetLanguageContext(SiteTopicLanguage context)
 {
     this.ContextLanguageDetail = context;
 }
예제 #2
0
        // for each topic translation form update ajax
        public ActionResult UpdateTopicLanguage(SiteTopicLanguage model, IEnumerable <HttpPostedFileBase> FileUp)
        {
            // Note: we have to reload the form to update new ID for each translation

            // get language name
            var langs     = Cache_GetAllLanguage();
            var lang      = langs.Where(m => m.Id == model.LanguageId).FirstOrDefault();
            var lang_name = lang == null ? "Unknown language" : lang.LanguageName;

            // delete the translation
            if (model.IsDeleted)
            {
                if (model.Id > 0)
                {
                    try
                    {
                        if (model.IsDefault)
                        {
                            // before delete, try to update the default
                            Db.UpdateOnly <SiteTopicLanguage>(new SiteTopicLanguage()
                            {
                                IsDefault = false
                            }, ev => ev.Update(p => p.IsDefault).Where(m => m.TopicId == model.TopicId));
                        }
                        // delete it
                        Db.DeleteById <SiteTopicLanguage>(model.Id);
                        if (model.IsDefault)
                        {
                            // then set default
                            var x = Db.Where <SiteTopicLanguage>(m => m.TopicId == model.TopicId).FirstOrDefault();
                            if (x != null)
                            {
                                x.IsDefault = true;
                                Db.Update <SiteTopicLanguage>(x);
                            }
                        }
                    }
                    catch
                    {
                    }
                }

                if (model.Id > 0)
                {
                    return(JsonSuccess(Url.Action("Detail", new { id = model.TopicId }), "Topic translation in " + lang_name + " has been deleted"));
                }
                else
                {
                    return(JsonSuccess(Url.Action("Detail", new { id = model.TopicId })));
                }
            }

            // or update - add new

            if (string.IsNullOrEmpty(model.Title))
            {
                return(JsonError("Please enter Title in translation for topic in " + lang_name + " language"));
            }

            if (string.IsNullOrEmpty(model.Body))
            {
                return(JsonError("Please enter Body in translation for topic in " + lang_name + " language"));
            }

            if (string.IsNullOrEmpty(model.MetaKeywords))
            {
                model.MetaKeywords = "";
            }

            if (string.IsNullOrEmpty(model.MetaDescription))
            {
                model.MetaDescription = "";
            }

            if (string.IsNullOrEmpty(model.MetaTitle))
            {
                model.MetaTitle = "";
            }

            if (string.IsNullOrEmpty(model.MoreLink))
            {
                model.MoreLink = "";
            }


            if (model.Id == 0)
            {
                Db.Insert <SiteTopicLanguage>(model);
                //if is default, then set default
                if (model.IsDefault)
                {
                    var id = (int)Db.GetLastInsertId();
                    Db.UpdateOnly <SiteTopicLanguage>(new SiteTopicLanguage()
                    {
                        IsDefault = false
                    }, ev => ev.Update(p => p.IsDefault).Where(m => m.TopicId == model.TopicId));
                    Db.UpdateOnly <SiteTopicLanguage>(new SiteTopicLanguage()
                    {
                        IsDefault = true
                    }, ev => ev.Update(p => p.IsDefault).Where(m => m.Id == id));
                }
                return(JsonSuccess(Url.Action("Detail", new { id = model.TopicId }), "Translation in " + lang_name + " added"));
            }
            else
            {
                Db.Update <SiteTopicLanguage>(model);

                Db.UpdateOnly <SiteTopicLanguage>(new SiteTopicLanguage()
                {
                    IsDefault = false
                }, ev => ev.Update(p => p.IsDefault).Where(m => m.TopicId == model.TopicId));
                Db.UpdateOnly <SiteTopicLanguage>(new SiteTopicLanguage()
                {
                    IsDefault = true
                }, ev => ev.Update(p => p.IsDefault).Where(m => m.Id == model.Id));

                return(JsonSuccess("", "Translation in " + lang_name + " updated"));
            }
        }