diff --git a/CodeSmith/Add.cshtml.cst b/CodeSmith/Add.cshtml.cst index 2cf8b971..6c1dab2b 100644 --- a/CodeSmith/Add.cshtml.cst +++ b/CodeSmith/Add.cshtml.cst @@ -1,148 +1,145 @@ -<%-- -Name: Database Table Properties -Author: Paul Welter -Description: Create a list of properties from a database table ---%> -<%@ CodeTemplate Language="C#" TargetLanguage="C#" Debug="False" Encoding="utf-8" Description="添加模块" %> -<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" -Description="连接的数据库" %> -<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %> -<%@ Property Name="NeedViewModel" Type="Boolean" Category="Context" Default="False" Description="是否需要ViewModel" %> -<%@ Property Name="CascadeId" Type="String" Category="" Default="ParentId" Description="级联字段" %> -<%@ Property Name="CascadeName" Type="String" Category="" Default="ParentName" Description="级联显示的文字" %> -<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %> -<%@ Assembly Name="SchemaExplorer" %> -<%@ Import Namespace="SchemaExplorer" %> - -<%if(NeedViewModel){ %> -@model OpenAuth.App.ViewModel.<%=GetModelName()%> -<%} else{ %> -@model OpenAuth.Domain.<%=GetModelName()%> -<%} %> -@{ - ViewBag.Title = "<%=GetModelName()%>编辑界面"; - Layout = null; -} - -
-
- - - - - - <% foreach (ColumnSchema column in this.SourceTable.Columns) { - if(column.Name == CascadeName) continue; - %> - - - - <% } %> - -

* 添加

