From 539528fdcb5bf32334fc23add8e3568bcd6b9058 Mon Sep 17 00:00:00 2001 From: "liuchun_0206@163.com" Date: Tue, 8 Nov 2016 15:35:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AA=E6=80=A7=E5=8C=96=E7=BB=B4=E6=8A=A4?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=92=8C=E4=BF=9D=E5=AD=98=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bootstrap.Admin/Bootstrap.Admin.csproj | 1 + .../Controllers/ProfilesController.cs | 41 +++++++++++++ Bootstrap.Admin/Scripts/Profiles.js | 57 ++++++++++++++++++- Bootstrap.Admin/Views/Admin/Profiles.cshtml | 10 ++-- Bootstrap.Admin/packages.config | 3 + Bootstrap.DataAccess/DictHelper.cs | 46 +++++++++++++++ 6 files changed, 153 insertions(+), 5 deletions(-) create mode 100644 Bootstrap.Admin/Controllers/ProfilesController.cs diff --git a/Bootstrap.Admin/Bootstrap.Admin.csproj b/Bootstrap.Admin/Bootstrap.Admin.csproj index 993dfbaf..e932ad0f 100644 --- a/Bootstrap.Admin/Bootstrap.Admin.csproj +++ b/Bootstrap.Admin/Bootstrap.Admin.csproj @@ -212,6 +212,7 @@ + diff --git a/Bootstrap.Admin/Controllers/ProfilesController.cs b/Bootstrap.Admin/Controllers/ProfilesController.cs new file mode 100644 index 00000000..9a7bf89c --- /dev/null +++ b/Bootstrap.Admin/Controllers/ProfilesController.cs @@ -0,0 +1,41 @@ +using Bootstrap.DataAccess; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Web.Http; + + +namespace Bootstrap.Admin.Controllers +{ + public class ProfilesController : ApiController + { + // GET api/ + public IEnumerable Get() + { + string sysName = DictHelper.RetrieveWebTitle(); + string footer = DictHelper.RetrieveWebFooter(); + return new string[] { sysName, footer }; + } + + // POST api/ + public bool Post([FromBody]JObject value) + { + //保存个性化设置 + dynamic json = value; + return DictHelper.SaveProfiles((string)json.type, (string)json.dvalue); + } + + // PUT api//5 + public void Put(int id, [FromBody]string value) + { + } + + // DELETE api//5 + public void Delete(int id) + { + } + } +} \ No newline at end of file diff --git a/Bootstrap.Admin/Scripts/Profiles.js b/Bootstrap.Admin/Scripts/Profiles.js index 1813e9a8..aed049f1 100644 --- a/Bootstrap.Admin/Scripts/Profiles.js +++ b/Bootstrap.Admin/Scripts/Profiles.js @@ -1,4 +1,55 @@ $(function () { + + var url = "../api/Profiles"; + + $.ajax({ + url: url, + type: 'GET', + success: function (result) { + if (result) { + $('#sysNameSet').val(result[0]); + $('#footSet').val(result[1]); + } + else { + swal("失败", "加载数据失败", "error"); + } + } + }); + + $('#sysSave').click(function () { + var dvalue = $('#sysNameSet').val(); + $.ajax({ + url: url, + data: { "type": "sysName", "dvalue": dvalue }, + type: 'POST', + success: function (result) { + if (result) { + swal("成功", "设置网站标题成功", "success"); + } + else { + swal("失败", "设置网站标题失败", "error"); + } + } + }); + }); + + $('#footSave').click(function () { + var dvalue = $('#footSet').val(); + $.ajax({ + url: url, + data: { "type": "foot", "dvalue": dvalue }, + type: 'POST', + success: function (result) { + if (result) { + swal("成功", "设置网站页脚成功", "success"); + } + else { + swal("失败", "设置网站页脚失败", "error"); + } + } + }); + }); + var html = '
  • {2}{0}
    {3}
  • '; function listCache(options) { @@ -31,4 +82,8 @@ listCache({ url: '../../CacheList.axd' }); $('a.fa-refresh').click(function () { listCache({ url: '../../CacheList.axd' }); }); -}); \ No newline at end of file + + + + +}) \ No newline at end of file diff --git a/Bootstrap.Admin/Views/Admin/Profiles.cshtml b/Bootstrap.Admin/Views/Admin/Profiles.cshtml index 86f1e25a..fc8dfe4e 100644 --- a/Bootstrap.Admin/Views/Admin/Profiles.cshtml +++ b/Bootstrap.Admin/Views/Admin/Profiles.cshtml @@ -4,6 +4,7 @@ Layout = "~/Views/Shared/_Admin.cshtml"; } @section Javascript { + } @section css { @@ -15,13 +16,14 @@ @section navigator { @Html.Partial("Navigator", Model) } +
    系统名称设置
    - + - +
    @@ -30,9 +32,9 @@
    页脚设置
    - + - +
    diff --git a/Bootstrap.Admin/packages.config b/Bootstrap.Admin/packages.config index a1fc3d2c..fc40b7d3 100644 --- a/Bootstrap.Admin/packages.config +++ b/Bootstrap.Admin/packages.config @@ -4,8 +4,11 @@ + + + diff --git a/Bootstrap.DataAccess/DictHelper.cs b/Bootstrap.DataAccess/DictHelper.cs index bdb34010..cbbf1fda 100644 --- a/Bootstrap.DataAccess/DictHelper.cs +++ b/Bootstrap.DataAccess/DictHelper.cs @@ -156,5 +156,51 @@ namespace Bootstrap.DataAccess var settings = DictHelper.RetrieveWebSettings(); return (settings.FirstOrDefault(d => d.Name == "网站页脚") ?? new Dict() { Code = "2016 © 通用后台管理系统" }).Code; } + /// + /// 保存网站个性化设置 + /// 2016-11-8 + /// + /// + public static bool SaveProfiles(string type, string value) + { + string name=""; + string category="网站设置"; + switch(type) + { + case "sysName": name = "网站标题"; break; + case "foot": name = "网站页脚"; break; + } + var settings = DictHelper.RetrieveWebSettings(); + var p = from ps in settings + where ps.Name.Equals(name) + select new + { + ID=ps.ID + }; + + var ret = false; + string sql = "Update Dicts set Code = @Code where Category =@Category and Name=@Name"; + try + { + using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql)) + { + cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Code", value, ParameterDirection.Input)); + cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Category", category, ParameterDirection.Input)); + cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Name", name, ParameterDirection.Input)); + DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); + } + ret = true; + + foreach(var px in p) + CacheCleanUtility.ClearCache(dictIds:px.ID.ToString()); + } + catch (DbException ex) + { + ExceptionManager.Publish(ex); + } + return ret; + } + + } }