diff --git a/.gitignore b/.gitignore index fecad19..078ea47 100644 --- a/.gitignore +++ b/.gitignore @@ -307,3 +307,4 @@ COMCMS.Web/wwwroot/userfiles/ /COMCMS.Web/COMCMS.Web.csproj.DotSettings /COMCMS.Web/UploadFile /COMCMS.Web/UploadTemp +/WebTest/wwwroot diff --git a/COMCMS.Common/COMCMS.Common.csproj b/COMCMS.Common/COMCMS.Common.csproj index 471d873..4633556 100644 --- a/COMCMS.Common/COMCMS.Common.csproj +++ b/COMCMS.Common/COMCMS.Common.csproj @@ -5,7 +5,7 @@ - + diff --git a/COMCMS.Common/Pages.cs b/COMCMS.Common/Pages.cs new file mode 100644 index 0000000..0e5f005 --- /dev/null +++ b/COMCMS.Common/Pages.cs @@ -0,0 +1,172 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace COMCMS.Common +{ + public class Pages + { + + #region 列表分页 + /// + /// 显示分页2 + /// + /// 每页显示记录数 + /// 总记录数 + /// 当前页码 + /// 分页文件名字,静态:index.html;动态List.aspx + /// 系统urlReWrite方案;99为ajax连接 + /// 最大显示分页数量 + /// 目录名称(系统urlReWrite方案为5必填) + /// + public static string GetPageStr(int pageSize, int recordCount, int page, string url, int isRewrite, int maxShowPage, string filepath = "") + { + if (recordCount < 1) + { + return ""; + } + int pageCount = recordCount / pageSize;//总页数 + if (recordCount % pageSize > 0) + { + pageCount += 1; + } + if (pageCount < 2) + { + return ""; + } + if (page > pageCount) page = pageCount; + StringBuilder strPage = new StringBuilder(); + string pageLink = "";// url + "?id=" + HttpContext.Current.Request.QueryString["id"] + "&page={0}"; + string strQueryString = MyHttpContext.Current.Request.QueryString.ToString().ToLower(); + if (isRewrite != 5) + url = url.ToLower(); + pageLink = url + "?" + strQueryString; + string currPage = MyHttpContext.Current.Request.Query["page"]; + string id = MyHttpContext.Current.Request.Query["id"]; + if (isRewrite == 5) + { + url = $"/{filepath}/index.html"; + } + if (url == "memberdownloads.aspx" && isRewrite == 2) + { + string t = MyHttpContext.Current.Request.Query["t"]; + if (string.IsNullOrEmpty(t) || !Utils.IsInt(t)) + t = "1"; + url = string.Format("memberdownloads-{0}.aspx", t); + } + + switch (isRewrite) + { + case 1: + url = url.Replace(".html", ".aspx");//避免设置错之后出现问题 + url = url.Replace(".", "-" + id + "."); + pageLink = url.Replace(".", "-{0}."); + break; + case 2: + url = url.Replace(".aspx", ".html");//避免设置错之后出现问题 + if (!string.IsNullOrEmpty(id)) + url = url.Replace(".", "-" + id + "."); + else + url = url.Replace(".", "-0."); + pageLink = url.Replace(".", "-{0}."); + break; + case 3: + url = url.Replace(".aspx", ".html");//避免设置错之后出现问题 + pageLink = url.Replace(".", "-{0}."); + break; + case 5: + pageLink = url.Replace(".", "-{0}."); + break; + case 99://调用ajax 连接 + pageLink = url; + url = string.Format(pageLink, "1"); + break; + case 0: + default: + //动态链接 + if (pageLink.IndexOf("page=") > 0) + { + pageLink = pageLink.Replace("page=" + currPage, "page={0}"); + } + else + { + pageLink = pageLink + "&page={0}"; + } + url = string.Format(pageLink, "1"); + break; + } + strPage.Append("
"); + if (page != 1)//显示[首页] + { + //strPage.AppendFormat("{1}", url, Lang.GetPagesLangVal("firstpage")); + strPage.AppendFormat("{1}", string.Format(pageLink, 1), "首页"); + } + + if (page > 1)//上一页 + { + if (page == 2)//[首页]要index.html + { + //strPage.AppendFormat("{1}", url, Lang.GetPagesLangVal("prevpage")); + strPage.AppendFormat("{1}", string.Format(pageLink, (page - 1).ToString()), "上一页"); + } + else + { + strPage.AppendFormat("{1}", string.Format(pageLink, (page - 1).ToString()), "上一页"); + } + } + //显示中间所有页数,如果是当前页,则外加一个样式 + string strAllPage = "[{1}]"; + + //显示当前的多少页 + int cureSize = maxShowPage; + int sizes = cureSize / 2;//中间 + int minPage = page - sizes;//最小起始页码 + int maxPage = page + sizes;//最大页码 + if (minPage <= 0) + { + minPage = 1; + maxPage = cureSize; + } + if (maxPage >= pageCount) + { + minPage = pageCount - cureSize + 1; + maxPage = pageCount; + } + + for (int i = 1; i <= pageCount; i++) + { + if (i >= minPage && i <= maxPage)//循环最小到最大页码中间所有页数 + { + if (i == page) + { + strPage.Append(string.Format(strAllPage, "javascritp:;", i.ToString(), "class=\"curr\"")); + } + else + { + if (i == 1)//第一页不能显示成index-1.html + { + if (isRewrite == 4) + { + strPage.Append(string.Format(strAllPage, string.Format(pageLink, i.ToString()), i.ToString(), "")); + } + else + strPage.Append(string.Format(strAllPage, url, "1", "")); + } + else + { + strPage.Append(string.Format(strAllPage, string.Format(pageLink, i.ToString()), i.ToString(), "")); + } + } + } + } + if (page < pageCount)//显示[下一页]/[尾页] + { + strPage.AppendFormat("{1}", string.Format(pageLink, (page + 1).ToString()), "下一页"); + strPage.AppendFormat("{1}", string.Format(pageLink, pageCount.ToString()), "尾页"); + } + strPage.Append("
"); + return strPage.ToString().Replace("[", "").Replace("]", ""); + } + #endregion + } +} diff --git a/COMCMS.Common/Utils.cs b/COMCMS.Common/Utils.cs index 4a93e12..75fb6ac 100644 --- a/COMCMS.Common/Utils.cs +++ b/COMCMS.Common/Utils.cs @@ -325,7 +325,7 @@ namespace COMCMS.Common { using (var md5 = System.Security.Cryptography.MD5.Create()) { - var result = md5.ComputeHash(Encoding.ASCII.GetBytes(str)); + var result = md5.ComputeHash(Encoding.UTF8.GetBytes(str)); var strResult = BitConverter.ToString(result); return strResult.Replace("-", ""); } @@ -339,7 +339,7 @@ namespace COMCMS.Common { using(var sha256 = System.Security.Cryptography.SHA256.Create()) { - var result = sha256.ComputeHash(Encoding.ASCII.GetBytes(str)); + var result = sha256.ComputeHash(Encoding.UTF8.GetBytes(str)); var strResult = BitConverter.ToString(result); return strResult.Replace("-", ""); } diff --git a/COMCMS.Core/COMCMS.Core.csproj b/COMCMS.Core/COMCMS.Core.csproj index 3346f3c..9017645 100644 --- a/COMCMS.Core/COMCMS.Core.csproj +++ b/COMCMS.Core/COMCMS.Core.csproj @@ -6,7 +6,7 @@ - + diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs index 07c98c3..af11af0 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; @@ -12,6 +13,8 @@ using Microsoft.AspNetCore.Http; namespace COMCMS.Web.Areas.AdminCP.Controllers { + [DisplayName("文章系统")] + [Description("文章系统管理,包括文章、文章栏目")] public class ArticleController : AdminBaseController { #region 文章栏目 @@ -20,6 +23,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers /// /// [MyAuthorize( "viewlist", "articlecategory")] + [DisplayName("文章栏目")] public IActionResult ArticleCategoryList() { IList list = ArticleCategory.GetListTree(0, -1, false, true); @@ -33,7 +37,20 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers //获取上级栏目 IList list = ArticleCategory.GetListTree(0, -1, true, false); ViewBag.ListTree = list; - //获取模板 + //获取模板 模板规则,以Index_开头的,为栏目列表,以Detial_开头的为文章详情 + List listTpls = new List(); + var asms = AppDomain.CurrentDomain.GetAssemblies(); + foreach (var asmItem in asms) + { + var types = asmItem.GetTypes().Where(e => e.Name.StartsWith("Views_Article")).ToList(); + if (types.Count == 0) continue; + foreach (var type in types) + { + string viewName = type.Name.Replace("Views_Article_", "") + ".cshtml"; + listTpls.Add(viewName); + } + } + ViewBag.ListTpl = listTpls; Core.Admin.WriteLogActions("查看添加文章栏目页面;"); return View(); } @@ -69,9 +86,21 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers //获取上级栏目 IList list = ArticleCategory.GetListTree(0, -1, true, false); ViewBag.ListTree = list; - //获取模板 - //List listtpl = COMCMS.Common.IOHelper.GetDirFiles(new DirectoryInfo(Server.MapPath("~/Views/article"))); - //ViewBag.ListTpl = listtpl; + + //获取模板 模板规则,以Index_开头的,为栏目列表,以Detial_开头的为文章详情 + List listTpls = new List(); + var asms = AppDomain.CurrentDomain.GetAssemblies(); + foreach (var asmItem in asms) + { + var types = asmItem.GetTypes().Where(e => e.Name.StartsWith("Views_Article")).ToList(); + if (types.Count == 0) continue; + foreach (var type in types) + { + string viewName = type.Name.Replace("Views_Article_", "") + ".cshtml"; + listTpls.Add(viewName); + } + } + ViewBag.ListTpl = listTpls; Core.Admin.WriteLogActions("查看/编辑文章栏目(id:" + id + ")页面;"); return View(entity); } @@ -189,6 +218,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers /// /// [MyAuthorize("viewlist", "article")] + [DisplayName("文章")] public IActionResult ArticleList() { //获取上级栏目 diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/GuestbookController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/GuestbookController.cs index f7cfe46..dfcef92 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/GuestbookController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/GuestbookController.cs @@ -99,7 +99,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers ViewBag.ListKinds = list; return View(); } - [MyAuthorize("viewlist", "guestbook")] + [MyAuthorize("viewlist", "guestbook","JSON")] public IActionResult GetGuesbookList(string keyword, int page = 1, int limit = 20) { int numPerPage, currentPage, startRowIndex; @@ -156,7 +156,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers } [HttpPost] [MyAuthorize("edit", "guestbook", "JSON")] - public IActionResult EditGuestbook(FormCollection fc) + public IActionResult EditGuestbook(IFormCollection fc) { string id = fc["Id"]; if (!Utils.IsInt(id) || int.Parse(id) <= 0) diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/MemberController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/MemberController.cs index 0440ad6..68e8c12 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/MemberController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/MemberController.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; @@ -19,6 +20,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers /// /// 后台用户管理控制器 /// + [DisplayName("管理员")] public class MemberController : AdminBaseController { #region 修改密码 @@ -115,6 +117,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers #region 管理组管理 [MyAuthorize("viewlist", "adminrole")] + [DisplayName("管理组")] public IActionResult AdminRole() { IList list = AdminRoles.FindAll(AdminRoles._.Id > 0, AdminRoles._.Rank.Asc(), null, 0, 0); @@ -366,6 +369,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers #region 管理员管理 //管理员管理 [MyAuthorize("viewlist", "admins")] + [DisplayName("管理员")] public IActionResult Admins() { //加载管理组 @@ -608,7 +612,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers //执行添加用户组 [HttpPost] [MyAuthorize("add", "memberrole", "JSON")] - public IActionResult AddMemberRole(FormCollection fc) + public IActionResult AddMemberRole(IFormCollection fc) { string RoleName = fc["RoleName"]; string RoleDescription = fc["RoleDescription"]; diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/PermissionController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/PermissionController.cs index 7e46894..dc40bcb 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/PermissionController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/PermissionController.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; @@ -13,6 +14,7 @@ using Microsoft.AspNetCore.Http; namespace COMCMS.Web.Areas.AdminCP.Controllers { [Area("AdminCP")] + [DisplayName("后台权限")] public class PermissionController : AdminBaseController { #region 事件管理 @@ -63,7 +65,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers [MyAuthorize( "add", "eventkey", "JSON")] [HttpPost] - public IActionResult AddEventKey(FormCollection fc) + public IActionResult AddEventKey(IFormCollection fc) { TargetEvent entity = new TargetEvent(); entity.EventKey = fc["EventKey"]; @@ -107,6 +109,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers #region 后台栏目管理 //后台菜单列表 [MyAuthorize( "viewlist", "adminmenu")] + [DisplayName("后台栏目")] public IActionResult AdminMenuList() { IList list = AdminMenu.GetListTree(0, -1, false, true); diff --git a/COMCMS.Web/Areas/AdminCP/Views/Article/AddArticleCategory.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Article/AddArticleCategory.cshtml index 9abb2d7..98356d8 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Article/AddArticleCategory.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Article/AddArticleCategory.cshtml @@ -76,28 +76,34 @@ - @*
- -
- -
-
-
- -
- + @foreach (var s in ViewBag.ListTpl) + { + if (s.ToLower().StartsWith("index")) { } - -
-
*@ + } + + + +
+ +
+ +
+
diff --git a/COMCMS.Web/Areas/AdminCP/Views/Article/EditArticleCategory.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Article/EditArticleCategory.cshtml index 8cfea3b..bc8c428 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Article/EditArticleCategory.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Article/EditArticleCategory.cshtml @@ -76,28 +76,34 @@
- @*
- -
- + @foreach (string s in ViewBag.ListTpl) + { + if (s.ToLower().StartsWith("index")) { - + } - -
+ } +
-
- -
- + @foreach (string s in ViewBag.ListTpl) + { + if (s.ToLower().StartsWith("detail")) { - + } - -
-
*@ + } + + +
diff --git a/COMCMS.Web/Areas/AdminCP/Views/Other/AddLink.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Other/AddLink.cshtml index 4388d8f..308f75e 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Other/AddLink.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Other/AddLink.cshtml @@ -81,6 +81,8 @@
diff --git a/COMCMS.Web/Areas/AdminCP/Views/Product/AddProduct.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Product/AddProduct.cshtml index 4172d20..699a3d3 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Product/AddProduct.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Product/AddProduct.cshtml @@ -2,7 +2,7 @@ @{ ViewBag.title = "添加商品详情"; } -
+
@ViewBag.title
diff --git a/COMCMS.Web/Areas/AdminCP/Views/Product/EditProduct.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Product/EditProduct.cshtml index 7f6b063..349c22d 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Product/EditProduct.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Product/EditProduct.cshtml @@ -2,7 +2,7 @@ @{ ViewBag.title = "编辑商品详情"; } -
+
@ViewBag.title
diff --git a/COMCMS.Web/Areas/AdminCP/Views/Shared/_CommonLayout.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Shared/_CommonLayout.cshtml index 69f7b9c..f55c23d 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Shared/_CommonLayout.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Shared/_CommonLayout.cshtml @@ -34,7 +34,7 @@ - + diff --git a/COMCMS.Web/COMCMS.Web.csproj b/COMCMS.Web/COMCMS.Web.csproj index 18d8dc0..e136e6e 100644 --- a/COMCMS.Web/COMCMS.Web.csproj +++ b/COMCMS.Web/COMCMS.Web.csproj @@ -5,17 +5,17 @@ - - - - + + + + - - - - - + + + + + diff --git a/COMCMS.Web/Common/HomeBaseController.cs b/COMCMS.Web/Common/HomeBaseController.cs new file mode 100644 index 0000000..97a5af8 --- /dev/null +++ b/COMCMS.Web/Common/HomeBaseController.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using COMCMS.Common; +using COMCMS.Core; +using XCode; + +namespace COMCMS.Web.Common +{ + /// + /// 网站前台基础页 + /// + public class HomeBaseController : Controller + { + public Config cfg; + public JsonTip tip = new JsonTip(); + + public HomeBaseController() + { + cfg = Config.GetSystemConfig(); + } + + /// + /// Alert提示并返回 + /// + /// 提示内容 + public IActionResult AlertAndGoBack(string str) + { + if (!string.IsNullOrWhiteSpace(str)) str = str.Replace("'", "\\'"); + return Content($""); + } + /// + /// Alert提示并跳转到指定URL + /// + /// 提示内容 + /// 跳转地址 + public IActionResult AlertAndRedirect(string str, string url) + { + if (!string.IsNullOrWhiteSpace(str)) str = str.Replace("'", "\\'"); + return Content($""); + } + + #region MyRegion + /// + /// 显示提示页面 + /// + /// 提示语 + /// 成功/失败 + /// 返回URL + /// + public IActionResult EchoTip(string Message, bool IsSuccess = false, string ReturnURL = "") + { + ViewBag.IsSuccess = IsSuccess; + ViewBag.Message = Message; + ViewBag.ReturnURL = ReturnURL; + ViewBag.cfg = cfg; + return View("EchoTip"); + } + #endregion + } +} \ No newline at end of file diff --git a/COMCMS.Web/Common/MenuRegister.cs b/COMCMS.Web/Common/MenuRegister.cs new file mode 100644 index 0000000..efb631e --- /dev/null +++ b/COMCMS.Web/Common/MenuRegister.cs @@ -0,0 +1,145 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Threading.Tasks; +using COMCMS.Core; +using Microsoft.AspNetCore.Mvc; +using NewLife.Reflection; +using XCode; + +namespace COMCMS.Web.Common +{ + public class MenuRegister + { + private static void StartRegister() + { + if (AdminMenu.Meta.Count > 0) + return; + // 操作项定义 + var menuEventDic = new Dictionary> + { + { "add",new KeyValuePair(1,"添加")}, + { "edit",new KeyValuePair(2,"修改")}, + { "del",new KeyValuePair(3,"删除")}, + { "view",new KeyValuePair(4,"查看")}, + { "viewlist",new KeyValuePair(5,"查看列表")}, + { "import",new KeyValuePair(6,"导入")}, + { "export",new KeyValuePair(7,"导出")}, + { "filter",new KeyValuePair(8,"搜索")}, + { "batch",new KeyValuePair(9,"批量操作")}, + { "recycle",new KeyValuePair(10,"回收站")}, + { "confirm",new KeyValuePair(11,"确认")}, + + }; + + var asms = AppDomain.CurrentDomain.GetAssemblies(); + foreach (var asmItem in asms) + { + var types = asmItem.GetTypes().Where(e => e.Name.EndsWith("Controller")).ToList(); + if (types.Count == 0) continue; + + foreach (var type in types) + { + if (!type.Namespace.Contains(".AdminCP.Controller")) + { + continue; + } + + // 控制器名称 + var ctrName = type.Name.TrimEnd("Controller"); + + // 控制器展示名 + var ctrDpName = type.GetDisplayName(); + + var ctrDes = type.GetDescription(); + + var url = ctrName; + + var fAdminMenu = AdminMenu.Find(AdminMenu._.MenuKey == ctrName + "Sys" & AdminMenu._.Link == "#"); + var nAdminMenu = new AdminMenu + { + Description = ctrDes, + IsHide = 0, + Level = 0, + Link = "#", + Location = "0,", + MenuKey = ctrName + "Sys", + MenuName = ctrDpName, + PId = 0 + }; + var pAdminMenu = fAdminMenu ?? nAdminMenu; + if (pAdminMenu.Id > 0) + { + pAdminMenu.Description = nAdminMenu.Description; + pAdminMenu.MenuName = nAdminMenu.MenuName; + } + + // 控制器所有包含MyAuthorizeAttribute的方法 + var acts = type.GetMethods() + .Where(w => w.IsDefined(typeof(MyAuthorizeAttribute))) + .ToList(); + + if (!acts.Any()) continue; + + pAdminMenu.Save(); + + var eventKeyDic = new Dictionary(); + var adminMenuEventList = new List(); + + foreach (var method in acts) + { + var dn = method.GetDisplayName(); + var methodDes = method.GetDescription(); + var actName = method.Name; + var myAuthorize = method.GetCustomAttribute(); + + var menuKey = myAuthorize.GetValue("_menuKey").ToString(); + var eventKey = myAuthorize.GetValue("_eventKey").ToString(); + var returnType = myAuthorize.GetValue("_returnType").ToString(); + + //保存菜单 + if (eventKey == "viewlist" && returnType == "HTML") + { + var adminMenu = AdminMenu.Find(AdminMenu._.MenuKey == menuKey & AdminMenu._.Link == url + "/" + actName) ?? new AdminMenu + { + Description = methodDes, + IsHide = 0, + Level = pAdminMenu.Level + 1, + Link = url + "/" + actName, + Location = pAdminMenu.Location + ",", + MenuKey = menuKey, + MenuName = dn, + PId = pAdminMenu.Id + }; + adminMenu.Save(); + + eventKeyDic[menuKey] = adminMenu.Id; + } + + // 保存操作 + var adminmenuevent = AdminMenuEvent.Find(AdminMenuEvent._.MenuId == menuEventDic[eventKey].Key + & AdminMenuEvent._.MenuKey == menuKey & AdminMenuEvent._.EventKey == eventKey) + ?? new AdminMenuEvent + { + MenuKey = menuKey, + MenuId = menuEventDic[eventKey].Key, + EventKey = eventKey, + EventName = menuEventDic[eventKey].Value + }; + adminMenuEventList.Add(adminmenuevent); + } + + adminMenuEventList.ForEach(f => f.MenuId = eventKeyDic.ContainsKey(f.MenuKey) ? eventKeyDic[f.MenuKey] : 0); + adminMenuEventList.Save(); + } + + } + } + + public static void Register() + { + Task.Run(() => { StartRegister(); }).LogException(); + } + } +} diff --git a/COMCMS.Web/Controllers/ArticleController.cs b/COMCMS.Web/Controllers/ArticleController.cs new file mode 100644 index 0000000..ee6b1d0 --- /dev/null +++ b/COMCMS.Web/Controllers/ArticleController.cs @@ -0,0 +1,155 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using COMCMS.Common; +using COMCMS.Core; +using COMCMS.Core.Models; +using COMCMS.Web.Common; +using XCode; + +namespace COMCMS.Web.Controllers +{ + public class ArticleController : HomeBaseController + { + #region 显示列表 + // GET: Article + [HttpGet] + public IActionResult Index(int id = 0, int page = 1) + { + ArticleCategory model = ArticleCategory.FindById(id); + if (model == null) + { + return AlertAndGoBack("系统找不到本记录"); + } + //如果跳转到地址 + if (!string.IsNullOrEmpty(model.LinkURL)) + { + if (Utils.IsInt(model.LinkURL))//如果是数字,则跳转到详情 + { + //Redirect($"/aritcle/{model.LinkURL}.html"); + return Redirect($"/Article/Detail/{model.LinkURL}"); + } + else + { + return Redirect(model.LinkURL); + } + + } + if (page < 1) page = 1; + + if (model.IsList == 1) + { + IList
list = new List
(); + int numPerPage, currentPage, startRowIndex; + numPerPage = model.PageSize; + if (page > 0) + currentPage = page; + else + currentPage = 1; + + startRowIndex = (currentPage - 1) * numPerPage; + + var ex = Article._.IsHide != 1 & Article._.IsDel != 1; + + //如果显示下级栏目文章 + if (model.IsShowSubDetail == 1) + { + //获取下级所有栏目 + List allsubkids = new List(); + allsubkids.Add(model.Id); + + IList allkind = ArticleCategory.FindAllSubKinds(model.Id); + if (allkind != null && allkind.Count > 0) + { + foreach (var s in allkind) + { + allsubkids.Add(s.Id); + } + } + ex &= Article._.KId.In(allsubkids); + } + else + ex &= Article._.KId == model.Id; + long totalCount = Article.FindCount(ex, Article._.Sequence.Asc().And(Article._.Id.Desc()), null, startRowIndex, numPerPage); + int pageCount = (int)totalCount / numPerPage;//总页数 + if (totalCount % numPerPage > 0) + { + pageCount += 1; + } + list = Article.FindAll(ex, Article._.Sequence.Asc().And(Article._.Id.Desc()), null, startRowIndex, numPerPage); + ViewBag.list = list;//列表 + //分页信息 + ViewBag.totalCount = totalCount; + ViewBag.pageCount = pageCount; + ViewBag.page = page; + ViewBag.pagesize = numPerPage; + } + + ViewBag.cfg = cfg; + string templatesname = "";//模板名称 + if (!string.IsNullOrEmpty(model.TemplateFile)) + { + templatesname = model.TemplateFile.Replace(".cshtml", "").Replace(".aspx", ""); + return View(templatesname, model); + } + else + { + return View(model); + } + } + #endregion + + #region 显示详情 + [HttpGet] + public IActionResult Detail(int id) + { + Article entity = Article.Find(Article._.Id == id); + if (entity == null) + { + return AlertAndGoBack("系统找不到本记录!"); + } + ArticleCategory kind = ArticleCategory.FindById(entity.KId); + if (kind == null) + { + return AlertAndGoBack("系统找不到本文章栏目!"); + } + //增加点击 + entity.Hits++; + entity.Update(); + if (!string.IsNullOrEmpty(entity.LinkURL)) + { + //return Content(entity.LinkURL); + return Redirect(entity.LinkURL); + } + ViewBag.kind = kind; + ViewBag.cfg = cfg; + //文章更多图片列表 + if (!string.IsNullOrEmpty(entity.ItemImg)) + { + string[] arrimg = entity.ItemImg.Split(new string[] { "|||" }, StringSplitOptions.None); + List listimg = new List(); + foreach (string s in arrimg) + { + if (!string.IsNullOrEmpty(s) && Utils.IsImgFilename(s)) + { + listimg.Add(s.Trim()); + } + } + ViewBag.ListImg = listimg; + } + string templatesname = "";//模板名称 + if (!string.IsNullOrEmpty(kind.TemplateFile)) + { + templatesname = kind.DetailTemplateFile.Replace(".cshtml", "").Replace(".aspx", ""); + return View(templatesname, entity); + } + else + { + return View(entity); + } + } + #endregion + } +} \ No newline at end of file diff --git a/COMCMS.Web/Controllers/HomeController.cs b/COMCMS.Web/Controllers/HomeController.cs index a4d3dd1..6a236db 100644 --- a/COMCMS.Web/Controllers/HomeController.cs +++ b/COMCMS.Web/Controllers/HomeController.cs @@ -15,54 +15,30 @@ using Microsoft.Extensions.Configuration.Json; using Microsoft.AspNetCore.Http; using System.Collections.Concurrent; using Newtonsoft.Json; +using COMCMS.Web.Common; namespace COMCMS.Web.Controllers { - public class HomeController : Controller + public class HomeController : HomeBaseController { - public static IConfiguration Configuration { get; set; } - public ConcurrentDictionary AllSession = new ConcurrentDictionary(); - - public HomeController(IConfiguration configuration) - { - //Configuration = new ConfigurationBuilder() - // .SetBasePath(Directory.GetCurrentDirectory()) - // .AddJsonFile("appsettings.json", optional: true, reloadOnChange : true) - // .Build(); - Configuration = configuration; - } + #region 首页 public IActionResult Index() { - CookieOptions op = new CookieOptions - { - Expires = DateTime.Now.AddMinutes(10), - Path = "/", - HttpOnly = true - }; - Response.Cookies.Append("abc", "123456", op);//用户名 - - - + ViewBag.cfg = cfg; + ViewBag.about = Article.FindById(1);//关于我们 return View(); } + #endregion + public IActionResult About() { - ViewData["Message"] = "Your application description page."; - CookiesHelper.WriteCookie("abc", Utils.GetRandomChar(20), 10); - //sessiong - SessionHelper.WriteSession("bcd", Utils.GetRandomChar(20)); - HttpContext.Session.SetString("abc", "123456"); - return View(); } public IActionResult Contact() { - Link l = Link.Find(Link._.Id == 1); - l.Title = "😂😂😂😂"; - l.Save(); - return View(l); + return View(); } public IActionResult Error() @@ -70,84 +46,5 @@ namespace COMCMS.Web.Controllers return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } - #region 测试 - public IActionResult Test() - { - var css = Configuration.GetSection("connectionStrings"); - var list = css.GetChildren(); - if(list !=null && list.Count() > 0) - { - - } - string s = ""; - foreach (var item in list) - { - string connName = item.Path.Substring(item.Path.IndexOf(":") + 1); - string connectionString = css.GetSection(connName).GetSection("connectionString").Value; - string providerName = css.GetSection(connName).GetSection("providerName").Value; - s += item.Path.Substring(item.Path.IndexOf(":")+1)+ "|"+ Configuration.GetSection(item.Path+ ":connectionString").Value+"|" + Configuration.GetSection(item.Path + ":providerName").Value +"|"+connectionString+"|"+ providerName +"|||" + list.Count(); - } - - return Content(s); - } - - public IActionResult Test2() - { - var settings = Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json"); - var css2 = new ConfigurationBuilder().AddJsonFile(settings).Build().GetSection("connectionStrings"); - - string s = ""; - if (css2 != null) - { - foreach (var item in css2.GetChildren()) - { - var name = item.Path.Substring(item.Path.IndexOf(":") + 1);// item["name"]; - var constr = item["connectionString"]; - var provider = item["providerName"]; - s += $"{name}|{constr}|{provider}|||"; - //var type = DbFactory.GetProviderType(constr, provider); - //if (type == null) XTrace.WriteLine("无法识别{0}的提供者{1}!", name, provider); - - //cs.Add(name, constr); - //_connTypes.Add(name, type); - } - - } - - return Content(s); - } - #endregion - - #region MyRegion - public IActionResult Test3() - { - bool isok = false; - if(AllSession.TryAdd(HttpContext.Session.Id, HttpContext.Session.Id)) - { - isok = true; - } - - return Content(isok.ToString() + ":" + JsonConvert.SerializeObject(AllSession)); - } - #endregion - - #region 测试 - [HttpGet] - public IActionResult Article(string title) - { - return Content(title); - } - #endregion - - public IActionResult Uploader() - { - return View("~/Areas/AdminCP/Views/WebUploader/Uploader.cshtml"); - } - - public IActionResult FileTest() - { - return View(); - - } } } diff --git a/COMCMS.Web/Controllers/ProductController.cs b/COMCMS.Web/Controllers/ProductController.cs new file mode 100644 index 0000000..e86991a --- /dev/null +++ b/COMCMS.Web/Controllers/ProductController.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using COMCMS.Common; +using COMCMS.Core; +using COMCMS.Core.Models; +using COMCMS.Web.Common; +using XCode; + +namespace COMCMS.Web.Controllers +{ + public class ProductController : HomeBaseController + { + #region 分类页面 + [HttpGet] + public IActionResult Index(int id = 0, int page = 1) + { + Category entity = null; + if (id > 0) + { + entity = Category.FindById(id); + if (entity == null) + { + return EchoTip("系统找不到本分类!"); + } + } + else + { + entity = new Category() + { + Id = 0, + KindName = "所有分类", + Keyword = "所有分类", + Description = "所有分类", + PageSize = 10 + }; + } + Expression ex = Product._.IsHide == 0; + if (entity.Id > 0) + { + ex &= Product._.KId == entity.Id; + } + + //计算分页 + int numPerPage, currentPage, startRowIndex; + long totalCount = 0; + + numPerPage = 10; + currentPage = page; + startRowIndex = (currentPage - 1) * numPerPage; + + IList list = Product.FindAll(ex, null, null, startRowIndex, numPerPage); + totalCount = Product.FindCount(ex, null, null, startRowIndex, numPerPage); + + ViewBag.totalCount = totalCount; + ViewBag.page = page; + ViewBag.pagesize = numPerPage; + ViewBag.cfg = cfg; + ViewBag.list = list; + + return View(entity); + } + #endregion + + #region 商品详情 + [HttpGet] + public IActionResult Detail(int id) + { + Product entity = Product.FindById(id); + if (entity == null || entity.IsHide == 1) + { + return EchoTip("系统找不到本记录!"); + } + //文章更多图片列表 + if (!string.IsNullOrEmpty(entity.ItemImg)) + { + string[] arrimg = entity.ItemImg.Split(new string[] { "|||" }, StringSplitOptions.None); + List listimg = new List(); + foreach (string s in arrimg) + { + if (!string.IsNullOrEmpty(s) && Utils.IsImgFilename(s)) + { + listimg.Add(s.Trim()); + } + } + ViewBag.ListImg = listimg; + } + entity.Hits++; + entity.Update(); + ViewBag.cfg = cfg; + ViewBag.category = entity.Category; + + return View(entity); + } + #endregion + } +} \ No newline at end of file diff --git a/COMCMS.Web/Controllers/ServerController.cs b/COMCMS.Web/Controllers/ServerController.cs new file mode 100644 index 0000000..fb27c5c --- /dev/null +++ b/COMCMS.Web/Controllers/ServerController.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using COMCMS.Common; +using COMCMS.Core; +using COMCMS.Core.Models; +using COMCMS.Web.Common; +using XCode; + +namespace COMCMS.Web.Controllers +{ + /// + /// 服务端处理 + /// + public class ServerController : HomeBaseController + { + #region 提交前台底部留言 + [HttpPost] + [AutoValidateAntiforgeryToken] + public IActionResult DoPostMessage(string name,string phone,string content) + { + if (string.IsNullOrWhiteSpace(name)) + { + tip.Message = "请填写您的姓名!"; + return Json(tip); + } + if (!Utils.IsTel(phone)) + { + tip.Message = "请填写正确的手机号码!"; + return Json(tip); + } + if (string.IsNullOrWhiteSpace(content)) + { + tip.Message = "请填写您的留言内容!"; + return Json(tip); + } + + Guestbook entity = new Guestbook() + { + AddTime = DateTime.Now, + IP = Utils.GetIP(), + KId = 1, + Nickname = name, + Content = Utils.NoHTML(content), + Tel = phone + }; + entity.Insert(); + + tip.Message = "留言成功,感谢您的留言!"; + tip.Status = JsonTip.SUCCESS; + return Json(tip); + } + #endregion + } +} \ No newline at end of file diff --git a/COMCMS.Web/Controllers/api/APIBaseController.cs b/COMCMS.Web/Controllers/api/APIBaseController.cs new file mode 100644 index 0000000..be9b404 --- /dev/null +++ b/COMCMS.Web/Controllers/api/APIBaseController.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using COMCMS.Common; +using COMCMS.Web.Common; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using NewLife.Log; + +// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 + +namespace COMCMS.Web.Controllers.api +{ + [Produces("application/json")] + [Route("api/[controller]/[action]")] + [WebAPIHandleError] + public class APIBaseController : Controller + { + public APIBaseController() + { + string url = MyHttpContext.Current.Request.Path; + string querystring = MyHttpContext.Current.Request.QueryString.ToString(); + //XTrace.WriteLine($"访问API:{url}?{querystring}"); + } + #region 通用信息 + public ReJSON reJson = new ReJSON() { code = 40000 }; + #endregion + + #region 验证签名 + public bool CheckSignature(SortedDictionary pars, string signature) + { + if (!MySign.CheckSign(pars, signature)) + { + reJson.code = 40004; + reJson.message = "signature 错误!"; + return false; + } + //判断是否超时 + string timeStamp = pars["timeStamp"]; + //判断时间有效性 + DateTime postTime = Utils.StampToDateTime(timeStamp); + if (postTime < DateTime.UtcNow.AddSeconds(-120))//30秒有效期 + { + reJson.code = 40004; + reJson.message = "数据请求超时!"; + reJson.isReload = 1; + return false; + } + return true; + } + + #endregion + + #region 自动验证QueryString 的签名 + /// + /// 自动验证QueryString 的签名 + /// + /// + public bool AutoCheckQueryStringSignature() + { + var queryStrings = Request.Query; + List keys = new List(); + //string[] keys = HttpContext.Current.Request.QueryString.AllKeys; + if (queryStrings == null) + { + return false; + } + foreach (var item in queryStrings.Keys) + { + keys.Add(item); + } + SortedDictionary pars = new SortedDictionary(); + string signature = ""; + foreach (var k in keys) + { + if (k != "signature") + { + string v = Request.Query[k]; + pars.Add(k, v); + } + else + { + signature = Request.Query[k]; + } + } + //没有签名返回错误 + if (string.IsNullOrEmpty(signature)) + return false; + return CheckSignature(pars, signature); + } + #endregion + } + + #region 通用返回信息 + public class ReJSON + { + /// + /// 返回代码 0 为正确 + /// + public int code { get; set; } = 40000; + + /// + /// 提示语 + /// + public string message { get; set; } + /// + /// 是否重新加载 + /// + public int isReload { get; set; } = 0; + + /// + /// 数据详情 object + /// + public object detail { get; set; } + } + #endregion +} diff --git a/COMCMS.Web/Controllers/api/ArticleController.cs b/COMCMS.Web/Controllers/api/ArticleController.cs new file mode 100644 index 0000000..3f4c115 --- /dev/null +++ b/COMCMS.Web/Controllers/api/ArticleController.cs @@ -0,0 +1,213 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using COMCMS.Common; +using COMCMS.Core; +using COMCMS.Core.Models; +using XCode; +using System.Web; +using COMCMS.Web.Filter; +using NewLife.Log; +using static COMCMS.Web.Models.APIModels; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Senparc.Weixin.WxOpen; + +namespace COMCMS.Web.Controllers.api +{ + public class ArticleController : APIBaseController + { + #region 获取文章列表 + /// + /// 获取文章列表 + /// + /// + /// + /// + /// + [HttpGet] + [CheckFilter] + public object GetArticleList(int kid, int pagesize = 10, int page = 1, string random = "", string timeStamp = "", string signature = "") + { + var where = Article._.IsHide != 1; + if (kid > 0) + where &= Article._.KId == kid; + + if (page <= 0) page = 1; + //计算分页 + int numPerPage, currentPage, startRowIndex; + + numPerPage = pagesize; + currentPage = page; + startRowIndex = (currentPage - 1) * numPerPage; + + IList
list = Article.FindAll(where, Article._.Sequence.Asc(), null, startRowIndex, numPerPage); + long totalCount = Article.FindCount(where, Article._.Sequence.Asc(), null, startRowIndex, numPerPage); + List relist = new List(); + if (list != null && list.Count > 0) + { + foreach (var item in list) + { + relist.Add(new + { + id = item.Id, + title = item.Title, + subTitle = item.SubTitle, + pic = item.Pic, + description = item.Description, + addTime = item.AddTime.ToString("yyyy-MM-dd HH:mm"), + origin = item.Origin + }); + } + } + dynamic re = new { total = totalCount, page = page, list = relist }; + + reJson.code = 0; + reJson.message = "获取成功"; + reJson.detail = re; + return reJson; + + } + #endregion + + #region 获取文章列表 + /// + /// 获取文章列表 + /// + /// + /// + /// + /// + [HttpGet] + [CheckFilter] + public object GetArticleListWidthSub(int kid, int pagesize = 10, int page = 1, string key = "", string random = "", string timeStamp = "", string signature = "") + { + + var where = Article._.IsHide != 1; + if (kid > 0) + { + //获取下属 + List kids = new List(); + kids.Add(kid); + IList subkinds = ArticleCategory.FindByParentID(kid); + if (subkinds != null && subkinds.Count > 0) + { + foreach (var item in subkinds) + { + kids.Add(item.Id); + } + } + where &= Article._.KId.In(kids); + } + if (!string.IsNullOrEmpty(key)) + { + where &= Article._.Title.Contains(key); + } + if (page <= 0) page = 1; + //计算分页 + int numPerPage, currentPage, startRowIndex; + + numPerPage = pagesize; + currentPage = page; + startRowIndex = (currentPage - 1) * numPerPage; + + IList
list = Article.FindAll(where, Article._.Sequence.Asc(), null, startRowIndex, numPerPage); + long totalCount = Article.FindCount(where, Article._.Sequence.Asc(), null, startRowIndex, numPerPage); + List relist = new List(); + if (list != null && list.Count > 0) + { + foreach (var item in list) + { + relist.Add(new + { + id = item.Id, + title = item.Title, + subTitle = item.SubTitle, + pic = item.Pic, + description = item.Description, + addTime = item.AddTime.ToString("yyyy-MM-dd HH:mm"), + origin = item.Origin + }); + } + } + dynamic re = new { total = totalCount, page = page, list = relist }; + + reJson.code = 0; + reJson.message = "获取成功"; + reJson.detail = re; + return reJson; + + } + #endregion + + #region 获取文章详情 + /// + /// 获取文章详情 + /// + /// 文章id + /// + /// + /// + /// + [HttpGet] + [CheckFilter] + public object GetArticleDetail(int id, string random = "", string timeStamp = "", string signature = "") + { + //获取商品 + Article entity = Article.FindById(id); + if (entity == null || entity.IsHide == 1) + { + reJson.code = 40000; + reJson.message = "系统找不到本记录"; + return reJson; + } + entity.Hits++; + entity.Update(); + return entity; + } + #endregion + + #region 获取文章栏目详情,并带下一级栏目 + [HttpGet] + [CheckFilter] + public object GetArticleCategory(int id, string random = "", string timeStamp = "", string signature = "") + { + ArticleCategory entity = ArticleCategory.FindById(id); + if (entity == null) + { + reJson.message = "系统找不到本记录"; + return reJson; + } + + //获取下属栏目 + IList listsub = ArticleCategory.FindAll(ArticleCategory._.PId == entity.Id & ArticleCategory._.IsHide == 0, ArticleCategory._.Rank.Asc(), null, 0, 0); + + List reListSubs = new List(); + if (listsub != null && listsub.Count > 0) + { + foreach (var item in listsub) + { + reListSubs.Add(new + { + kindName = item.KindName, + id = item.Id + }); + } + } + dynamic detail = new + { + category = entity, + sublist = reListSubs + }; + + reJson.code = 0; + reJson.message = "获取成功!"; + reJson.detail = detail; + return reJson; + } + #endregion + } +} diff --git a/COMCMS.Web/Controllers/api/ProductController.cs b/COMCMS.Web/Controllers/api/ProductController.cs new file mode 100644 index 0000000..322343f --- /dev/null +++ b/COMCMS.Web/Controllers/api/ProductController.cs @@ -0,0 +1,216 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using COMCMS.Common; +using COMCMS.Core; +using COMCMS.Core.Models; +using XCode; +using System.Web; +using COMCMS.Web.Filter; +using NewLife.Log; +using static COMCMS.Web.Models.APIModels; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Senparc.Weixin.WxOpen; + +// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 + +namespace COMCMS.Web.Controllers.api +{ + public class ProductController : APIBaseController + { + #region 获取分类列表 + /// + /// 获取分类列表 + /// + /// + /// + /// + /// + /// + /// + [HttpGet] + [CheckFilter] + public object GetCategories(int level, int pid = 0, string random = "", string timeStamp = "", string signature = "") + { + var list = Category.GetListTree(pid, level, false, false); + + List relist = new List(); + if (list != null && list.Count > 0) + { + foreach (var item in list) + { + relist.Add(new + { + id = item.Id, + kindName = item.KindName, + subTitle = item.SubTitle, + pic = item.Pic, + banner = item.BannerImg, + description = item.Description + }); + } + } + reJson.code = 0; + reJson.message = "获取成功"; + reJson.detail = relist; + return reJson; + } + #endregion + + #region 获取商品列表 + /// + /// 获取商品列表 + /// + /// 分类ID + /// 第几页 + /// 每页显示数量 + /// + /// + /// + /// + [HttpGet] + [CheckFilter] + public object GetProductList(int kid, int page, int pageSize = 10, string random = "", string timeStamp = "", string signature = "") + { + var where = Product._.IsHide == 0; + if (kid > 0) + where &= Product._.KId == kid; + + if (page <= 0) page = 1; + //计算分页 + int numPerPage, currentPage, startRowIndex; + + numPerPage = pageSize; + currentPage = page; + startRowIndex = (currentPage - 1) * numPerPage; + + IList list = Product.FindAll(where, Product._.Sequence.Asc(), null, startRowIndex, numPerPage); + long totalCount = Product.FindCount(where, Product._.Sequence.Asc(), null, startRowIndex, numPerPage); + List relist = new List(); + if (list != null && list.Count > 0) + { + foreach (var item in list) + { + relist.Add(new + { + id = item.Id, + title = item.Title, + subTitle = item.SubTitle, + price = item.Price, + marketPrice = item.MarketPrice, + pic = item.Pic, + description = item.Description, + stock = item.Stock, + addTime = item.AddTime.ToString("yyyy-MM-dd HH:mm") + }); + } + } + dynamic re = new { total = totalCount, page = page, list = relist }; + + reJson.code = 0; + reJson.message = "获取成功"; + reJson.detail = re; + return reJson; + } + #endregion + + #region 商品详情 + /// + /// 获取商品详情 + /// + /// 商品id + /// + /// + /// + /// + [HttpGet] + [CheckFilter] + public object GetProductDetail(int id, string random = "", string timeStamp = "", string signature = "") + { + //获取商品 + Product entity = Product.FindById(id); + if (entity == null || entity.IsHide == 1) + { + reJson.code = 40000; + reJson.message = "系统找不到本记录"; + return reJson; + } + entity.Hits++; + entity.Update(); + return entity; + } + #endregion + + #region 搜索商品 + /// + /// 获取商品列表 + /// + /// 关键字 + /// 第几页 + /// 每页显示数量 + /// + /// + /// + /// + [HttpGet] + [CheckFilter] + public object GetSearchProductList(string key, int page, int pageSize = 10, int kid = 0, string random = "", string timeStamp = "", string signature = "") + { + var where = Product._.IsHide == 0; + + if (kid != 0) + { + where &= Product._.KId == kid; + } + + if (!string.IsNullOrEmpty(key)) + { + key = Utils.NoHTML(key); + where &= Product._.Title.Contains(key); + } + + if (page <= 0) page = 1; + //计算分页 + int numPerPage, currentPage, startRowIndex; + + numPerPage = pageSize; + currentPage = page; + startRowIndex = (currentPage - 1) * numPerPage; + + IList list = Product.FindAll(where, Product._.Sequence.Asc(), null, startRowIndex, numPerPage); + long totalCount = Product.FindCount(where, Product._.Sequence.Asc(), null, startRowIndex, numPerPage); + List relist = new List(); + if (list != null && list.Count > 0) + { + foreach (var item in list) + { + relist.Add(new + { + id = item.Id, + title = item.Title, + subTitle = item.SubTitle, + price = item.Price, + marketPrice = item.MarketPrice, + pic = item.Pic, + description = item.Description, + stock = item.Stock, + addTime = item.AddTime.ToString("yyyy-MM-dd HH:mm") + }); + } + } + dynamic re = new { total = totalCount, page = page, list = relist }; + + reJson.code = 0; + reJson.message = "获取成功"; + reJson.detail = re; + return reJson; + } + #endregion + + + } +} diff --git a/COMCMS.Web/Controllers/wxpaymentController.cs b/COMCMS.Web/Controllers/wxpaymentController.cs index 0abb1ad..c6de522 100644 --- a/COMCMS.Web/Controllers/wxpaymentController.cs +++ b/COMCMS.Web/Controllers/wxpaymentController.cs @@ -126,6 +126,5 @@ namespace COMCMS.Web.Controllers } #endregion - public wxpaymentController(IConfiguration configuration) : base(configuration){} } } \ No newline at end of file diff --git a/COMCMS.Web/Filter/CheckFilter.cs b/COMCMS.Web/Filter/CheckFilter.cs index 70cd663..4996375 100644 --- a/COMCMS.Web/Filter/CheckFilter.cs +++ b/COMCMS.Web/Filter/CheckFilter.cs @@ -15,7 +15,7 @@ namespace COMCMS.Web.Filter { public class CheckFilterAttribute : ActionFilterAttribute { - public override async void OnActionExecuting(ActionExecutingContext context) + public override void OnActionExecuting(ActionExecutingContext context) { if (!context.ModelState.IsValid) { diff --git a/COMCMS.Web/Startup.cs b/COMCMS.Web/Startup.cs index fb57925..4451f8d 100644 --- a/COMCMS.Web/Startup.cs +++ b/COMCMS.Web/Startup.cs @@ -43,8 +43,11 @@ namespace COMCMS.Web // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { + // 注册菜单 + MenuRegister.Register(); + //注入自己的HttpContext - services.AddSingleton(); + //services.AddSingleton(); //services.AddMvc().AddSessionStateTempDataProvider(); //添加Configuration到静态变量 diff --git a/COMCMS.Web/Views/Article/Detail.cshtml b/COMCMS.Web/Views/Article/Detail.cshtml new file mode 100644 index 0000000..2314402 --- /dev/null +++ b/COMCMS.Web/Views/Article/Detail.cshtml @@ -0,0 +1,66 @@ +@model COMCMS.Core.Article +@{ + ViewBag.title = Model.Title; + ViewBag.keywords = Model.Keyword; + ViewBag.description = Model.Description; + IList
alist = Article.FindAll(Article._.KId == Model.KId, Article._.Sequence.Asc(), null, 0, 0); + int topkid = ViewBag.kind.PId >0? ViewBag.kind.PId : ViewBag.kind.Id; + +} + + + +
+
+
    + @foreach (Article a in alist) + { +
  • @a.Title
  • + } +
