mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-07-19 07:44:59 +08:00
Routine update
This commit is contained in:
parent
e4f4c03389
commit
e4305be038
@ -60,6 +60,7 @@
|
|||||||
<Compile Include="JsonConverter.cs" />
|
<Compile Include="JsonConverter.cs" />
|
||||||
<Compile Include="JsonHelper.cs" />
|
<Compile Include="JsonHelper.cs" />
|
||||||
<Compile Include="LogHelper.cs" />
|
<Compile Include="LogHelper.cs" />
|
||||||
|
<Compile Include="ObjectHelper.cs" />
|
||||||
<Compile Include="PredicateBuilder.cs" />
|
<Compile Include="PredicateBuilder.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Response.cs" />
|
<Compile Include="Response.cs" />
|
||||||
|
62
Infrastructure/ObjectHelper.cs
Normal file
62
Infrastructure/ObjectHelper.cs
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
// ***********************************************************************
|
||||||
|
// Assembly : Infrastructure
|
||||||
|
// Author : Yubao Li
|
||||||
|
// Created : 11-23-2015
|
||||||
|
//
|
||||||
|
// Last Modified By : Yubao Li
|
||||||
|
// Last Modified On : 11-23-2015
|
||||||
|
// ***********************************************************************
|
||||||
|
// <copyright file="ObjectHelper.cs" company="">
|
||||||
|
// Copyright (c) . All rights reserved.
|
||||||
|
// </copyright>
|
||||||
|
// <summary>对象COPY/初始化帮助</summary>
|
||||||
|
// ***********************************************************************
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Infrastructure
|
||||||
|
{
|
||||||
|
public static class ObjectHelper
|
||||||
|
{
|
||||||
|
|
||||||
|
public static void CopyTo<T>(this object source, T target)
|
||||||
|
where T : class,new()
|
||||||
|
{
|
||||||
|
if (source == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (target == null)
|
||||||
|
{
|
||||||
|
target = new T();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var property in target.GetType().GetProperties())
|
||||||
|
{
|
||||||
|
var propertyValue = source.GetType().GetProperty(property.Name).GetValue(source, null);
|
||||||
|
if (propertyValue != null)
|
||||||
|
{
|
||||||
|
if (propertyValue.GetType().IsClass)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
target.GetType().InvokeMember(property.Name, BindingFlags.SetProperty, null, target, new object[] { propertyValue });
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var field in target.GetType().GetFields())
|
||||||
|
{
|
||||||
|
var fieldValue = source.GetType().GetField(field.Name).GetValue(source);
|
||||||
|
if (fieldValue != null)
|
||||||
|
{
|
||||||
|
target.GetType().InvokeMember(field.Name, BindingFlags.SetField, null, target, new object[] { fieldValue });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,10 @@
|
|||||||
|
using OpenAuth.App.ViewModel;
|
||||||
using OpenAuth.Domain;
|
using OpenAuth.Domain;
|
||||||
using OpenAuth.Domain.Interface;
|
using OpenAuth.Domain.Interface;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenAuth.App.ViewModel;
|
using Infrastructure;
|
||||||
|
|
||||||
namespace OpenAuth.App
|
namespace OpenAuth.App
|
||||||
{
|
{
|
||||||
@ -18,7 +18,7 @@ namespace OpenAuth.App
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 加载一个部门及子部门全部Modules
|
/// 加载一个节点下面的所有
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public dynamic Load(int parentId, int pageindex, int pagesize)
|
public dynamic Load(int parentId, int pageindex, int pagesize)
|
||||||
{
|
{
|
||||||
@ -71,7 +71,6 @@ namespace OpenAuth.App
|
|||||||
return modules;
|
return modules;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Module Find(int id)
|
public Module Find(int id)
|
||||||
{
|
{
|
||||||
var module = _repository.FindSingle(u => u.Id == id);
|
var module = _repository.FindSingle(u => u.Id == id);
|
||||||
@ -88,23 +87,21 @@ namespace OpenAuth.App
|
|||||||
_repository.Delete(u => u.CascadeId.Contains(del.CascadeId));
|
_repository.Delete(u => u.CascadeId.Contains(del.CascadeId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddOrUpdate(Module model)
|
public void AddOrUpdate(Module vm)
|
||||||
{
|
{
|
||||||
Module module = model;
|
Module model = new Module();
|
||||||
ChangeModuleCascade(module);
|
vm.CopyTo(model); //copy一次,防止成员为null的情况
|
||||||
if (module.Id == 0)
|
ChangeModuleCascade(model);
|
||||||
|
if (model.Id == 0)
|
||||||
{
|
{
|
||||||
_repository.Add(module);
|
_repository.Add(model);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_repository.Update(module);
|
_repository.Update(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#region 私有方法
|
#region 私有方法
|
||||||
|
|
||||||
//根据同一级中最大的语义ID
|
//根据同一级中最大的语义ID
|
||||||
@ -150,13 +147,12 @@ namespace OpenAuth.App
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
cascadeId = "0." + currentCascadeId;
|
cascadeId = "0." + currentCascadeId;
|
||||||
module.ParentName = "";
|
module.ParentName = "根节点";
|
||||||
}
|
}
|
||||||
|
|
||||||
module.CascadeId = cascadeId;
|
module.CascadeId = cascadeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion 私有方法
|
#endregion 私有方法
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -14,7 +14,6 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
@Html.HiddenFor(m => m.Id)
|
@Html.HiddenFor(m => m.Id)
|
||||||
@Html.HiddenFor(m =>m.CascadeId)
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
@ -34,7 +33,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<label for="ParentId" class="control-label x120">上级功能模块:</label>
|
<label for="ParentId" class="control-label x120">上级功能模块:</label>
|
||||||
<input id="ParentId" name="ParentId" value="" style="display: none"/>
|
<input id="ParentId" name="ParentId" value="@Model.ParentId" style="display: none"/>
|
||||||
<input type="text" name="ParentName" id="ParentName"
|
<input type="text" name="ParentName" id="ParentName"
|
||||||
data-toggle="selectztree" size="20" data-tree="#j_select_tree1"
|
data-toggle="selectztree" size="20" data-tree="#j_select_tree1"
|
||||||
value="@Model.ParentName">
|
value="@Model.ParentName">
|
||||||
|
@ -139,7 +139,9 @@ namespace OpenAuth.UnitTest
|
|||||||
var module = new Module()
|
var module = new Module()
|
||||||
{
|
{
|
||||||
Name = "test_" + _time,
|
Name = "test_" + _time,
|
||||||
ParentId = parent
|
ParentId = parent,
|
||||||
|
IconName = null,
|
||||||
|
HotKey = null
|
||||||
};
|
};
|
||||||
_app.AddOrUpdate(module);
|
_app.AddOrUpdate(module);
|
||||||
return module;
|
return module;
|
||||||
|
Loading…
Reference in New Issue
Block a user