Browse Source

修改配置文件接口

zhoufan 7 years ago
parent
commit
84727a2591

+ 22 - 0
codegit/CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Controllers/HomeController.cs

@@ -288,5 +288,27 @@ namespace CallCenterApi.Interface.Controllers
288 288
             return Success("成功", n);
289 289
         }
290 290
 
291
+        public ActionResult GetConfigList()
292
+        {
293
+            return Success("成功", Configs.GetList());
294
+        }
295
+
296
+        public ActionResult GetConfig(string key)
297
+        {
298
+            return Success("成功", Configs.GetValue(key));
299
+        }
300
+
301
+        public ActionResult SetConfig(string key,string value)
302
+        {
303
+            if (Configs.SetValue(key, value))
304
+            {
305
+                return Success("成功");
306
+            }
307
+            else
308
+            {
309
+                return Error("失败");
310
+            }
311
+        }
312
+
291 313
     }
292 314
 }

+ 1 - 1
codegit/CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Controllers/SysConfigController.cs

@@ -11,7 +11,7 @@ using System.Web.Mvc;
11 11
 
12 12
 namespace CallCenterApi.Interface.Controllers
13 13
 {
14
-    //[Authority]
14
+    [Authority]
15 15
     public class SysConfigController : BaseController
16 16
     {
17 17
         private BLL.T_Sys_SystemConfig sysConfigBLL = new BLL.T_Sys_SystemConfig();

+ 36 - 3
codegit/CallCenterCommon/CallCenter.Utility/Configs/Configs.cs

@@ -1,4 +1,5 @@
1
-using System.Configuration;
1
+using System.Collections.Generic;
2
+using System.Configuration;
2 3
 using System.Web;
3 4
 namespace CallCenter.Utility
4 5
 {
@@ -37,7 +38,7 @@ namespace CallCenter.Utility
37 38
         /// </summary>
38 39
         /// <param name="key">要修改的Key</param>
39 40
         /// <param name="value">要修改为的值</param>
40
-        public static void SetValue(string key, string value)
41
+        public static bool SetValue(string key, string value)
41 42
         {
42 43
             try
43 44
             {
@@ -57,9 +58,41 @@ namespace CallCenter.Utility
57 58
                     xNode.AppendChild(xElem2);
58 59
                 }
59 60
                 xDoc.Save(HttpContext.Current.Server.MapPath("~/Configs/system.config"));
61
+
62
+                return true;
63
+            }
64
+            catch
65
+            {
66
+                return false;
67
+            }
68
+        }
69
+
70
+        /// <summary>
71
+        /// 获取配置列表
72
+        /// </summary>
73
+        /// <returns></returns>
74
+        public static Dictionary<string, string> GetList()
75
+        {
76
+            Dictionary<string, string> paras = new Dictionary<string, string>();
77
+
78
+            try
79
+            {
80
+                System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument();
81
+                xDoc.Load(HttpContext.Current.Server.MapPath("~/Configs/system.config"));
82
+                System.Xml.XmlNode xNode = xDoc.SelectSingleNode("//appSettings");
83
+
84
+                var enumer = xNode.SelectNodes("//add").GetEnumerator();
85
+                while (enumer.MoveNext())
86
+                {
87
+                    System.Xml.XmlElement xe = (System.Xml.XmlElement)enumer.Current;
88
+                    paras.Add(xe.GetAttribute("key"), xe.GetAttribute("value"));
89
+                }
60 90
             }
61 91
             catch
62
-            { }
92
+            {
93
+            }
94
+
95
+            return paras;
63 96
         }
64 97
     }
65 98
 }