+ + +
+
+ +
+
+
+ @Html.Raw(Model.Content) +
+
+
+ diff --git a/COMCMS.Web/Views/Article/Detail_About.cshtml b/COMCMS.Web/Views/Article/Detail_About.cshtml new file mode 100644 index 0000000..4e6c641 --- /dev/null +++ b/COMCMS.Web/Views/Article/Detail_About.cshtml @@ -0,0 +1,65 @@ +@model COMCMS.Core.Article +@{ + ViewBag.title = Model.Title; + ViewBag.keywords = Model.Keyword; + ViewBag.description = Model.Description; + IList
alist = Article.FindAll(Article._.KId == Model.KId, Article._.Sequence.Asc(), null, 0, 0); + int topkid = ViewBag.kind.PId > 0 ? ViewBag.kind.PId : ViewBag.kind.Id; +} + + + +
+
+
    + @foreach (Article a in alist) + { +
  • @a.Title
  • + } +
+ + +
+
+ +
+
+
+ @Html.Raw(Model.Content) +
+
+
+ \ No newline at end of file diff --git a/COMCMS.Web/Views/Article/Detail_Contact.cshtml b/COMCMS.Web/Views/Article/Detail_Contact.cshtml new file mode 100644 index 0000000..9cbd3eb --- /dev/null +++ b/COMCMS.Web/Views/Article/Detail_Contact.cshtml @@ -0,0 +1,127 @@ +@model COMCMS.Core.Article +@{ + ViewBag.title = Model.Title; + ViewBag.keywords = Model.Keyword; + ViewBag.description = Model.Description; + IList
alist = Article.FindAll(Article._.KId == Model.KId, Article._.Sequence.Asc(), null, 0, 0); + int topkid = ViewBag.kind.PId > 0 ? ViewBag.kind.PId : ViewBag.kind.Id; + //获取同级分类 + IList sameList = ArticleCategory.FindAll(ArticleCategory._.PId == ViewBag.kind.PId, ArticleCategory._.Rank.Asc(), null, 0, 0); +} + + + + +
+
+
    + @foreach (var k in sameList) + { +
  • @k.KindName
  • + } +
+ + +
+
+ +
+
+
+
+ +
+ +
+ + +
+ +
+
+ COMCMS 内容管理系统 + COMCMS Technology Co.,Ltd +
+
+
    +
  • 电话:+86-20-88888888
  • +
  • 传真:+86-20-88888888
  • +
  • 邮箱:hogenwang@vip.qq.com
  • +
  • 地址:广东省广州市天河区天河城
  • +
+ +
+
+
+
+
+
+ + diff --git a/COMCMS.Web/Views/Article/Detail_News.cshtml b/COMCMS.Web/Views/Article/Detail_News.cshtml new file mode 100644 index 0000000..7ced4c2 --- /dev/null +++ b/COMCMS.Web/Views/Article/Detail_News.cshtml @@ -0,0 +1,88 @@ +@model COMCMS.Core.Article +@{ + ViewBag.title = Model.Title; + ViewBag.keywords = Model.Keyword; + ViewBag.description = Model.Description; + IList
alist = Article.FindAll(Article._.KId == Model.KId, Article._.Sequence.Asc(), null, 0, 0); + int topkid = ViewBag.kind.PId > 0 ? ViewBag.kind.PId : ViewBag.kind.Id; + //获取同级分类 + IList sameList = ArticleCategory.FindAll(ArticleCategory._.PId == ViewBag.kind.PId, ArticleCategory._.Rank.Asc(), null, 0, 0); + +} + + + +
+
+
    + @foreach (var k in sameList) + { +
  • @k.KindName
  • + } +
+ + +
+
+ +
+
+
+
+ @Model.Title + @Model.AddTime.ToString("yyyy-MM-dd HH:mm") +
+
+ @Html.Raw(Model.Content) +
+ + +
+ @*
+

+ 上一篇: +

+

+ 下一篇:已经最后一篇 +

+
*@ + [ 返回列表 ] +
+
+
+
+ + diff --git a/COMCMS.Web/Views/Article/Index.cshtml b/COMCMS.Web/Views/Article/Index.cshtml new file mode 100644 index 0000000..2217776 --- /dev/null +++ b/COMCMS.Web/Views/Article/Index.cshtml @@ -0,0 +1,104 @@ +@model COMCMS.Core.ArticleCategory +@{ + ViewBag.title = Model.KindName; + ViewBag.keywords = Model.Keyword; + ViewBag.description = Model.Description; + //获取同级分类 + IList sameList = ArticleCategory.FindAll(ArticleCategory._.PId == Model.PId, ArticleCategory._.Rank.Asc(), null, 0, 0); + int topkid = Model.PId > 0 ? Model.PId : Model.Id; +} + + + + +@if (Model.PId > 0) +{ +
+
+
    + @foreach (var k in sameList) + { +
  • @k.KindName
  • + } +
+ + +
+
+} + +
+
+
+ + +
+ @Html.Raw(Pages.GetPageStr(ViewBag.pagesize, (int)ViewBag.totalCount, ViewBag.page, $"/Article/Index/{Model.Id}" + "?page={0}", 99, 10, "")) +
+ +
+
+
+ + \ No newline at end of file diff --git a/COMCMS.Web/Views/Article/Index_Guestbook.cshtml b/COMCMS.Web/Views/Article/Index_Guestbook.cshtml new file mode 100644 index 0000000..9db2473 --- /dev/null +++ b/COMCMS.Web/Views/Article/Index_Guestbook.cshtml @@ -0,0 +1,83 @@ +@model COMCMS.Core.ArticleCategory +@{ + ViewBag.title = Model.KindName; + ViewBag.keywords = Model.Keyword; + ViewBag.description = Model.Description; + //获取同级分类 + IList sameList = ArticleCategory.FindAll(ArticleCategory._.PId == Model.PId, ArticleCategory._.Rank.Asc(), null, 0, 0); + int topkid = Model.PId > 0 ? Model.PId : Model.Id; +} + + + +@if (Model.PId > 0) +{ +
+
+
    + @foreach (var k in sameList) + { +
  • @k.KindName
  • + } +
+ + +
+
+} + + + +
+
+
+
+
+ 在线留言 +
+
+

+

+

+

+
+
+
+
+
+ + + \ No newline at end of file diff --git a/COMCMS.Web/Views/Home/Index.cshtml b/COMCMS.Web/Views/Home/Index.cshtml index 5fa8db5..d92ab5b 100644 --- a/COMCMS.Web/Views/Home/Index.cshtml +++ b/COMCMS.Web/Views/Home/Index.cshtml @@ -1,107 +1,487 @@ -@{ - Layout = null; - ViewData["Title"] = "Home Page"; +@using COMCMS.Core.Models +@{ + Config cfg = ViewBag.cfg; + ViewBag.title = string.IsNullOrEmpty(cfg.IndexTitle) ? cfg.SiteName : cfg.IndexTitle; + ViewBag.keywords = cfg.Keyword; + ViewBag.description = cfg.Description; + + Article about = ViewBag.about; + + IList listLinks = Link.FindAll(Link._.KId == 1, Link._.Sequence.Asc(), null, 0, 0); + + //处理bannr广告 + var bannerPC = Ads.GetSlideAds(1); + var bannerMobile = Ads.GetSlideAds(2); } -