public static SystemConfig GetSystemConfig(SystemConfigType systemConfigType) { using (var db = new CallerContext()) { return(db.SystemConfigs.Where(x => x.Code == (int)systemConfigType).FirstOrDefault()); } }
public ActionResult Edit(string configTypeCode, string configCode, FormCollection collection) { SystemConfigValue data = null; try { // 配置类型. SystemConfigType sct = this.systemConfigService.GetSystemConfigType(configTypeCode); ViewBag.SystemConfigType = sct; // 配置属性 List <SystemConfigProperty> scp = this.systemConfigService.GetSystemConfigPropertyByType(configTypeCode); ViewBag.SystemConfigPropertys = scp; // 数据. data = this.systemConfigService.GetSystemConfigValue(configTypeCode, configCode); if (data == null) { return(HttpNotFound()); } if (data.SystemConfigTypeData.ConfigClassName == SystemConfigType.SimpleDictionary) { Dictionary <string, Object> configObj = new Dictionary <string, object>(); foreach (var prop in scp) { String value = collection[prop.PropertyName]; configObj.Add(prop.PropertyName, BasicDataConvert(prop.PropertyDataType, value)); } data.ConfigValueObject = configObj; } else { data.ConfigValueObject = BasicDataConvert(sct.ConfigClassName, collection["ConfigValue"]); } string resultMsg = null; bool result = this.systemConfigService.UpdateSystemConfigValue(data, ref resultMsg); if (!result) { return(View(model: data)); } return(RedirectToAction("Index", new { id = data.ConfigTypeCode })); } catch { return(View(model: data)); } }
public ActionResult Create(string id, string configCode, FormCollection collection) { SystemConfigValue data = null; try { // 配置类型. SystemConfigType sct = this.systemConfigService.GetSystemConfigType(id); ViewBag.SystemConfigType = sct; // 配置属性 List <SystemConfigProperty> scp = this.systemConfigService.GetSystemConfigPropertyByType(id); ViewBag.SystemConfigPropertys = scp; data = this.systemConfigService.GetSystemConfigValue(id, configCode); if (data != null) { // 数据已存在. return(View(model: data)); } data = new SystemConfigValue() { ConfigTypeCode = id, ConfigCode = configCode, ConfigName = collection["ConfigName"], }; Dictionary <string, Object> configObj = new Dictionary <string, object>(); foreach (var prop in scp) { String value = collection[prop.PropertyName]; configObj.Add(prop.PropertyName, BasicDataConvert(prop.PropertyDataType, value)); } data.ConfigValueObject = configObj; string resultMsg = null; bool result = this.systemConfigService.UpdateSystemConfigValue(data, ref resultMsg); if (!result) { return(View(model: data)); } return(RedirectToAction("Index", new { id = data.ConfigTypeCode })); } catch { return(View(model: data)); } }
/// <summary> /// 取得指定类型的 系统配置数值. /// </summary> /// <param name="configTypeCode"></param> /// <returns></returns> public List <SystemConfigValue> GetSystemConfigValueByType(string configTypeCode) { using (MySystemConfigContext context = new MySystemConfigContext()) { // 首先,取得类型. SystemConfigType systemConfigType = context.SystemConfigTypes.Find(configTypeCode); if (systemConfigType == null) { // 类型为空, 返回空白列表. return(new List <SystemConfigValue>()); } // 然后, 查询明细. var query = from data in context.SystemConfigValues where data.ConfigTypeCode == configTypeCode orderby data.ConfigCode select data; // 取得结果. List <SystemConfigValue> resultList = query.ToList(); // 配置的数据类型. Type configType = null; try { configType = Type.GetType(systemConfigType.ConfigClassName); } catch (Exception) { configType = null; } foreach (var item in resultList) { // Json 反序列化. if (configType != null) { // 指定了数据类型. item.ConfigValueObject = JsonConvert.DeserializeObject(item.ConfigValue, configType); } else { // 未指定数据类型. item.ConfigValueObject = JsonConvert.DeserializeObject(item.ConfigValue); } } return(resultList); } }
public ActionResult Create(string id) { // 配置类型. SystemConfigType sct = this.systemConfigService.GetSystemConfigType(id); ViewBag.SystemConfigType = sct; // 配置属性 List <SystemConfigProperty> scp = this.systemConfigService.GetSystemConfigPropertyByType(id); ViewBag.SystemConfigPropertys = scp; return(View()); }
// GET: SystemConfig/Details/5 public ActionResult Details(string configTypeCode, string configCode) { // 配置类型. SystemConfigType sct = this.systemConfigService.GetSystemConfigType(configTypeCode); ViewBag.SystemConfigType = sct; // 配置属性 List <SystemConfigProperty> scp = this.systemConfigService.GetSystemConfigPropertyByType(configTypeCode); ViewBag.SystemConfigPropertys = scp; // 数据. SystemConfigValue data = this.systemConfigService.GetSystemConfigValue(configTypeCode, configCode); if (data == null) { return(HttpNotFound()); } return(View(model: data)); }
// GET: SystemConfigValue public ActionResult Index(string id) { SystemConfigType typeData = this.systemConfigService.GetSystemConfigType(id); if (typeData == null) { return(HttpNotFound()); } ViewBag.SystemConfigType = typeData; List <SystemConfigValue> dataList = null; using (MySystemConfigContext context = new MySystemConfigContext()) { var query = from data in context.SystemConfigValues select data; if (!String.IsNullOrEmpty(id)) { query = query.Where(p => p.ConfigTypeCode == id); } // 查询数据. dataList = query.ToList(); } if (typeData.ConfigClassName == SystemConfigType.SimpleDictionary) { // 如果是简单 Key-Value。 // 还需要额外处理查询条件。 foreach (var data in dataList) { data.ConfigValueObject = JsonConvert.DeserializeObject(data.ConfigValue, Type.GetType(typeData.ConfigClassName)); } var dataQuery = from data in dataList select data; // 配置属性 List <SystemConfigProperty> scpList = this.systemConfigService.GetSystemConfigPropertyByType(id); foreach (var scp in scpList) { if (scp.IsSearchAble) { string queryString = Request[scp.PropertyName]; if (!String.IsNullOrEmpty(queryString)) { switch (scp.PropertyDataType) { case "System.Boolean": bool boolValue = Convert.ToBoolean(queryString); dataQuery = dataQuery.Where(p => p.ConfigValueObject[scp.PropertyName] == boolValue); break; case "System.String": dataQuery = dataQuery.Where(p => p.ConfigValueObject[scp.PropertyName].Contains(queryString)); break; case "System.Int32": case "System.Int64": long intValue = 0; if (Int64.TryParse(queryString, out intValue)) { dataQuery = dataQuery.Where(p => p.ConfigValueObject[scp.PropertyName] == intValue); } break; } } } } List <SystemConfigValue> resultList = dataQuery.ToList(); return(View(model: resultList)); } return(View(model: dataList)); }