调整程序框架

This commit is contained in:
yubaolee
2015-05-23 12:10:53 +08:00
parent b4fc05a823
commit d2641d40fa
44 changed files with 434 additions and 635 deletions

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
<connectionStrings configSource="DB.config"></connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>

View File

@@ -0,0 +1,4 @@
<connectionStrings>
<add name="OpenAuthDBContext" connectionString="Data Source=.;Initial Catalog=OpenAuthDB;Persist Security Info=True;User ID=sa;Password=516688;MultipleActiveResultSets=True"
providerName="System.Data.SqlClient" />
</connectionStrings>

View File

@@ -0,0 +1,49 @@
using System.Data.Entity.ModelConfiguration;
using OpenAuth.Domain.Model;
namespace OpenAuth.Repository.Mapping
{
public class ButtonMap : EntityTypeConfiguration<Button>
{
public ButtonMap()
{
// Primary Key
this.HasKey(t => t.Id);
// Properties
this.Property(t => t.Id)
.IsRequired()
.HasMaxLength(50);
this.Property(t => t.FullName)
.HasMaxLength(50);
this.Property(t => t.Img)
.HasMaxLength(50);
this.Property(t => t.Event)
.HasMaxLength(200);
this.Property(t => t.Control_ID)
.HasMaxLength(50);
this.Property(t => t.Category)
.HasMaxLength(50);
this.Property(t => t.Description)
.HasMaxLength(200);
// Table & Column Mappings
this.ToTable("Button");
this.Property(t => t.Id).HasColumnName("ButtonId");
this.Property(t => t.FullName).HasColumnName("FullName");
this.Property(t => t.Img).HasColumnName("Img");
this.Property(t => t.Event).HasColumnName("Event");
this.Property(t => t.Control_ID).HasColumnName("Control_ID");
this.Property(t => t.Category).HasColumnName("Category");
this.Property(t => t.Description).HasColumnName("Description");
this.Property(t => t.Enabled).HasColumnName("Enabled");
this.Property(t => t.SortCode).HasColumnName("SortCode");
}
}
}

View File

@@ -0,0 +1,39 @@
using System.Data.Entity.ModelConfiguration;
using OpenAuth.Domain.Model;
namespace OpenAuth.Repository.Mapping
{
public class DataPermissionMap : EntityTypeConfiguration<DataPermission>
{
public DataPermissionMap()
{
// Primary Key
this.HasKey(t => t.Id);
// Properties
this.Property(t => t.Id)
.IsRequired()
.HasMaxLength(50);
this.Property(t => t.RoleId)
.IsRequired()
.HasMaxLength(50);
this.Property(t => t.ResourceId)
.HasMaxLength(50);
// Table & Column Mappings
this.ToTable("DataPermission");
this.Property(t => t.Id).HasColumnName("Id");
this.Property(t => t.RoleId).HasColumnName("RoleId");
this.Property(t => t.ResourceId).HasColumnName("ResourceId");
this.Property(t => t.ObjectId).HasColumnName("ObjectId");
// Relationships
this.HasRequired(t => t.Role)
.WithMany(t => t.DataPermissions)
.HasForeignKey(d => d.RoleId);
}
}
}

View File

@@ -0,0 +1,51 @@
using System.Data.Entity.ModelConfiguration;
using OpenAuth.Domain.Model;
namespace OpenAuth.Repository.Mapping
{
public class DepartmentMap : EntityTypeConfiguration<Department>
{
public DepartmentMap()
{
// Primary Key
this.HasKey(t => t.Id);
// Properties
this.Property(t => t.Id)
.IsRequired()
.HasMaxLength(50);
this.HasMany(d => d.Users)
.WithMany(u => u.Departments)
.Map(
m =>
{
m.MapLeftKey("DepartmentId");
m.MapRightKey("UserId");
m.ToTable("UserDepartment");
});
this.HasMany(d => d.Roles)
.WithRequired(r => r.Department);
this.Property(t => t.ParentId)
.HasMaxLength(50);
this.Property(t => t.FullName)
.HasMaxLength(50);
this.Property(t => t.Description)
.HasMaxLength(50);
// Table & Column Mappings
this.ToTable("Department");
this.Property(t => t.Id).HasColumnName("DepartmentId");
this.Property(t => t.ParentId).HasColumnName("ParentId");
this.Property(t => t.FullName).HasColumnName("FullName");
this.Property(t => t.Description).HasColumnName("Description");
this.Property(t => t.Enabled).HasColumnName("Enabled");
this.Property(t => t.SortCode).HasColumnName("SortCode");
this.Property(t => t.DeleteMark).HasColumnName("DeleteMark");
}
}
}

View File

