public void ActionAdd(SysResourceModel model) { if (model.RecordID > 0) { entity = WebResourceService.Instance.GetByID(model.RecordID); // khoi tao gia tri mac dinh khi update } else { entity = new WebResourceEntity(); // khoi tao gia tri mac dinh khi insert entity.LangID = model.LangID; } ViewBag.Data = entity; ViewBag.Model = model; }
public void ActionAdd(SysResourceModel model) { if (model.RecordID > 0) { entity = WebResourceService.Instance.GetByID(model.RecordID); // khoi tao gia tri mac dinh khi update } else { entity = new WebResourceEntity(); // khoi tao gia tri mac dinh khi insert entity.LangID = model.LangID; } ViewBag.Data = entity; ViewBag.Model = model; }
public static string GetValue(string code, string defalt) { SysLangEntity _Lang = SysLangService.Instance.CreateQuery() .Where(o => o.Code == CurrentCode) .ToSingle_Cache(); if (_Lang == null) { return(defalt); } WebResourceEntity _Resource = WebResourceService.Instance.GetByCode_Cache(code, _Lang.ID); if (_Resource != null) { return(_Resource.Value); } IniResourceService _IniResourceService = new IniResourceService(HttpContext.Current.Server.MapPath("~/Views/Lang/" + _Lang.Code + ".ini")); return(_IniResourceService.HL_Core_GetByCode(code, defalt)); }
private bool ValidSave(SysResourceModel model) { if (!string.IsNullOrEmpty(model.Resource)) { var ArrItem = model.Resource.Split('\n'); foreach (var t in ArrItem) { if (string.IsNullOrEmpty(t.Trim()) || t.StartsWith("//")) { continue; } var index = t.IndexOf('='); if (index < 0) { continue; } var key = t.Substring(0, index).Trim(); var value = t.Substring(index + 1).Trim(); _item = WebResourceService.Instance.CreateQuery() .Where(o => o.LangID == model.LangID && o.Code == key) .ToSingle(); if (_item == null) { _item = new WebResourceEntity { ID = 0, LangID = model.LangID, Code = key } } ; _item.Value = value; WebResourceService.Instance.Save(_item); } return(true); } else { TryUpdateModel(_item); ViewBag.Data = _item; ViewBag.Model = model; CPViewPage.Message.MessageType = Message.MessageTypeEnum.Error; //kiem tra ma if (_item.Code.Trim() == string.Empty) { CPViewPage.Message.ListMessage.Add("Nhập mã."); } //kiem tra ton tai if (model.RecordID < 1 && WebResourceService.Instance.CP_HasExists(_item.Code, _item.LangID)) { CPViewPage.Message.ListMessage.Add("Mã đã tồn tại."); } if (CPViewPage.Message.ListMessage.Count != 0) { return(false); } try { //save WebResourceService.Instance.Save(_item); } catch (Exception ex) { Error.Write(ex); CPViewPage.Message.ListMessage.Add(ex.Message); return(false); } return(true); } }