/// <summary> /// Retorna a tradução de um texto. /// </summary> /// <param name="text">Texto.</param> /// <param name="language">Nome do idioma.</param> /// <returns>Texto traduzido.</returns> public static string GetText(string text, string language = null) { language = language ?? Default?.Language ?? string.Empty; return(Translates.ContainsKey(language) && Translates[language].ContainsKey(text) ? Translates[language][text] : text); }
public ActionResult GetContent(Translates item) { using (AbcUEMDbEntities db = new AbcUEMDbEntities()) { return(Json(db.Translates.Where(x => x.Id == item.Id).FirstOrDefault(), JsonRequestBehavior.AllowGet)); } }
protected virtual IActionResult DeleteAction() { this.RequireAjaxRequest(); var json = Request.Get <string>("json"); var original = JsonConvert.DeserializeObject <IList <string> >(json).FirstOrDefault(); if (!string.IsNullOrEmpty(original)) { Translates.Remove(original); } Translates = Translates; return(new JsonResult(new { message = new T("Delete Successful") })); }
public ActionResult DeleteContent(Translates item) { using (AbcUEMDbEntities db = new AbcUEMDbEntities()) { bool res = true; try { db.Translates.Remove(db.Translates.Find(item.Id)); db.SaveChanges(); } catch { res = false; } return(Json(res, JsonRequestBehavior.AllowGet)); } }
public ActionResult AddContent(Translates item) { bool res = true; try { using (AbcUEMDbEntities db = new AbcUEMDbEntities()) { db.Translates.Add(item); db.SaveChanges(); } } catch { res = false; } return(Json(res, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 删除翻译内容 /// </summary> /// <returns></returns> protected virtual IActionResult DeleteAction() { // 检查权限 HttpRequestChecker.RequieAjaxRequest(); var privilegeManager = Application.Ioc.Resolve <PrivilegeManager>(); privilegeManager.Check(AllowedUserTypes, RequiredPrivileges); // 获取参数并执行删除 var json = HttpManager.CurrentContext.Request.Get <string>("json"); var original = JsonConvert.DeserializeObject <IList <string> >(json).FirstOrDefault(); if (!string.IsNullOrEmpty(original)) { Translates.Remove(original); } Translates = Translates; return(new JsonResult(new { message = new T("Delete Successful") })); }
public ActionResult UpdateContent(Translates item) { bool res = true; try { using (AbcUEMDbEntities db = new AbcUEMDbEntities()) { var obj = db.Translates.Find(item.Id); db.Entry(obj).CurrentValues.SetValues(item); db.SaveChanges(); } } catch { res = false; } return(Json(res, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 搜索请求的处理函数 /// </summary> /// <returns></returns> protected override IActionResult SearchAction() { // 检查权限 var privilegeManager = Application.Ioc.Resolve <PrivilegeManager>(); privilegeManager.Check(AllowedUserTypes, RequiredPrivileges); // 获取参数并转换到搜索请求 var json = HttpManager.CurrentContext.Request.Get <string>("json"); var request = AjaxTableSearchRequest.FromJson(json); // 构建搜索回应 var query = Translates.Select(t => new Translation() { Original = t.Key, Translated = t.Value }); if (!string.IsNullOrEmpty(request.Keyword)) { query = query.Where(q => q.Original.Contains(request.Keyword) || q.Translated.Contains(request.Keyword)); } var response = new AjaxTableSearchResponse(); var result = response.Pagination.Paging(request, query.AsQueryable()); response.PageNo = request.PageNo; response.PageSize = request.PageSize; response.Rows.AddRange(result.Select(translation => new Dictionary <string, object>() { { "Id", HttpUtils.UrlEncode(translation.Original) }, { "OriginalText", translation.Original }, { "TranslatedText", translation.Translated }, { "ToString", translation.ToString() } })); response.Columns.AddNoColumn(); response.Columns.AddMemberColumn("OriginalText"); response.Columns.AddMemberColumn("TranslatedText"); var actionColumn = response.Columns.AddActionColumn("130"); actionColumn.AddEditAction("Translation", EditUrl, dialogParameters: new { size = "size-wide" }); actionColumn.AddDeleteAction("Translation", DeleteUrl); return(new JsonResult(response)); }
/// <summary> /// 搜索请求的处理函数 /// </summary> /// <returns></returns> protected override IActionResult SearchAction() { var json = Request.Get <string>("json"); var request = AjaxTableSearchRequest.FromJson(json); var query = Translates.Select(t => new CustomTranslation() { Id = t.Key, Translated = t.Value }); if (!string.IsNullOrEmpty(request.Keyword)) { query = query.Where(q => q.Id.Contains(request.Keyword) || q.Translated.Contains(request.Keyword)); } var response = new AjaxTableSearchResponse(); var result = response.Pagination.Paging(request, query.AsQueryable()); response.PageNo = request.PageNo; response.PageSize = request.PageSize; response.Rows.AddRange(result.Select(translation => new Dictionary <string, object>() { { "Id", HttpUtils.UrlEncode(translation.Id) }, { "OriginalText", translation.Id }, { "TranslatedText", translation.Translated }, { "ToString", translation.ToString() } })); response.Columns.AddNoColumn(); response.Columns.AddMemberColumn("OriginalText"); response.Columns.AddMemberColumn("TranslatedText"); var actionColumn = response.Columns.AddActionColumn("130"); actionColumn.AddEditAction("Translation", EditUrl, dialogParameters: new { size = "size-wide" }); actionColumn.AddDeleteAction("Translation", DeleteUrl); return(new JsonResult(response)); }
/// <summary> /// 翻译文本 /// </summary> public virtual string Translate(string text) { return(Translates.GetOrDefault(text)); }