@@ -0,0 +1,75 @@
using System.Data.Entity.ModelConfiguration;
using OpenAuth.Domain;
using OpenAuth.Domain.Model;
namespace OpenAuth.Repository.Mapping
{
public class MenuMap : EntityTypeConfiguration<Menu>
{
public MenuMap()
{
// Primary Key
this.HasKey(t => t.Id);
// Properties
this.Property(t => t.Id)
.IsRequired()
.HasMaxLength(50);
this.Property(t => t.ParentId)
.HasMaxLength(50);
this.Property(t => t.FullName)
.HasMaxLength(50);
this.Property(t => t.Description)
.HasMaxLength(200);
this.Property(t => t.Img)
.HasMaxLength(50);
this.Property(t => t.NavigateUrl)
.HasMaxLength(200);
this.Property(t => t.FormName)
.HasMaxLength(200);
this.Property(t => t.Target)
.HasMaxLength(50);
//<2F>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>İ<EFBFBD>ť
this.HasMany(t => t.Buttons)
.WithMany(b => b.Menus)
.Map(m =>
{
m.MapLeftKey("MenuId");
m.MapRightKey("ButtonId");
m.ToTable("MenuButton");
});
//TODO:<3A>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ľ<EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>䣬EF<45><46>ѯʱ<D1AF><CAB1><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>Role_RoleId<49><64>
this.HasMany(t => t.Roles)
.WithMany(b => b.RoleMenus)
.Map(m =>
{
m.MapLeftKey("MenuId");
m.MapRightKey("RoleId");
m.ToTable("RoleMenu");
});
// Table & Column Mappings
this.ToTable("Menu");
this.Property(t => t.Id).HasColumnName("MenuId");
this.Property(t => t.ParentId).HasColumnName("ParentId");
this.Property(t => t.FullName).HasColumnName("FullName");
this.Property(t => t.Description).HasColumnName("Description");
this.Property(t => t.Img).HasColumnName("Img");
this.Property(t => t.Category).HasColumnName("Category");
this.Property(t => t.NavigateUrl).HasColumnName("NavigateUrl");
this.Property(t => t.FormName).HasColumnName("FormName");
this.Property(t => t.Target).HasColumnName("Target");
this.Property(t => t.IsUnfold).HasColumnName("IsUnfold");
this.Property(t => t.Enabled).HasColumnName("Enabled");
this.Property(t => t.SortCode).HasColumnName("SortCode");
}
}
}

View File

@@ -0,0 +1,70 @@
using System.Data.Entity.ModelConfiguration;
using OpenAuth.Domain;
using OpenAuth.Domain.Model;
namespace OpenAuth.Repository.Mapping
{
public class RoleMap : EntityTypeConfiguration<Role>
{
public RoleMap()
{
// Primary Key
this.HasKey(t => t.Id);
// Properties
this.Property(t => t.Id)
.IsRequired()
.HasMaxLength(50);
this.Property(t => t.ParentId)
.HasMaxLength(50);
this.Property(t => t.FullName)
.HasMaxLength(50);
this.Property(t => t.Category)
.HasMaxLength(50);
this.Property(t => t.Description)
.HasMaxLength(200);
this.Property(t => t.DepartmentId)
.HasMaxLength(50);
//<2F><>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>
this.HasMany(d => d.Users)
.WithMany(u => u.Roles)
.Map(
m =>
{
m.MapLeftKey("RoleId");
m.MapRightKey("UserId");
m.ToTable("UserRole");
});
//<2F><>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD>IJ˵<C4B2>
this.HasMany(m => m.RoleMenus)
.WithMany(r => r.Roles)
.Map(m =>
{
m.MapLeftKey("RoleId");
m.MapRightKey("MenuId");
m.ToTable("RoleMenu");
});
// Table & Column Mappings
this.ToTable("Role");
this.Property(t => t.Id).HasColumnName("RoleId");
this.Property(t => t.ParentId).HasColumnName("ParentId");
this.Property(t => t.FullName).HasColumnName("FullName");
this.Property(t => t.Category).HasColumnName("Category");
this.Property(t => t.Description).HasColumnName("Description");
this.Property(t => t.Enabled).HasColumnName("Enabled");
this.Property(t => t.SortCode).HasColumnName("SortCode");
this.Property(t => t.DeleteMark).HasColumnName("DeleteMark");
this.Property(t => t.DepartmentId).HasColumnName("DepartmentId");
}
}
}

View File

