mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-09-18 17:48:01 +08:00
完成机构与用户管理
This commit is contained in:
@@ -1,130 +1,130 @@
|
||||
<#@ template hostspecific="true" language="C#" #>
|
||||
<#@ include file="EF.Utility.CS.ttinclude" #><#@
|
||||
output extension=".cs" #><#
|
||||
|
||||
var efHost = (EfTextTemplateHost)Host;
|
||||
var code = new CodeGenerationTools(this);
|
||||
code.GetSummryDictionary(".",efHost.EntityContainer.Name,efHost.EntityType.Name,"sa","000000");
|
||||
|
||||
#>
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenAuth.Domain
|
||||
{
|
||||
/// <summary>
|
||||
/// <#= code.GetSummry(code.Escape(efHost.EntityType.Properties[0])) #>
|
||||
/// </summary>
|
||||
public partial class <#= efHost.EntityType.Name #>
|
||||
{
|
||||
<#
|
||||
var collectionNavigations = efHost.EntityType.NavigationProperties.Where(np => np.DeclaringType == efHost.EntityType && np.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many);
|
||||
|
||||
foreach (var property in efHost.EntityType.Properties)
|
||||
{
|
||||
var typeUsage = code.Escape(property.TypeUsage);
|
||||
|
||||
// Fix-up spatial types for EF6
|
||||
if (efHost.EntityFrameworkVersion >= new Version(6, 0)
|
||||
&& typeUsage.StartsWith("System.Data.Spatial."))
|
||||
{
|
||||
typeUsage = typeUsage.Replace(
|
||||
"System.Data.Spatial.",
|
||||
"System.Data.Entity.Spatial.");
|
||||
}
|
||||
#>
|
||||
/// <summary>
|
||||
/// <#= code.GetSummry(code.Escape(property)) #>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
<#= Accessibility.ForProperty(property) #> <#= typeUsage #> <#= code.Escape(property) #> { get; set; }
|
||||
|
||||
<#
|
||||
}
|
||||
|
||||
foreach (var navProperty in efHost.EntityType.NavigationProperties.Where(np => np.DeclaringType == efHost.EntityType))
|
||||
{
|
||||
if (navProperty.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many)
|
||||
{
|
||||
#>
|
||||
public virtual ICollection<<#= code.Escape(navProperty.ToEndMember.GetEntityType()) #>> <#= code.Escape(navProperty) #> { get; set; }
|
||||
<#
|
||||
}
|
||||
else
|
||||
{
|
||||
#>
|
||||
public virtual <#= code.Escape(navProperty.ToEndMember.GetEntityType()) #> <#= code.Escape(navProperty) #> { get; set; }
|
||||
<#
|
||||
}
|
||||
}
|
||||
#>
|
||||
|
||||
public <#= code.Escape(efHost.EntityType) #>()
|
||||
{
|
||||
<# foreach (var property in efHost.EntityType.Properties)
|
||||
{
|
||||
var typeUsage = code.Escape(property.TypeUsage);
|
||||
|
||||
// Fix-up spatial types for EF6
|
||||
if (efHost.EntityFrameworkVersion >= new Version(6, 0)
|
||||
&& typeUsage.StartsWith("System.Data.Spatial."))
|
||||
{
|
||||
typeUsage = typeUsage.Replace(
|
||||
"System.Data.Spatial.",
|
||||
"System.Data.Entity.Spatial.");
|
||||
}
|
||||
if(typeUsage=="System.Guid")
|
||||
{
|
||||
#>
|
||||
this.<#= code.Escape(property) #>= Guid.NewGuid();
|
||||
<#}
|
||||
else if(typeUsage=="System.DateTime")
|
||||
{
|
||||
#>
|
||||
this.<#= code.Escape(property) #>= DateTime.Now;
|
||||
<#}
|
||||
else if(typeUsage=="bool")
|
||||
{
|
||||
#>
|
||||
this.<#= code.Escape(property) #>= false;
|
||||
<# }
|
||||
else if(typeUsage=="int"||typeUsage=="double")
|
||||
{
|
||||
#>
|
||||
this.<#= code.Escape(property) #>= 0;
|
||||
<# }
|
||||
else if(typeUsage=="byte[]")
|
||||
{
|
||||
#>
|
||||
this.<#= code.Escape(property) #>= new byte[0];
|
||||
<# }
|
||||
else if(typeUsage=="decimal")
|
||||
{
|
||||
#>
|
||||
this.<#= code.Escape(property) #>= 0M;
|
||||
<# }
|
||||
else if(typeUsage=="string")
|
||||
{
|
||||
#>
|
||||
this.<#= code.Escape(property) #>= string.Empty;
|
||||
<#}
|
||||
else{ }
|
||||
}
|
||||
if (collectionNavigations.Any())
|
||||
{
|
||||
foreach (var navProperty in collectionNavigations)
|
||||
{
|
||||
#>
|
||||
this.<#= code.Escape(navProperty) #> = new List<<#= code.Escape(navProperty.ToEndMember.GetEntityType()) #>>();
|
||||
<#
|
||||
}
|
||||
|
||||
}#>
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
<#@ template hostspecific="true" language="C#" #>
|
||||
<#@ include file="EF.Utility.CS.ttinclude" #><#@
|
||||
output extension=".cs" #><#
|
||||
|
||||
var efHost = (EfTextTemplateHost)Host;
|
||||
var code = new CodeGenerationTools(this);
|
||||
code.GetSummryDictionary(".",efHost.EntityContainer.Name,efHost.EntityType.Name,"sa","000000");
|
||||
|
||||
#>
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenAuth.Domain
|
||||
{
|
||||
/// <summary>
|
||||
/// <#= code.GetSummry(code.Escape(efHost.EntityType.Properties[0])) #>
|
||||
/// </summary>
|
||||
public partial class <#= efHost.EntityType.Name #>
|
||||
{
|
||||
<#
|
||||
var collectionNavigations = efHost.EntityType.NavigationProperties.Where(np => np.DeclaringType == efHost.EntityType && np.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many);
|
||||
|
||||
foreach (var property in efHost.EntityType.Properties)
|
||||
{
|
||||
var typeUsage = code.Escape(property.TypeUsage);
|
||||
|
||||
// Fix-up spatial types for EF6
|
||||
if (efHost.EntityFrameworkVersion >= new Version(6, 0)
|
||||
&& typeUsage.StartsWith("System.Data.Spatial."))
|
||||
{
|
||||
typeUsage = typeUsage.Replace(
|
||||
"System.Data.Spatial.",
|
||||
"System.Data.Entity.Spatial.");
|
||||
}
|
||||
#>
|
||||
/// <summary>
|
||||
/// <#= code.GetSummry(code.Escape(property)) #>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
<#= Accessibility.ForProperty(property) #> <#= typeUsage #> <#= code.Escape(property) #> { get; set; }
|
||||
|
||||
<#
|
||||
}
|
||||
|
||||
foreach (var navProperty in efHost.EntityType.NavigationProperties.Where(np => np.DeclaringType == efHost.EntityType))
|
||||
{
|
||||
if (navProperty.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many)
|
||||
{
|
||||
#>
|
||||
public virtual ICollection<<#= code.Escape(navProperty.ToEndMember.GetEntityType()) #>> <#= code.Escape(navProperty) #> { get; set; }
|
||||
<#
|
||||
}
|
||||
else
|
||||
{
|
||||
#>
|
||||
public virtual <#= code.Escape(navProperty.ToEndMember.GetEntityType()) #> <#= code.Escape(navProperty) #> { get; set; }
|
||||
<#
|
||||
}
|
||||
}
|
||||
#>
|
||||
|
||||
public <#= code.Escape(efHost.EntityType) #>()
|
||||
{
|
||||
<# foreach (var property in efHost.EntityType.Properties)
|
||||
{
|
||||
var typeUsage = code.Escape(property.TypeUsage);
|
||||
|
||||
// Fix-up spatial types for EF6
|
||||
if (efHost.EntityFrameworkVersion >= new Version(6, 0)
|
||||
&& typeUsage.StartsWith("System.Data.Spatial."))
|
||||
{
|
||||
typeUsage = typeUsage.Replace(
|
||||
"System.Data.Spatial.",
|
||||
"System.Data.Entity.Spatial.");
|
||||
}
|
||||
if(typeUsage=="System.Guid")
|
||||
{
|
||||
#>
|
||||
this.<#= code.Escape(property) #>= Guid.NewGuid();
|
||||
<#}
|
||||
else if(typeUsage=="System.DateTime")
|
||||
{
|
||||
#>
|
||||
this.<#= code.Escape(property) #>= DateTime.Now;
|
||||
<#}
|
||||
else if(typeUsage=="bool")
|
||||
{
|
||||
#>
|
||||
this.<#= code.Escape(property) #>= false;
|
||||
<# }
|
||||
else if(typeUsage=="int"||typeUsage=="double")
|
||||
{
|
||||
#>
|
||||
this.<#= code.Escape(property) #>= 0;
|
||||
<# }
|
||||
else if(typeUsage=="byte[]")
|
||||
{
|
||||
#>
|
||||
this.<#= code.Escape(property) #>= new byte[0];
|
||||
<# }
|
||||
else if(typeUsage=="decimal")
|
||||
{
|
||||
#>
|
||||
this.<#= code.Escape(property) #>= 0M;
|
||||
<# }
|
||||
else if(typeUsage=="string")
|
||||
{
|
||||
#>
|
||||
this.<#= code.Escape(property) #>= string.Empty;
|
||||
<#}
|
||||
else{ }
|
||||
}
|
||||
if (collectionNavigations.Any())
|
||||
{
|
||||
foreach (var navProperty in collectionNavigations)
|
||||
{
|
||||
#>
|
||||
this.<#= code.Escape(navProperty) #> = new List<<#= code.Escape(navProperty.ToEndMember.GetEntityType()) #>>();
|
||||
<#
|
||||
}
|
||||
|
||||
}#>
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
@@ -45,6 +45,7 @@
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Transactions" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
|
@@ -14,5 +14,15 @@ namespace OpenAuth.Repository
|
||||
{
|
||||
return Find();
|
||||
}
|
||||
|
||||
public IEnumerable<Org> LoadByUser(int userId)
|
||||
{
|
||||
var result = from userorg in Context.UserOrgs
|
||||
join org in Context.Orgs on userorg.OrgId equals org.Id
|
||||
where userorg.UserId == userId
|
||||
select org;
|
||||
return result;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,35 +1,35 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的常规信息通过以下
|
||||
// 特性集控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("OpenAuth.Repository")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Microsoft")]
|
||||
[assembly: AssemblyProduct("OpenAuth.Repository")]
|
||||
[assembly: AssemblyCopyright("Copyright © Microsoft 2015")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 将 ComVisible 设置为 false 使此程序集中的类型
|
||||
// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
|
||||
// 则将该类型上的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("9d65fb39-6789-4fca-877b-85a106672986")]
|
||||
|
||||
// 程序集的版本信息由下面四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 生成号
|
||||
// 修订号
|
||||
//
|
||||
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
||||
// 方法是按如下所示使用“*”:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的常规信息通过以下
|
||||
// 特性集控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("OpenAuth.Repository")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Microsoft")]
|
||||
[assembly: AssemblyProduct("OpenAuth.Repository")]
|
||||
[assembly: AssemblyCopyright("Copyright © Microsoft 2015")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 将 ComVisible 设置为 false 使此程序集中的类型
|
||||
// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
|
||||
// 则将该类型上的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("9d65fb39-6789-4fca-877b-85a106672986")]
|
||||
|
||||
// 程序集的版本信息由下面四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 生成号
|
||||
// 修订号
|
||||
//
|
||||
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
||||
// 方法是按如下所示使用“*”:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
|
@@ -1,27 +1,70 @@
|
||||
using OpenAuth.Domain.Interface;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Transactions;
|
||||
using EntityFramework.Extensions;
|
||||
using OpenAuth.Domain;
|
||||
|
||||
namespace OpenAuth.Repository
|
||||
{
|
||||
public class UserRepository :BaseRepository<User>, IUserRepository
|
||||
{
|
||||
public User FindByAccount(string account)
|
||||
{
|
||||
return Context.Users.SingleOrDefault(u => u.Account == account);
|
||||
}
|
||||
|
||||
public User FindById(string id)
|
||||
{
|
||||
return FindSingle(u => u.Account == id);
|
||||
}
|
||||
|
||||
public IEnumerable<User> LoadUsers()
|
||||
{
|
||||
return Context.Users.ToList();
|
||||
}
|
||||
|
||||
public IEnumerable<User> LoadInOrgs(params int[] orgId)
|
||||
{
|
||||
var result = from user in Context.Users
|
||||
where (
|
||||
Context.UserOrgs.Where(uo => orgId.Contains(uo.OrgId))
|
||||
.Select(u => u.UserId)
|
||||
.Distinct()
|
||||
)
|
||||
.Contains(user.Id)
|
||||
select user;
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
public int GetUserCount(params int[] orgIds)
|
||||
{
|
||||
return LoadInOrgs(orgIds).Count();
|
||||
}
|
||||
|
||||
public IEnumerable<User> LoadInOrgs(int pageindex, int pagesize, params int[] orgIds)
|
||||
{
|
||||
return LoadInOrgs(orgIds).OrderBy(u =>u.Name).Skip((pageindex -1)*pagesize).Take(pagesize);
|
||||
}
|
||||
|
||||
public void AddWithOrg(User user, params int[] orgIds)
|
||||
{
|
||||
using (TransactionScope ts = new TransactionScope())
|
||||
{
|
||||
Add(user);
|
||||
Save();
|
||||
|
||||
foreach (var orgId in orgIds)
|
||||
{
|
||||
Context.UserOrgs.Add(new UserOrg{OrgId = orgId,UserId = user.Id});
|
||||
}
|
||||
Save();
|
||||
ts.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
public void Delete(int id)
|
||||
{
|
||||
using (TransactionScope ts = new TransactionScope())
|
||||
{
|
||||
Context.UserOrgs.Where(u => u.UserId == id).Delete();
|
||||
Delete(u =>u.Id == id);
|
||||
ts.Complete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user