diff --git a/OpenAuth.App/CategoryApp.cs b/OpenAuth.App/CategoryApp.cs
new file mode 100644
index 00000000..6cbf68ab
--- /dev/null
+++ b/OpenAuth.App/CategoryApp.cs
@@ -0,0 +1,85 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using OpenAuth.App;
+using OpenAuth.App.Request;
+using OpenAuth.App.Response;
+using OpenAuth.Repository.Domain;
+
+namespace LwSolution.App
+{
+ ///
+ /// 分类管理
+ ///
+ public class CategoryApp :BaseApp
+ {
+
+ public IEnumerable Get(string type)
+ {
+ return UnitWork.Find(u => u.TypeId == type);
+ }
+
+ public void Add(Category category)
+ {
+ if (string.IsNullOrEmpty(category.Id))
+ {
+ category.Id = Guid.NewGuid().ToString();
+ }
+ UnitWork.Add(category);
+ UnitWork.Save();
+ }
+
+ public void Update(Category category)
+ {
+ UnitWork.Update(u =>u.Id,category);
+ UnitWork.Save();
+ }
+
+
+ public void Delete(string[] ids)
+ {
+ UnitWork.Delete(u => ids.Contains(u.Id));
+ }
+
+
+ public TableData All(QueryCategoriesReq request)
+ {
+ var result = new TableData();
+ var categories = UnitWork.Find(null) ;
+ if (!string.IsNullOrEmpty(request.key))
+ {
+ categories = categories.Where(u => u.Name.Contains(request.key) || u.Id.Contains(request.key));
+ }
+
+ if (!string.IsNullOrEmpty(request.TypeId))
+ {
+ categories = categories.Where(u => u.TypeId == request.TypeId);
+ }
+
+ var query = from category in categories
+ join ct in UnitWork.Find(null) on category.TypeId equals ct.Id
+ into tmp
+ from ct in tmp.DefaultIfEmpty()
+ select new
+ {
+ category.Name,
+ category.Id,
+ category.TypeId,
+ TypeName = ct.Name,
+ category.Description
+ };
+
+ result.data = query.OrderBy(u => u.TypeId)
+ .Skip((request.page - 1) * request.limit)
+ .Take(request.limit).ToList();
+ result.count = categories.Count();
+ return result;
+ }
+
+ public List AllTypes()
+ {
+ return UnitWork.Find(null).ToList();
+
+ }
+ }
+}
\ No newline at end of file
diff --git a/OpenAuth.App/Extention/WF_RuntimeInitModel.cs b/OpenAuth.App/Extention/WF_RuntimeInitModel.cs
index f6f682ca..9f6696c8 100644
--- a/OpenAuth.App/Extention/WF_RuntimeInitModel.cs
+++ b/OpenAuth.App/Extention/WF_RuntimeInitModel.cs
@@ -1,6 +1,4 @@
-using System;
-
-namespace OpenAuth.App.Extention
+namespace OpenAuth.App.Extention
{
public class WF_RuntimeInitModel
diff --git a/OpenAuth.App/OpenAuth.App.csproj b/OpenAuth.App/OpenAuth.App.csproj
index 5bef9003..7c14f4f6 100644
--- a/OpenAuth.App/OpenAuth.App.csproj
+++ b/OpenAuth.App/OpenAuth.App.csproj
@@ -83,13 +83,16 @@
+
+
+
@@ -129,9 +132,7 @@
-
-
-
+
+
+
+
+
\ No newline at end of file
diff --git a/OpenAuth.Mvc/js/categories.js b/OpenAuth.Mvc/js/categories.js
new file mode 100644
index 00000000..036180fc
--- /dev/null
+++ b/OpenAuth.Mvc/js/categories.js
@@ -0,0 +1,153 @@
+layui.config({
+ base: "/js/"
+}).use(['form','vue', 'ztree', 'layer', 'jquery', 'table','droptree','openauth'], function () {
+ var form = layui.form,
+ //layer = (parent == undefined || parent.layer === undefined )? layui.layer : parent.layer,
+ layer = layui.layer,
+ $ = layui.jquery;
+ var table = layui.table;
+ var openauth = layui.openauth;
+ layui.droptree("/Categories/AllTypes", "#TypeName", "#TypeId", false);
+
+ //主列表加载,可反复调用进行刷新
+ var config= {}; //table的参数,如搜索key,点击tree的id
+ var mainList = function (options) {
+ if (options != undefined) {
+ $.extend(config, options);
+ }
+ table.reload('mainList', {
+ url: '/Categories/All',
+ where: config
+ });
+ }
+ //左边树状机构列表
+ var ztree = function () {
+ var url = '/Categories/AllTypes';
+ var zTreeObj;
+ var setting = {
+ view: { selectedMulti: false },
+ data: {
+ key: {
+ name: 'Name',
+ title: 'Name'
+ },
+ simpleData: {
+ enable: true,
+ idKey: 'Id',
+ pIdKey: 'ParentId',
+ rootPId: 'null'
+ }
+ },
+ callback: {
+ onClick: function (event, treeId, treeNode) {
+ mainList({ typeId: treeNode.Id });
+ }
+ }
+ };
+ var load = function () {
+ $.getJSON(url, function (json) {
+ zTreeObj = $.fn.zTree.init($("#tree"), setting, json);
+ mainList({ typeId: json[0].Id });
+ zTreeObj.expandAll(true);
+ });
+ };
+ load();
+ return {
+ reload: load
+ }
+ }();
+
+ //添加(编辑)对话框
+ var editDlg = function() {
+ var vm = new Vue({
+ el: "#formEdit"
+ });
+ var update = false; //是否为更新
+ var show = function (data) {
+ var title = update ? "编辑信息" : "添加";
+ layer.open({
+ title: title,
+ area: ["500px", "400px"],
+ type: 1,
+ content: $('#divEdit'),
+ success: function() {
+ vm.$set('$data', data);
+ },
+ end: mainList
+ });
+ var url = "/Categories/Add";
+ if (update) {
+ url = "/Categories/Update"; //暂时和添加一个地址
+ }
+ //提交数据
+ form.on('submit(formSubmit)',
+ function(data) {
+ $.post(url,
+ data.field,
+ function(data) {
+ layer.msg(data.Message);
+ },
+ "json");
+ return false;
+ });
+ }
+ return {
+ add: function() { //弹出添加
+ update = false;
+ show({
+ Id: ''
+ });
+ },
+ update: function(data) { //弹出编辑框
+ update = true;
+ show(data);
+ }
+ };
+ }();
+
+ //监听表格内部按钮
+ table.on('tool(list)', function (obj) {
+ var data = obj.data;
+ if (obj.event === 'detail') { //查看
+ layer.msg('ID:' + data.Id + ' 的查看操作');
+ }
+ });
+
+
+ //监听页面主按钮操作
+ var active = {
+ btnDel: function () { //批量删除
+ var checkStatus = table.checkStatus('mainList')
+ , data = checkStatus.data;
+ openauth.del("/Categories/Delete",
+ data.map(function (e) { return e.Id; }),
+ mainList);
+ }
+ , btnAdd: function () { //添加
+ editDlg.add();
+ }
+ , btnEdit: function () { //编辑
+ var checkStatus = table.checkStatus('mainList')
+ , data = checkStatus.data;
+ if (data.length != 1) {
+ layer.msg("请选择编辑的行,且同时只能编辑一行");
+ return;
+ }
+ editDlg.update(data[0]);
+ }
+
+ , search: function () { //搜索
+ mainList({ key: $('#key').val() });
+ }
+ , btnRefresh: function() {
+ mainList();
+ }
+ };
+
+ $('.toolList .layui-btn').on('click', function () {
+ var type = $(this).data('type');
+ active[type] ? active[type].call(this) : '';
+ });
+
+ //监听页面主按钮操作 end
+})
\ No newline at end of file
diff --git a/OpenAuth.Repository/BaseRepository.cs b/OpenAuth.Repository/BaseRepository.cs
index 28c99e8d..161d0caf 100644
--- a/OpenAuth.Repository/BaseRepository.cs
+++ b/OpenAuth.Repository/BaseRepository.cs
@@ -62,7 +62,10 @@ namespace OpenAuth.Repository
public void Add(T entity)
{
- entity.Id = Guid.NewGuid().ToString();
+ if (string.IsNullOrEmpty(entity.Id))
+ {
+ entity.Id = Guid.NewGuid().ToString();
+ }
Context.Set().Add(entity);
Save();
}
diff --git a/OpenAuth.Repository/UnitWork.cs b/OpenAuth.Repository/UnitWork.cs
index 489f908d..12c3addf 100644
--- a/OpenAuth.Repository/UnitWork.cs
+++ b/OpenAuth.Repository/UnitWork.cs
@@ -62,7 +62,10 @@ namespace OpenAuth.Repository
public void Add(T entity) where T : Domain.Entity
{
- entity.Id = Guid.NewGuid().ToString();
+ if (string.IsNullOrEmpty(entity.Id))
+ {
+ entity.Id = Guid.NewGuid().ToString();
+ }
Context.Set().Add(entity);
}