@@ -0,0 +1,67 @@
using System.Data.Entity.ModelConfiguration;
using OpenAuth.Domain;
using OpenAuth.Domain.Model;
namespace OpenAuth.Repository.Mapping
{
public class UserMap : EntityTypeConfiguration<User>
{
public UserMap()
{
// Primary Key
this.HasKey(t => t.Id);
// Properties
this.Property(t => t.Id)
.IsRequired()
.HasMaxLength(50);
this.Property(t => t.Account)
.HasMaxLength(50);
this.Property(t => t.Password)
.HasMaxLength(50);
this.Property(t => t.RealName)
.HasMaxLength(50);
this.Property(t => t.RoleId)
.HasMaxLength(50);
this.HasMany(u => u.Departments)
.WithMany(d => d.Users)
.Map(m =>
{
m.MapLeftKey("UserId");
m.MapRightKey("DepartmentId");
m.ToTable("UserDepartment");
});
this.HasMany(u => u.Roles)
.WithMany(r => r.Users)
.Map(m =>
{
m.MapLeftKey("UserId");
m.MapRightKey("RoleId");
m.ToTable("UserRole");
});
//Ĭ<>Ͻ<EFBFBD>ɫ
this.HasOptional(u => u.DefaultRole)
.WithMany()
.HasForeignKey(u =>u.RoleId);
// Table & Column Mappings
this.ToTable("User");
this.Property(t => t.Id).HasColumnName("UserId");
this.Property(t => t.Account).HasColumnName("Account");
this.Property(t => t.Password).HasColumnName("Password");
this.Property(t => t.RealName).HasColumnName("RealName");
this.Property(t => t.RoleId).HasColumnName("RoleId");
this.Property(t => t.Enabled).HasColumnName("Enabled");
this.Property(t => t.DeleteMark).HasColumnName("DeleteMark");
}
}
}

View File

@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E8DF8DEA-E2CF-4BDB-8F4F-3F8205B0E03A}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OpenAuth.Repository</RootNamespace>
<AssemblyName>OpenAuth.Repository</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="EntityFramework">
<HintPath>..\packages\EntityFramework.6.1.3\lib\net40\EntityFramework.dll</HintPath>
</Reference>
<Reference Include="EntityFramework.SqlServer">
<HintPath>..\packages\EntityFramework.6.1.3\lib\net40\EntityFramework.SqlServer.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Mapping\ButtonMap.cs" />
<Compile Include="Mapping\DataPermissionMap.cs" />
<Compile Include="Mapping\DepartmentMap.cs" />
<Compile Include="Mapping\MenuMap.cs" />
<Compile Include="Mapping\RoleMap.cs" />
<Compile Include="Mapping\UserMap.cs" />
<Compile Include="OpenAuthDBContext.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Repository\BaseRepository.cs" />
<Compile Include="Repository\UserRepository.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenAuth.Domain\OpenAuth.Domain.csproj">
<Project>{6108da8e-92a1-4abe-b9f5-26d64d55ca2c}</Project>
<Name>OpenAuth.Domain</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="DB.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,36 @@
using System.Data.Entity;
using OpenAuth.Domain.Model;
using OpenAuth.Repository.Mapping;
namespace OpenAuth.Repository
{
public partial class OpenAuthDBContext : DbContext
{
static OpenAuthDBContext()
{
Database.SetInitializer<OpenAuthDBContext>(null);
}
public OpenAuthDBContext()
: base("Name=OpenAuthDBContext")
{
}
public DbSet<Button> Buttons { get; set; }
public DbSet<DataPermission> DataPermissions { get; set; }
public DbSet<Department> Departments { get; set; }
public DbSet<Menu> Menus { get; set; }
public DbSet<Role> Roles { get; set; }
public DbSet<User> Users { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new ButtonMap());
modelBuilder.Configurations.Add(new DataPermissionMap());
modelBuilder.Configurations.Add(new DepartmentMap());
modelBuilder.Configurations.Add(new MenuMap());
modelBuilder.Configurations.Add(new RoleMap());
modelBuilder.Configurations.Add(new UserMap());
}
}
}

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
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")]

View File

@@ -0,0 +1,7 @@
namespace OpenAuth.Repository.Repository
{
public class BaseRepository
{
protected OpenAuthDBContext _Context = new OpenAuthDBContext();
}
}

View File

@@ -0,0 +1,35 @@
using System;
using System.Linq;
using OpenAuth.Domain.Interface;
using OpenAuth.Domain.Model;
namespace OpenAuth.Repository.Repository
{
public class UserRepository :BaseRepository, IUserRepository
{
public User FindByAccount(string username)
{
try
{
return _Context.Users.First(e => e.Account == username);
}
catch (Exception)
{
return null;
}
}
public User FindById(string id)
{
try
{
return _Context.Users.First(e => e.Id == id);
}
catch (Exception)
{
return null;
}
}
}
}

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.1.3" targetFramework="net40" />
</packages>