- <%if(column.IsPrimaryKeyMember){ %> - @Html.HiddenFor(m =>m.Id) - <% } else if(column.Name == CascadeId) {%> - - - -
    - - <% } else if(CSharpAlias[column.SystemType.FullName] == "bool") {%> - - - - <%} else if(CSharpAlias[column.SystemType.FullName] == "int") {%> - - - <%} else{%> - - - <%} %> -
    -
    -
    - - - +<%if(NeedViewModel){ %> +@model OpenAuth.App.ViewModel.<%=GetModelName()%> +<%} else{ %> +@model OpenAuth.Domain.<%=GetModelName()%> +<%} %> +@{ + ViewBag.Title = "<%=GetModelName()%>编辑界面"; + Layout = null; +} + +
    +
    + + + <% foreach (ColumnSchema column in this.SourceTable.Columns) { + if(column.Name == CascadeName) continue; + %> + + + + <% } %> + +
    + <%if(column.IsPrimaryKeyMember){ %> + @Html.HiddenFor(m =>m.Id) + <% } else if(column.Name == CascadeId) {%> + + + +
      + + <% } else if(CSharpAlias[column.SystemType.FullName] == "bool") {%> + + + + <%} else if(CSharpAlias[column.SystemType.FullName] == "int") {%> + + + <%} else{%> + + + <%} %> +
      +
      +
      + + + \ No newline at end of file diff --git a/CodeSmith/Application.cst b/CodeSmith/Application.cst index 7d3e6d7a..0ae0fbb7 100644 --- a/CodeSmith/Application.cst +++ b/CodeSmith/Application.cst @@ -1,131 +1,131 @@ -<%-- -Name: Database Table Properties -Author: Paul Welter -Description: Create a list of properties from a database table ---%> -<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="False" Description="应用层" %> -<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %> -<%@ Property Name="NeedViewModel" Type="Boolean" Category="Context" Default="False" Description="是否需要ViewModel" %> -<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %> -<%@ Assembly Name="SchemaExplorer" %> -<%@ Import Namespace="SchemaExplorer" %> - - -<%if(NeedViewModel){ %> -using OpenAuth.App.ViewModel; -<%} %> -using OpenAuth.Domain; -using OpenAuth.Domain.Interface; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace OpenAuth.App -{ - public class <%=ModuleName%>ManagerApp - { - private I<%=ModuleName%>Repository _repository; - private IOrgRepository _orgRepository; - - public <%=ModuleName%>ManagerApp(I<%=ModuleName%>Repository repository, - IOrgRepository orgRepository) - { - _repository = repository; - _orgRepository = orgRepository; - } - - public int Get<%=GetModelName()%>CntInOrg(int orgId) - { - if (orgId == 0) - { - return _repository.Find(null).Count(); - } - else - { - return _repository.Get<%=GetModelName()%>CntInOrgs(GetSubOrgIds(orgId)); - } - } - - /// - /// 加载一个部门及子部门全部<%=GetModelName()%>s - /// - public dynamic Load(int orgId, int pageindex, int pagesize) - { - IEnumerable<<%=ModuleName%>> <%=ModuleName%>s; - int total = 0; - if (orgId == 0) - { - <%=ModuleName%>s = _repository.Load<%=ModuleName%>s(pageindex, pagesize); - total = _repository.GetCount(); - } - else - { - <%=ModuleName%>s = _repository.LoadInOrgs(pageindex, pagesize,GetSubOrgIds(orgId)); - total = _repository.Get<%=ModuleName%>CntInOrgs(orgId); - } - <%if(NeedViewModel){ %> - var <%=ModuleName%>views = new List<<%=ModuleName%>View>(); - foreach (var <%=ModuleName%> in <%=ModuleName%>s) - { - <%=ModuleName%>View uv = <%=ModuleName%>; - uv.Organizations = string.Join(",", _orgRepository.LoadBy<%=ModuleName%>(<%=ModuleName%>.Id).Select(u => u.Name).ToList()); - <%=ModuleName%>views.Add(uv); - } - <%} %> - - return new - { - total = total, - list = <%=GetModelName()%>s, - pageCurrent = pageindex - }; - } - - /// - /// 获取当前组织的所有下级组织 - /// - private int[] GetSubOrgIds(int orgId) - { - var org = _orgRepository.FindSingle(u => u.Id == orgId); - var orgs = _orgRepository.Find(u => u.CascadeId.Contains(org.CascadeId)).Select(u => u.Id).ToArray(); - return orgs; - } - - public <%=GetModelName()%> Find(int id) - { - var <%=ModuleName.ToLower()%> = _repository.FindSingle(u => u.Id == id); - if (<%=ModuleName.ToLower()%> == null) return new <%=GetModelName()%>(); - - return <%=ModuleName.ToLower() %>; - } - - public void Delete(int id) - { - _repository.Delete(id); - } - - public void AddOrUpdate(<%=GetModelName()%> model) - { - <%=ModuleName%> <%=ModuleName.ToLower()%> = model; - if (<%=ModuleName.ToLower()%>.Id == 0) - { - _repository.Add(<%=ModuleName.ToLower()%>); - } - else - { - _repository.Update(<%=ModuleName.ToLower()%>); - } - - } - - - } +<%-- +Name: Database Table Properties +Author: Paul Welter +Description: Create a list of properties from a database table +--%> +<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="False" Description="应用层" %> +<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %> +<%@ Property Name="NeedViewModel" Type="Boolean" Category="Context" Default="False" Description="是否需要ViewModel" %> +<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %> +<%@ Assembly Name="SchemaExplorer" %> +<%@ Import Namespace="SchemaExplorer" %> + + +<%if(NeedViewModel){ %> +using OpenAuth.App.ViewModel; +<%} %> +using OpenAuth.Domain; +using OpenAuth.Domain.Interface; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenAuth.App +{ + public class <%=ModuleName%>ManagerApp + { + private I<%=ModuleName%>Repository _repository; + private IOrgRepository _orgRepository; + + public <%=ModuleName%>ManagerApp(I<%=ModuleName%>Repository repository, + IOrgRepository orgRepository) + { + _repository = repository; + _orgRepository = orgRepository; + } + + public int Get<%=GetModelName()%>CntInOrg(int orgId) + { + if (orgId == 0) + { + return _repository.Find(null).Count(); + } + else + { + return _repository.Get<%=GetModelName()%>CntInOrgs(GetSubOrgIds(orgId)); + } + } + + /// + /// 加载一个部门及子部门全部<%=GetModelName()%>s + /// + public dynamic Load(int orgId, int pageindex, int pagesize) + { + IEnumerable<<%=ModuleName%>> <%=ModuleName%>s; + int total = 0; + if (orgId == 0) + { + <%=ModuleName%>s = _repository.Load<%=ModuleName%>s(pageindex, pagesize); + total = _repository.GetCount(); + } + else + { + <%=ModuleName%>s = _repository.LoadInOrgs(pageindex, pagesize,GetSubOrgIds(orgId)); + total = _repository.Get<%=ModuleName%>CntInOrgs(orgId); + } + <%if(NeedViewModel){ %> + var <%=ModuleName%>views = new List<<%=ModuleName%>View>(); + foreach (var <%=ModuleName%> in <%=ModuleName%>s) + { + <%=ModuleName%>View uv = <%=ModuleName%>; + uv.Organizations = string.Join(",", _orgRepository.LoadBy<%=ModuleName%>(<%=ModuleName%>.Id).Select(u => u.Name).ToList()); + <%=ModuleName%>views.Add(uv); + } + <%} %> + + return new + { + total = total, + list = <%=GetModelName()%>s, + pageCurrent = pageindex + }; + } + + /// + /// 获取当前组织的所有下级组织 + /// + private int[] GetSubOrgIds(int orgId) + { + var org = _orgRepository.FindSingle(u => u.Id == orgId); + var orgs = _orgRepository.Find(u => u.CascadeId.Contains(org.CascadeId)).Select(u => u.Id).ToArray(); + return orgs; + } + + public <%=GetModelName()%> Find(int id) + { + var <%=ModuleName.ToLower()%> = _repository.FindSingle(u => u.Id == id); + if (<%=ModuleName.ToLower()%> == null) return new <%=GetModelName()%>(); + + return <%=ModuleName.ToLower() %>; + } + + public void Delete(int id) + { + _repository.Delete(id); + } + + public void AddOrUpdate(<%=GetModelName()%> model) + { + <%=ModuleName%> <%=ModuleName.ToLower()%> = model; + if (<%=ModuleName.ToLower()%>.Id == 0) + { + _repository.Add(<%=ModuleName.ToLower()%>); + } + else + { + _repository.Update(<%=ModuleName.ToLower()%>); + } + + } + + + } } \ No newline at end of file diff --git a/CodeSmith/Controller.cst b/CodeSmith/Controller.cst index 9b88dd88..b8a51bd5 100644 --- a/CodeSmith/Controller.cst +++ b/CodeSmith/Controller.cst @@ -1,102 +1,95 @@ -<%-- -Name: Database Table Properties -Author: Paul Welter -Description: Create a list of properties from a database table ---%> -<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="False" Description="控制器" %> -<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %> -<%@ Property Name="NeedViewModel" Type="Boolean" Category="Context" Default="False" Description="是否需要ViewModel" %> -<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %> -<%@ Assembly Name="SchemaExplorer" %> -<%@ Import Namespace="SchemaExplorer" %> - - -using System; -using System.Web.Mvc; -using Infrastructure; -using OpenAuth.App; -<%if(NeedViewModel){ %> -using OpenAuth.App.ViewModel; -<%} %> - -namespace OpenAuth.Mvc.Controllers -{ - public class <%=ModuleName%>ManagerController : BaseController - { - private <%=ModuleName%>ManagerApp _app; - - public <%=ModuleName%>ManagerController() - { - _app = (<%=ModuleName%>ManagerApp)DependencyResolver.Current.GetService(typeof(<%=ModuleName%>ManagerApp)); - } - - // - // GET: /<%=ModuleName%>Manager/ - public ActionResult Index() - { - return View(); - } - - public ActionResult Add(int id = 0) - { - return View(_app.Find(id)); - } - - //添加或修改组织 - [HttpPost] - public string Add(<%=GetModelName()%> model) - { - try - { - _app.AddOrUpdate(model); - - } - catch (Exception ex) - { - BjuiResponse.statusCode = "300"; - BjuiResponse.message = ex.Message; - } - return JsonHelper.Instance.Serialize(BjuiResponse); - } - - /// - /// 加载组织下面的所有用户 - /// - public string Load(int orgId, int pageCurrent = 1, int pageSize = 30) - { - return JsonHelper.Instance.Serialize(_app.Load(orgId, pageCurrent, pageSize)); - } - - //获取组织下面用户个数 - public int GetCount(int orgId) - { - return _app.Get<%=GetModelName()%>CntInOrg(orgId); - } - - public string Delete(string Id) - { - try - { - foreach (var obj in Id.Split(',')) - { - _app.Delete(int.Parse(obj)); - } - } - catch (Exception e) - { - BjuiResponse.statusCode = "300"; - BjuiResponse.message = e.Message; - } - - return JsonHelper.Instance.Serialize(BjuiResponse); - } - } +<%-- +Name: Database Table Properties +Author: Paul Welter +Description: Create a list of properties from a database table +--%> +<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="False" Description="控制器" %> +<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %> +<%@ Property Name="NeedViewModel" Type="Boolean" Category="Context" Default="False" Description="是否需要ViewModel" %> +<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %> +<%@ Assembly Name="SchemaExplorer" %> +<%@ Import Namespace="SchemaExplorer" %> + + +using System; +using System.Web.Mvc; +using Infrastructure; +using OpenAuth.App; +<%if(NeedViewModel){ %> +using OpenAuth.App.ViewModel; +<%} %> + +namespace OpenAuth.Mvc.Controllers +{ + public class <%=ModuleName%>ManagerController : BaseController + { + private <%=ModuleName%>ManagerApp _app; + + public <%=ModuleName%>ManagerController() + { + _app = (<%=ModuleName%>ManagerApp)DependencyResolver.Current.GetService(typeof(<%=ModuleName%>ManagerApp)); + } + + // + // GET: /UserManager/ + public ActionResult Index() + { + return View(); + } + + public ActionResult Add(int id = 0) + { + return View(_app.Find(id)); + } + + //添加或修改<%=ModuleName %> + [HttpPost] + public string Add(<%=GetModelName()%> model) + { + try + { + _app.AddOrUpdate(model); + + } + catch (Exception ex) + { + BjuiResponse.statusCode = "300"; + BjuiResponse.message = ex.Message; + } + return JsonHelper.Instance.Serialize(BjuiResponse); + } + + /// + /// 加载组织下面的所有用户 + /// + public string Load(int orgId, int pageCurrent = 1, int pageSize = 30) + { + return JsonHelper.Instance.Serialize(_app.Load(orgId, pageCurrent, pageSize)); + } + + public string Delete(int Id) + { + try + { + _app.Delete(Id); + } + catch (Exception e) + { + BjuiResponse.statusCode = "300"; + BjuiResponse.message = e.Message; + } + + return JsonHelper.Instance.Serialize(BjuiResponse); + } + + + } } \ No newline at end of file diff --git a/CodeSmith/IRepository.cst b/CodeSmith/IRepository.cst index 4e1ec96c..4be8b648 100644 --- a/CodeSmith/IRepository.cst +++ b/CodeSmith/IRepository.cst @@ -1,28 +1,28 @@ -<%-- -Name: Database Table Properties -Author: Paul Welter -Description: Create a list of properties from a database table ---%> -<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="False" Description="创建包含组织机构的接口" %> -<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %> -<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %> -<%@ Assembly Name="SchemaExplorer" %> -<%@ Import Namespace="SchemaExplorer" %> - -using System.Collections.Generic; -using System.Linq; - -namespace OpenAuth.Domain.Interface -{ - public interface I<%=ModuleName%>Repository :IRepository<<%=ModuleName%>> - { - IEnumerable<<%=ModuleName%>> Load<%=ModuleName%>s(int pageindex, int pagesize); - - IEnumerable<<%=ModuleName%>> LoadInOrgs(params int[] orgId); - int Get<%=ModuleName%>CntInOrgs(params int[] orgIds); - IEnumerable<<%=ModuleName%>> LoadInOrgs(int pageindex, int pagesize, params int[] orgIds); - - void Delete(int id); - - } +<%-- +Name: Database Table Properties +Author: Paul Welter +Description: Create a list of properties from a database table +--%> +<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="False" Description="创建包含组织机构的接口" %> +<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %> +<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %> +<%@ Assembly Name="SchemaExplorer" %> +<%@ Import Namespace="SchemaExplorer" %> + +using System.Collections.Generic; +using System.Linq; + +namespace OpenAuth.Domain.Interface +{ + public interface I<%=ModuleName%>Repository :IRepository<<%=ModuleName%>> + { + IEnumerable<<%=ModuleName%>> Load<%=ModuleName%>s(int pageindex, int pagesize); + + IEnumerable<<%=ModuleName%>> LoadInOrgs(params int[] orgId); + int Get<%=ModuleName%>CntInOrgs(params int[] orgIds); + IEnumerable<<%=ModuleName%>> LoadInOrgs(int pageindex, int pagesize, params int[] orgIds); + + void Delete(int id); + + } } \ No newline at end of file diff --git a/CodeSmith/Index.cshtml.cst b/CodeSmith/Index.cshtml.cst index 5396b131..0a8f6712 100644 --- a/CodeSmith/Index.cshtml.cst +++ b/CodeSmith/Index.cshtml.cst @@ -1,170 +1,148 @@ -<%-- -Name: Database Table Properties -Author: Paul Welter -Description: Create a list of properties from a database table ---%> -<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="True" Description="Create a list of properties from database table." %> -<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="Table that the object is based on." %> -<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %> -<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %> -<%@ Assembly Name="SchemaExplorer" %> -<%@ Import Namespace="SchemaExplorer" %> - -@{ - string _prefix = "<%=ModuleName%>"; - var _treeId = _prefix + "Tree"; - var _gridId = _prefix + "Grid"; - var _treeDetail = _prefix + "Detail"; -} -
      -
      -
      -
        -
        - -
        -
        -
        -
        - - - +<%-- +Name: Database Table Properties +Author: Paul Welter +Description: Create a list of properties from a database table +--%> +<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="True" Description="Create a list of properties from database table." %> +<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="Table that the object is based on." %> +<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %> +<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %> +<%@ Assembly Name="SchemaExplorer" %> +<%@ Import Namespace="SchemaExplorer" %> + +@{ + string _prefix = "<%=ModuleName%>"; + var _treeId = _prefix + "Tree"; + var _gridId = _prefix + "Grid"; + var _treeDetail = _prefix + "Detail"; +} + +@{ Html.RenderAction("MenuHeader", "Home");} +
        +
        +
        +
          +
          + +
          +
          +
          +
          + + + diff --git a/OpenAuth.App/CategoryManagerApp.cs b/OpenAuth.App/CategoryManagerApp.cs new file mode 100644 index 00000000..3cb1b1f1 --- /dev/null +++ b/OpenAuth.App/CategoryManagerApp.cs @@ -0,0 +1,99 @@ + +using OpenAuth.Domain; +using OpenAuth.Domain.Interface; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenAuth.App +{ + public class CategoryManagerApp + { + private ICategoryRepository _repository; + private IOrgRepository _orgRepository; + + public CategoryManagerApp(ICategoryRepository repository, + IOrgRepository orgRepository) + { + _repository = repository; + _orgRepository = orgRepository; + } + + public int GetCategoryCntInOrg(int orgId) + { + if (orgId == 0) + { + return _repository.Find(null).Count(); + } + else + { + return _repository.GetCategoryCntInOrgs(GetSubOrgIds(orgId)); + } + } + + /// + /// 加载一个部门及子部门全部Categorys + /// + public dynamic Load(int orgId, int pageindex, int pagesize) + { + IEnumerable Categorys; + int total = 0; + if (orgId == 0) + { + Categorys = _repository.LoadCategorys(pageindex, pagesize); + total = _repository.GetCount(); + } + else + { + Categorys = _repository.LoadInOrgs(pageindex, pagesize,GetSubOrgIds(orgId)); + total = _repository.GetCategoryCntInOrgs(orgId); + } + + return new + { + total = total, + list = Categorys, + pageCurrent = pageindex + }; + } + + /// + /// 获取当前组织的所有下级组织 + /// + private int[] GetSubOrgIds(int orgId) + { + var org = _orgRepository.FindSingle(u => u.Id == orgId); + var orgs = _orgRepository.Find(u => u.CascadeId.Contains(org.CascadeId)).Select(u => u.Id).ToArray(); + return orgs; + } + + public Category Find(int id) + { + var category = _repository.FindSingle(u => u.Id == id); + if (category == null) return new Category(); + + return category; + } + + public void Delete(int id) + { + _repository.Delete(id); + } + + public void AddOrUpdate(Category model) + { + Category category = model; + if (category.Id == 0) + { + _repository.Add(category); + } + else + { + _repository.Update(category); + } + + } + + + } +} \ No newline at end of file diff --git a/OpenAuth.App/OpenAuth.App.csproj b/OpenAuth.App/OpenAuth.App.csproj index 1eaf6be2..5ec499cd 100644 --- a/OpenAuth.App/OpenAuth.App.csproj +++ b/OpenAuth.App/OpenAuth.App.csproj @@ -43,6 +43,7 @@ + diff --git a/OpenAuth.Domain/Interface/ICategoryRepository.cs b/OpenAuth.Domain/Interface/ICategoryRepository.cs new file mode 100644 index 00000000..a3b5a269 --- /dev/null +++ b/OpenAuth.Domain/Interface/ICategoryRepository.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; +using System.Linq; + +namespace OpenAuth.Domain.Interface +{ + public interface ICategoryRepository :IRepository + { + IEnumerable LoadCategorys(int pageindex, int pagesize); + + IEnumerable LoadInOrgs(params int[] orgId); + int GetCategoryCntInOrgs(params int[] orgIds); + IEnumerable LoadInOrgs(int pageindex, int pagesize, params int[] orgIds); + + void Delete(int id); + + } +} \ No newline at end of file diff --git a/OpenAuth.Domain/OpenAuth.Domain.csproj b/OpenAuth.Domain/OpenAuth.Domain.csproj index c83af34b..510ab64f 100644 --- a/OpenAuth.Domain/OpenAuth.Domain.csproj +++ b/OpenAuth.Domain/OpenAuth.Domain.csproj @@ -46,6 +46,7 @@ + diff --git a/OpenAuth.Mvc/Controllers/CategoryManagerController.cs b/OpenAuth.Mvc/Controllers/CategoryManagerController.cs new file mode 100644 index 00000000..f52fffed --- /dev/null +++ b/OpenAuth.Mvc/Controllers/CategoryManagerController.cs @@ -0,0 +1,73 @@ + +using System; +using System.Web.Mvc; +using Infrastructure; +using OpenAuth.App; +using OpenAuth.Domain; + +namespace OpenAuth.Mvc.Controllers +{ + public class CategoryManagerController : BaseController + { + private CategoryManagerApp _app; + + public CategoryManagerController() + { + _app = (CategoryManagerApp)DependencyResolver.Current.GetService(typeof(CategoryManagerApp)); + } + + // + // GET: /UserManager/ + public ActionResult Index() + { + return View(); + } + + public ActionResult Add(int id = 0) + { + return View(_app.Find(id)); + } + + //添加或修改Category + [HttpPost] + public string Add(Category model) + { + try + { + _app.AddOrUpdate(model); + + } + catch (Exception ex) + { + BjuiResponse.statusCode = "300"; + BjuiResponse.message = ex.Message; + } + return JsonHelper.Instance.Serialize(BjuiResponse); + } + + /// + /// 加载组织下面的所有用户 + /// + public string Load(int orgId, int pageCurrent = 1, int pageSize = 30) + { + return JsonHelper.Instance.Serialize(_app.Load(orgId, pageCurrent, pageSize)); + } + + public string Delete(int Id) + { + try + { + _app.Delete(Id); + } + catch (Exception e) + { + BjuiResponse.statusCode = "300"; + BjuiResponse.message = e.Message; + } + + return JsonHelper.Instance.Serialize(BjuiResponse); + } + + + } +} \ No newline at end of file diff --git a/OpenAuth.Mvc/OpenAuth.Mvc.csproj b/OpenAuth.Mvc/OpenAuth.Mvc.csproj index 25b69ca3..6a66c47f 100644 --- a/OpenAuth.Mvc/OpenAuth.Mvc.csproj +++ b/OpenAuth.Mvc/OpenAuth.Mvc.csproj @@ -20,6 +20,7 @@ enabled disabled + true @@ -125,6 +126,7 @@ + @@ -554,6 +556,8 @@ + + diff --git a/OpenAuth.Mvc/Views/CategoryManager/Add.cshtml b/OpenAuth.Mvc/Views/CategoryManager/Add.cshtml new file mode 100644 index 00000000..725bf3fb --- /dev/null +++ b/OpenAuth.Mvc/Views/CategoryManager/Add.cshtml @@ -0,0 +1,143 @@ +@model OpenAuth.Domain.Category +@{ + ViewBag.Title = "Category编辑界面"; + Layout = null; +} + +
          +
          + + + + + + + + + + + + + + + + + + + + + + + + + + + +
          + @Html.HiddenFor(m =>m.Id) +
          + + +
          + + +
          + + + +
            + +
            + + +
            + + +
            + + +
            + + +
            +
            +
            + + + \ No newline at end of file diff --git a/OpenAuth.Mvc/Views/CategoryManager/Index.cshtml b/OpenAuth.Mvc/Views/CategoryManager/Index.cshtml new file mode 100644 index 00000000..45ae8199 --- /dev/null +++ b/OpenAuth.Mvc/Views/CategoryManager/Index.cshtml @@ -0,0 +1,162 @@ +@{ + string _prefix = "Category"; + var _treeId = _prefix + "Tree"; + var _gridId = _prefix + "Grid"; + var _treeDetail = _prefix + "Detail"; +} + +@{ Html.RenderAction("MenuHeader", "Home");} +
            +
            +
            +
              +
              + +
              +
              +
              +
              + + + diff --git a/OpenAuth.Repository/CategoryRepository.cs b/OpenAuth.Repository/CategoryRepository.cs new file mode 100644 index 00000000..3cddcb27 --- /dev/null +++ b/OpenAuth.Repository/CategoryRepository.cs @@ -0,0 +1,39 @@ +using System.Collections.Generic; +using System.Linq; +using OpenAuth.Domain; +using OpenAuth.Domain.Interface; + +namespace OpenAuth.Repository +{ + public class CategoryRepository :BaseRepository, ICategoryRepository + { + + public IEnumerable LoadCategorys(int pageindex, int pagesize) + { + return Context.Categories.OrderBy(u => u.Id).Skip((pageindex - 1) * pagesize).Take(pagesize); + } + + public IEnumerable LoadInOrgs(params int[] orgId) + { + var result = from category in Context.Categories where orgId.Contains(category.Id) + select category; + return result; + + } + + public int GetCategoryCntInOrgs(params int[] orgIds) + { + return LoadInOrgs(orgIds).Count(); + } + + public IEnumerable LoadInOrgs(int pageindex, int pagesize, params int[] orgIds) + { + return LoadInOrgs(orgIds).OrderBy(u =>u.Id).Skip((pageindex -1)*pagesize).Take(pagesize); + } + + public void Delete(int id) + { + Delete(u =>u.Id == id); + } + } +} diff --git a/OpenAuth.Repository/OpenAuth.Repository.csproj b/OpenAuth.Repository/OpenAuth.Repository.csproj index c1e1379e..d9f1f7c2 100644 --- a/OpenAuth.Repository/OpenAuth.Repository.csproj +++ b/OpenAuth.Repository/OpenAuth.Repository.csproj @@ -72,6 +72,7 @@ +