v3.0.0
v3.0.0
This commit is contained in:
50
CC.Yi.Old/CC.Yi.API/CC.Yi.API.csproj
Normal file
50
CC.Yi.Old/CC.Yi.API/CC.Yi.API.csproj
Normal file
@@ -0,0 +1,50 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Autofac" Version="6.1.0" />
|
||||
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.1.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.5" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CC.Yi.BLL\CC.Yi.BLL.csproj" />
|
||||
<ProjectReference Include="..\CC.Yi.Common\CC.Yi.Common.csproj" />
|
||||
<ProjectReference Include="..\CC.Yi.IBLL\CC.Yi.IBLL.csproj" />
|
||||
<ProjectReference Include="..\CC.Yi.Model\CC.Yi.Model.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="nlog.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="T4Startup.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>T4Startup.tt</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="T4Startup.tt">
|
||||
<Generator>TextTemplatingFileGenerator</Generator>
|
||||
<LastGenOutput>T4Startup.cs</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
175
CC.Yi.Old/CC.Yi.API/Controllers/StudentController.cs
Normal file
175
CC.Yi.Old/CC.Yi.API/Controllers/StudentController.cs
Normal file
@@ -0,0 +1,175 @@
|
||||
using CC.Yi.API.Filter;
|
||||
using CC.Yi.Common;
|
||||
using CC.Yi.Common.Cache;
|
||||
using CC.Yi.Common.Jwt;
|
||||
using CC.Yi.IBLL;
|
||||
using CC.Yi.Model;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CC.Yi.API.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]/[action]")]
|
||||
public class StudentController : Controller
|
||||
{
|
||||
private readonly ILogger<StudentController> _logger;//处理日志相关文件
|
||||
|
||||
//private UserManager<result_user> _userManager;//处理用户相关逻辑:添加密码,修改密码,添加删除角色等等
|
||||
//private SignInManager<result_user> _signInManager;//处理注册登录的相关逻辑
|
||||
|
||||
private IstudentBll _studentBll;
|
||||
public StudentController(ILogger<StudentController> logger, IstudentBll studentBll)
|
||||
{
|
||||
|
||||
_logger = logger;
|
||||
_logger.LogInformation("现在你进入了StudentController控制器");
|
||||
_studentBll = studentBll;
|
||||
//_userManager = userManager;
|
||||
//_signInManager = signInManager;
|
||||
}
|
||||
#region
|
||||
//关于身份认证配置使用:
|
||||
//在需要身份认证的控制器上打上 [Authorize] 特性标签
|
||||
#endregion
|
||||
//[HttpGet]
|
||||
//public async Task<IActionResult> IdentityTest()
|
||||
//{
|
||||
// //用户登入
|
||||
// var data = await _signInManager.PasswordSignInAsync("账号", "密码", false, false); //"是否记住密码","是否登入失败锁定用户"
|
||||
// //用户登出
|
||||
// await _signInManager.SignOutAsync();
|
||||
// //创建用户
|
||||
// var data2 = await _userManager.CreateAsync(new result_user { UserName="账户",Email="邮箱"},"密码");
|
||||
// //获取用户
|
||||
// var data3 = _userManager.Users;//这里可以使用Linq表达式Select
|
||||
// return Ok();
|
||||
//}
|
||||
|
||||
#region
|
||||
//下面,这里是操作reids
|
||||
#endregion
|
||||
[HttpGet]
|
||||
public Result GetReids()
|
||||
{
|
||||
var data = CacheHelper.CacheWriter.GetCache<string>("key01");
|
||||
return Result.Success(data);
|
||||
}
|
||||
|
||||
#region
|
||||
//下面,权限验证
|
||||
#endregion
|
||||
|
||||
//发送令牌
|
||||
[HttpGet]
|
||||
public Result Login(string role)
|
||||
{
|
||||
string userName = "admin";
|
||||
var claims = new[]
|
||||
{
|
||||
new Claim(JwtRegisteredClaimNames.Nbf,$"{new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds()}") ,
|
||||
new Claim (JwtRegisteredClaimNames.Exp,$"{new DateTimeOffset(DateTime.Now.AddMinutes(30)).ToUnixTimeSeconds()}"),
|
||||
new Claim(ClaimTypes.Name, userName),
|
||||
new Claim(ClaimTypes.Role,role)
|
||||
|
||||
};
|
||||
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(JwtConst.SecurityKey));
|
||||
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
|
||||
|
||||
var token = new JwtSecurityToken(
|
||||
issuer: JwtConst.Domain,
|
||||
audience: JwtConst.Domain,
|
||||
claims: claims,
|
||||
expires: DateTime.Now.AddMinutes(30),
|
||||
signingCredentials: creds);
|
||||
|
||||
var tokenData= new JwtSecurityTokenHandler().WriteToken(token);
|
||||
return Result.Success("欢迎你!管理员!").SetData(new { token= tokenData });
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Authorize(Policy = "myadmin")]//基于策略的验证
|
||||
public Result MyAdmin()
|
||||
{
|
||||
return Result.Success("欢迎你!管理员!");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Authorize(Roles ="user")]//基于角色的验证
|
||||
public Result MyUser()
|
||||
{
|
||||
return Result.Success("欢迎你!游客!");
|
||||
}
|
||||
|
||||
|
||||
#region
|
||||
//下面,经典的 增删改查 即为简易--Yi意框架
|
||||
//注意:请确保你的数据库中存在合理的数据
|
||||
#endregion
|
||||
[HttpGet]
|
||||
[DbContextFilter]
|
||||
public async Task<Result> GetTest()//查
|
||||
{
|
||||
_logger.LogInformation("调用查方法");
|
||||
var data =await _studentBll.GetAllEntities().ToListAsync();
|
||||
return Result.Success("查询成功").SetData(data);
|
||||
}
|
||||
[HttpGet]
|
||||
[DbContextFilter]
|
||||
public Result AddTest()//增
|
||||
{
|
||||
_logger.LogInformation("调用增方法");
|
||||
List<student> students = new List<student>() {new student { name = "学生a" } ,new student { name="学生d"} };
|
||||
if (_studentBll.Add(students))
|
||||
{
|
||||
return Result.Success("增加成功");
|
||||
}
|
||||
else
|
||||
{
|
||||
return Result.Error("增加失败");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
[HttpGet]
|
||||
[DbContextFilter]
|
||||
public Result RemoveTest()//删
|
||||
{
|
||||
_logger.LogInformation("调用删方法");
|
||||
if (_studentBll.Delete(u=>u.name=="学生a"))
|
||||
{
|
||||
return Result.Success("删除成功");
|
||||
}
|
||||
else
|
||||
{
|
||||
return Result.Error("删除失败");
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
[DbContextFilter]
|
||||
public Result UpdateTest()//改
|
||||
{
|
||||
_logger.LogInformation("调用改方法");
|
||||
if (_studentBll.Update(new student { id=2, name = "学生a" }, "name"))
|
||||
{
|
||||
return Result.Success("修改成功");
|
||||
}
|
||||
else
|
||||
{
|
||||
return Result.Error("修改失败");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
22
CC.Yi.Old/CC.Yi.API/Filter/DbContextFilter.cs
Normal file
22
CC.Yi.Old/CC.Yi.API/Filter/DbContextFilter.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using CC.Yi.DAL;
|
||||
using CC.Yi.Model;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CC.Yi.API.Filter
|
||||
{
|
||||
public class DbContextFilter : ActionFilterAttribute
|
||||
{
|
||||
public override void OnActionExecuting(ActionExecutingContext filterContext)
|
||||
{
|
||||
var cache = filterContext.HttpContext.RequestServices.GetService(typeof(DataContext)) as DataContext;
|
||||
DbContentFactory.Initialize(cache);
|
||||
base.OnActionExecuting(filterContext);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
40
CC.Yi.Old/CC.Yi.API/Migrations/20210319112041_yi1.Designer.cs
generated
Normal file
40
CC.Yi.Old/CC.Yi.API/Migrations/20210319112041_yi1.Designer.cs
generated
Normal file
@@ -0,0 +1,40 @@
|
||||
// <auto-generated />
|
||||
using CC.Yi.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
namespace CC.Yi.API.Migrations
|
||||
{
|
||||
[DbContext(typeof(DataContext))]
|
||||
[Migration("20210319112041_yi1")]
|
||||
partial class yi1
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128)
|
||||
.HasAnnotation("ProductVersion", "5.0.4")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
modelBuilder.Entity("CC.Yi.Model.student", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
b.Property<int>("name")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.ToTable("student");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
29
CC.Yi.Old/CC.Yi.API/Migrations/20210319112041_yi1.cs
Normal file
29
CC.Yi.Old/CC.Yi.API/Migrations/20210319112041_yi1.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace CC.Yi.API.Migrations
|
||||
{
|
||||
public partial class yi1 : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "student",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
name = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_student", x => x.id);
|
||||
});
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "student");
|
||||
}
|
||||
}
|
||||
}
|
||||
40
CC.Yi.Old/CC.Yi.API/Migrations/20210320082935_yi2.Designer.cs
generated
Normal file
40
CC.Yi.Old/CC.Yi.API/Migrations/20210320082935_yi2.Designer.cs
generated
Normal file
@@ -0,0 +1,40 @@
|
||||
// <auto-generated />
|
||||
using CC.Yi.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
namespace CC.Yi.API.Migrations
|
||||
{
|
||||
[DbContext(typeof(DataContext))]
|
||||
[Migration("20210320082935_yi2")]
|
||||
partial class yi2
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128)
|
||||
.HasAnnotation("ProductVersion", "5.0.4")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
modelBuilder.Entity("CC.Yi.Model.student", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
b.Property<string>("name")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.ToTable("student");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
31
CC.Yi.Old/CC.Yi.API/Migrations/20210320082935_yi2.cs
Normal file
31
CC.Yi.Old/CC.Yi.API/Migrations/20210320082935_yi2.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace CC.Yi.API.Migrations
|
||||
{
|
||||
public partial class yi2 : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "name",
|
||||
table: "student",
|
||||
type: "nvarchar(max)",
|
||||
nullable: true,
|
||||
oldClrType: typeof(int),
|
||||
oldType: "int");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<int>(
|
||||
name: "name",
|
||||
table: "student",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
defaultValue: 0,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "nvarchar(max)",
|
||||
oldNullable: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
93
CC.Yi.Old/CC.Yi.API/Migrations/20210325123550_yi3.Designer.cs
generated
Normal file
93
CC.Yi.Old/CC.Yi.API/Migrations/20210325123550_yi3.Designer.cs
generated
Normal file
@@ -0,0 +1,93 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using CC.Yi.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
namespace CC.Yi.API.Migrations
|
||||
{
|
||||
[DbContext(typeof(DataContext))]
|
||||
[Migration("20210325123550_yi3")]
|
||||
partial class yi3
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128)
|
||||
.HasAnnotation("ProductVersion", "5.0.4")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
modelBuilder.Entity("CC.Yi.Model.result_user", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<int>("AccessFailedCount")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("ConcurrencyStamp")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<bool>("EmailConfirmed")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<bool>("LockoutEnabled")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<DateTimeOffset?>("LockoutEnd")
|
||||
.HasColumnType("datetimeoffset");
|
||||
|
||||
b.Property<string>("NormalizedEmail")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("NormalizedUserName")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("PhoneNumber")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<bool>("PhoneNumberConfirmed")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("SecurityStamp")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<bool>("TwoFactorEnabled")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("UserName")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("result_user");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CC.Yi.Model.student", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
b.Property<string>("name")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.ToTable("student");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
42
CC.Yi.Old/CC.Yi.API/Migrations/20210325123550_yi3.cs
Normal file
42
CC.Yi.Old/CC.Yi.API/Migrations/20210325123550_yi3.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace CC.Yi.API.Migrations
|
||||
{
|
||||
public partial class yi3 : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "result_user",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
UserName = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
NormalizedUserName = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
Email = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
NormalizedEmail = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
EmailConfirmed = table.Column<bool>(type: "bit", nullable: false),
|
||||
PasswordHash = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
SecurityStamp = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
ConcurrencyStamp = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
PhoneNumber = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
PhoneNumberConfirmed = table.Column<bool>(type: "bit", nullable: false),
|
||||
TwoFactorEnabled = table.Column<bool>(type: "bit", nullable: false),
|
||||
LockoutEnd = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
|
||||
LockoutEnabled = table.Column<bool>(type: "bit", nullable: false),
|
||||
AccessFailedCount = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_result_user", x => x.Id);
|
||||
});
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "result_user");
|
||||
}
|
||||
}
|
||||
}
|
||||
301
CC.Yi.Old/CC.Yi.API/Migrations/20210325124241_yi4.Designer.cs
generated
Normal file
301
CC.Yi.Old/CC.Yi.API/Migrations/20210325124241_yi4.Designer.cs
generated
Normal file
@@ -0,0 +1,301 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using CC.Yi.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
namespace CC.Yi.API.Migrations
|
||||
{
|
||||
[DbContext(typeof(DataContext))]
|
||||
[Migration("20210325124241_yi4")]
|
||||
partial class yi4
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128)
|
||||
.HasAnnotation("ProductVersion", "5.0.4")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
modelBuilder.Entity("CC.Yi.Model.student", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
b.Property<string>("name")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.ToTable("student");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("ConcurrencyStamp")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("nvarchar(256)");
|
||||
|
||||
b.Property<string>("NormalizedName")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("nvarchar(256)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NormalizedName")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("RoleNameIndex")
|
||||
.HasFilter("[NormalizedName] IS NOT NULL");
|
||||
|
||||
b.ToTable("AspNetRoles");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
b.Property<string>("ClaimType")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("ClaimValue")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("RoleId")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RoleId");
|
||||
|
||||
b.ToTable("AspNetRoleClaims");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<int>("AccessFailedCount")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("ConcurrencyStamp")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Discriminator")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("nvarchar(256)");
|
||||
|
||||
b.Property<bool>("EmailConfirmed")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<bool>("LockoutEnabled")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<DateTimeOffset?>("LockoutEnd")
|
||||
.HasColumnType("datetimeoffset");
|
||||
|
||||
b.Property<string>("NormalizedEmail")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("nvarchar(256)");
|
||||
|
||||
b.Property<string>("NormalizedUserName")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("nvarchar(256)");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("PhoneNumber")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<bool>("PhoneNumberConfirmed")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("SecurityStamp")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<bool>("TwoFactorEnabled")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("UserName")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("nvarchar(256)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NormalizedEmail")
|
||||
.HasDatabaseName("EmailIndex");
|
||||
|
||||
b.HasIndex("NormalizedUserName")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("UserNameIndex")
|
||||
.HasFilter("[NormalizedUserName] IS NOT NULL");
|
||||
|
||||
b.ToTable("AspNetUsers");
|
||||
|
||||
b.HasDiscriminator<string>("Discriminator").HasValue("IdentityUser");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
b.Property<string>("ClaimType")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("ClaimValue")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("UserId")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("AspNetUserClaims");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
|
||||
{
|
||||
b.Property<string>("LoginProvider")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("ProviderKey")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("ProviderDisplayName")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("UserId")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.HasKey("LoginProvider", "ProviderKey");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("AspNetUserLogins");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
|
||||
{
|
||||
b.Property<string>("UserId")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("RoleId")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.HasKey("UserId", "RoleId");
|
||||
|
||||
b.HasIndex("RoleId");
|
||||
|
||||
b.ToTable("AspNetUserRoles");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
|
||||
{
|
||||
b.Property<string>("UserId")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("LoginProvider")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("Value")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("UserId", "LoginProvider", "Name");
|
||||
|
||||
b.ToTable("AspNetUserTokens");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CC.Yi.Model.result_user", b =>
|
||||
{
|
||||
b.HasBaseType("Microsoft.AspNetCore.Identity.IdentityUser");
|
||||
|
||||
b.HasDiscriminator().HasValue("result_user");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
|
||||
{
|
||||
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("RoleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
|
||||
{
|
||||
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
|
||||
{
|
||||
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
|
||||
{
|
||||
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("RoleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
|
||||
{
|
||||
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
315
CC.Yi.Old/CC.Yi.API/Migrations/20210325124241_yi4.cs
Normal file
315
CC.Yi.Old/CC.Yi.API/Migrations/20210325124241_yi4.cs
Normal file
@@ -0,0 +1,315 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace CC.Yi.API.Migrations
|
||||
{
|
||||
public partial class yi4 : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_result_user",
|
||||
table: "result_user");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "result_user",
|
||||
newName: "AspNetUsers");
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "UserName",
|
||||
table: "AspNetUsers",
|
||||
type: "nvarchar(256)",
|
||||
maxLength: 256,
|
||||
nullable: true,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "nvarchar(max)",
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "NormalizedUserName",
|
||||
table: "AspNetUsers",
|
||||
type: "nvarchar(256)",
|
||||
maxLength: 256,
|
||||
nullable: true,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "nvarchar(max)",
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "NormalizedEmail",
|
||||
table: "AspNetUsers",
|
||||
type: "nvarchar(256)",
|
||||
maxLength: 256,
|
||||
nullable: true,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "nvarchar(max)",
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "Email",
|
||||
table: "AspNetUsers",
|
||||
type: "nvarchar(256)",
|
||||
maxLength: 256,
|
||||
nullable: true,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "nvarchar(max)",
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "Discriminator",
|
||||
table: "AspNetUsers",
|
||||
type: "nvarchar(max)",
|
||||
nullable: false,
|
||||
defaultValue: "");
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_AspNetUsers",
|
||||
table: "AspNetUsers",
|
||||
column: "Id");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AspNetRoles",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
Name = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
|
||||
NormalizedName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
|
||||
ConcurrencyStamp = table.Column<string>(type: "nvarchar(max)", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AspNetRoles", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AspNetUserClaims",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
UserId = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
ClaimType = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
ClaimValue = table.Column<string>(type: "nvarchar(max)", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AspNetUserClaims", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_AspNetUserClaims_AspNetUsers_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "AspNetUsers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AspNetUserLogins",
|
||||
columns: table => new
|
||||
{
|
||||
LoginProvider = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
ProviderKey = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
ProviderDisplayName = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
UserId = table.Column<string>(type: "nvarchar(450)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey });
|
||||
table.ForeignKey(
|
||||
name: "FK_AspNetUserLogins_AspNetUsers_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "AspNetUsers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AspNetUserTokens",
|
||||
columns: table => new
|
||||
{
|
||||
UserId = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
LoginProvider = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
Name = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
Value = table.Column<string>(type: "nvarchar(max)", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name });
|
||||
table.ForeignKey(
|
||||
name: "FK_AspNetUserTokens_AspNetUsers_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "AspNetUsers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AspNetRoleClaims",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
RoleId = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
ClaimType = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
ClaimValue = table.Column<string>(type: "nvarchar(max)", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_AspNetRoleClaims_AspNetRoles_RoleId",
|
||||
column: x => x.RoleId,
|
||||
principalTable: "AspNetRoles",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AspNetUserRoles",
|
||||
columns: table => new
|
||||
{
|
||||
UserId = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
RoleId = table.Column<string>(type: "nvarchar(450)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId });
|
||||
table.ForeignKey(
|
||||
name: "FK_AspNetUserRoles_AspNetRoles_RoleId",
|
||||
column: x => x.RoleId,
|
||||
principalTable: "AspNetRoles",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_AspNetUserRoles_AspNetUsers_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "AspNetUsers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "EmailIndex",
|
||||
table: "AspNetUsers",
|
||||
column: "NormalizedEmail");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "UserNameIndex",
|
||||
table: "AspNetUsers",
|
||||
column: "NormalizedUserName",
|
||||
unique: true,
|
||||
filter: "[NormalizedUserName] IS NOT NULL");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AspNetRoleClaims_RoleId",
|
||||
table: "AspNetRoleClaims",
|
||||
column: "RoleId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "RoleNameIndex",
|
||||
table: "AspNetRoles",
|
||||
column: "NormalizedName",
|
||||
unique: true,
|
||||
filter: "[NormalizedName] IS NOT NULL");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AspNetUserClaims_UserId",
|
||||
table: "AspNetUserClaims",
|
||||
column: "UserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AspNetUserLogins_UserId",
|
||||
table: "AspNetUserLogins",
|
||||
column: "UserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AspNetUserRoles_RoleId",
|
||||
table: "AspNetUserRoles",
|
||||
column: "RoleId");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "AspNetRoleClaims");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "AspNetUserClaims");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "AspNetUserLogins");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "AspNetUserRoles");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "AspNetUserTokens");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "AspNetRoles");
|
||||
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_AspNetUsers",
|
||||
table: "AspNetUsers");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "EmailIndex",
|
||||
table: "AspNetUsers");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "UserNameIndex",
|
||||
table: "AspNetUsers");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Discriminator",
|
||||
table: "AspNetUsers");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "AspNetUsers",
|
||||
newName: "result_user");
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "UserName",
|
||||
table: "result_user",
|
||||
type: "nvarchar(max)",
|
||||
nullable: true,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "nvarchar(256)",
|
||||
oldMaxLength: 256,
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "NormalizedUserName",
|
||||
table: "result_user",
|
||||
type: "nvarchar(max)",
|
||||
nullable: true,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "nvarchar(256)",
|
||||
oldMaxLength: 256,
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "NormalizedEmail",
|
||||
table: "result_user",
|
||||
type: "nvarchar(max)",
|
||||
nullable: true,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "nvarchar(256)",
|
||||
oldMaxLength: 256,
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "Email",
|
||||
table: "result_user",
|
||||
type: "nvarchar(max)",
|
||||
nullable: true,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "nvarchar(256)",
|
||||
oldMaxLength: 256,
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_result_user",
|
||||
table: "result_user",
|
||||
column: "Id");
|
||||
}
|
||||
}
|
||||
}
|
||||
40
CC.Yi.Old/CC.Yi.API/Migrations/20210410090937_yi5.Designer.cs
generated
Normal file
40
CC.Yi.Old/CC.Yi.API/Migrations/20210410090937_yi5.Designer.cs
generated
Normal file
@@ -0,0 +1,40 @@
|
||||
// <auto-generated />
|
||||
using CC.Yi.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
namespace CC.Yi.API.Migrations
|
||||
{
|
||||
[DbContext(typeof(DataContext))]
|
||||
[Migration("20210410090937_yi5")]
|
||||
partial class yi5
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128)
|
||||
.HasAnnotation("ProductVersion", "5.0.4")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
modelBuilder.Entity("CC.Yi.Model.student", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
b.Property<string>("name")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.ToTable("student");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
220
CC.Yi.Old/CC.Yi.API/Migrations/20210410090937_yi5.cs
Normal file
220
CC.Yi.Old/CC.Yi.API/Migrations/20210410090937_yi5.cs
Normal file
@@ -0,0 +1,220 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace CC.Yi.API.Migrations
|
||||
{
|
||||
public partial class yi5 : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "AspNetRoleClaims");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "AspNetUserClaims");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "AspNetUserLogins");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "AspNetUserRoles");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "AspNetUserTokens");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "AspNetRoles");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "AspNetUsers");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AspNetRoles",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
ConcurrencyStamp = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
Name = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
|
||||
NormalizedName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AspNetRoles", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AspNetUsers",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
AccessFailedCount = table.Column<int>(type: "int", nullable: false),
|
||||
ConcurrencyStamp = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
Discriminator = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Email = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
|
||||
EmailConfirmed = table.Column<bool>(type: "bit", nullable: false),
|
||||
LockoutEnabled = table.Column<bool>(type: "bit", nullable: false),
|
||||
LockoutEnd = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
|
||||
NormalizedEmail = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
|
||||
NormalizedUserName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
|
||||
PasswordHash = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
PhoneNumber = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
PhoneNumberConfirmed = table.Column<bool>(type: "bit", nullable: false),
|
||||
SecurityStamp = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
TwoFactorEnabled = table.Column<bool>(type: "bit", nullable: false),
|
||||
UserName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AspNetUsers", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AspNetRoleClaims",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ClaimType = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
ClaimValue = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
RoleId = table.Column<string>(type: "nvarchar(450)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_AspNetRoleClaims_AspNetRoles_RoleId",
|
||||
column: x => x.RoleId,
|
||||
principalTable: "AspNetRoles",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AspNetUserClaims",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ClaimType = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
ClaimValue = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
UserId = table.Column<string>(type: "nvarchar(450)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AspNetUserClaims", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_AspNetUserClaims_AspNetUsers_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "AspNetUsers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AspNetUserLogins",
|
||||
columns: table => new
|
||||
{
|
||||
LoginProvider = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
ProviderKey = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
ProviderDisplayName = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
UserId = table.Column<string>(type: "nvarchar(450)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey });
|
||||
table.ForeignKey(
|
||||
name: "FK_AspNetUserLogins_AspNetUsers_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "AspNetUsers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AspNetUserRoles",
|
||||
columns: table => new
|
||||
{
|
||||
UserId = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
RoleId = table.Column<string>(type: "nvarchar(450)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId });
|
||||
table.ForeignKey(
|
||||
name: "FK_AspNetUserRoles_AspNetRoles_RoleId",
|
||||
column: x => x.RoleId,
|
||||
principalTable: "AspNetRoles",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_AspNetUserRoles_AspNetUsers_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "AspNetUsers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AspNetUserTokens",
|
||||
columns: table => new
|
||||
{
|
||||
UserId = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
LoginProvider = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
Name = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
Value = table.Column<string>(type: "nvarchar(max)", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name });
|
||||
table.ForeignKey(
|
||||
name: "FK_AspNetUserTokens_AspNetUsers_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "AspNetUsers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AspNetRoleClaims_RoleId",
|
||||
table: "AspNetRoleClaims",
|
||||
column: "RoleId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "RoleNameIndex",
|
||||
table: "AspNetRoles",
|
||||
column: "NormalizedName",
|
||||
unique: true,
|
||||
filter: "[NormalizedName] IS NOT NULL");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AspNetUserClaims_UserId",
|
||||
table: "AspNetUserClaims",
|
||||
column: "UserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AspNetUserLogins_UserId",
|
||||
table: "AspNetUserLogins",
|
||||
column: "UserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AspNetUserRoles_RoleId",
|
||||
table: "AspNetUserRoles",
|
||||
column: "RoleId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "EmailIndex",
|
||||
table: "AspNetUsers",
|
||||
column: "NormalizedEmail");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "UserNameIndex",
|
||||
table: "AspNetUsers",
|
||||
column: "NormalizedUserName",
|
||||
unique: true,
|
||||
filter: "[NormalizedUserName] IS NOT NULL");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using CC.Yi.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
namespace CC.Yi.API.Migrations
|
||||
@@ -13,16 +14,19 @@ namespace CC.Yi.API.Migrations
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "5.0.5");
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128)
|
||||
.HasAnnotation("ProductVersion", "5.0.4")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
modelBuilder.Entity("CC.Yi.Model.student", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
.HasColumnType("int")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
b.Property<string>("name")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
62
CC.Yi.Old/CC.Yi.API/Program.cs
Normal file
62
CC.Yi.Old/CC.Yi.API/Program.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using Autofac.Extensions.DependencyInjection;
|
||||
using CC.Yi.DAL;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog.Web;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CC.Yi.API
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();
|
||||
try
|
||||
{
|
||||
logger.Debug("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Yi<59><69><EFBFBD><EFBFBD><EFBFBD>ܡ<EFBFBD><DCA1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||||
var host = CreateHostBuilder(args).Build();
|
||||
//var scope = host.Services.CreateScope();
|
||||
//var services = scope.ServiceProvider;
|
||||
//var context = services.GetRequiredService<Model.DataContext>();//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
||||
//DbContentFactory.Initialize(context);//<2F><><EFBFBD>þ<EFBFBD>̬<EFBFBD><EFBFBD><E0B7BD>ע<EFBFBD><D7A2>
|
||||
host.Run();
|
||||
logger.Info("Yi<59><69><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD>");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
//NLog: catch setup errors
|
||||
logger.Error(exception, "Stopped program because of exception");
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux)
|
||||
NLog.LogManager.Shutdown();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
webBuilder.UseStartup<Startup>();
|
||||
}).UseServiceProviderFactory(new AutofacServiceProviderFactory())
|
||||
.ConfigureLogging(logging =>
|
||||
{
|
||||
// logging.ClearProviders(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>п<EFBFBD><D0BF><EFBFBD>̨<EFBFBD><CCA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
|
||||
}).UseNLog();//<2F><><EFBFBD><EFBFBD>nlog<6F><67>־<EFBFBD><D6BE><EFBFBD><EFBFBD>
|
||||
|
||||
}
|
||||
}
|
||||
164
CC.Yi.Old/CC.Yi.API/Startup.cs
Normal file
164
CC.Yi.Old/CC.Yi.API/Startup.cs
Normal file
@@ -0,0 +1,164 @@
|
||||
|
||||
using Autofac;
|
||||
using Autofac.Extras.DynamicProxy;
|
||||
using CC.Yi.API.Extension;
|
||||
using CC.Yi.API.Filter;
|
||||
using CC.Yi.BLL;
|
||||
using CC.Yi.Common.Cache;
|
||||
using CC.Yi.Common.Castle;
|
||||
using CC.Yi.Common.Jwt;
|
||||
using CC.Yi.DAL;
|
||||
using CC.Yi.IBLL;
|
||||
using CC.Yi.IDAL;
|
||||
using CC.Yi.Model;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.HttpsPolicy;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CC.Yi.API
|
||||
{
|
||||
public partial class Startup
|
||||
{
|
||||
public Startup(IConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD>Jwt
|
||||
services.AddAuthorization(options =>
|
||||
{
|
||||
//<2F><><EFBFBD>û<EFBFBD><C3BB>ڲ<EFBFBD><DAB2>Ե<EFBFBD><D4B5><EFBFBD>֤
|
||||
options.AddPolicy("myadmin", policy =>
|
||||
policy.RequireRole("admin"));
|
||||
});
|
||||
|
||||
|
||||
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||
.AddJwtBearer(options => {
|
||||
options.TokenValidationParameters = new TokenValidationParameters
|
||||
{
|
||||
ValidateIssuer = true,//<2F>Ƿ<EFBFBD><C7B7><EFBFBD>֤Issuer
|
||||
ValidateAudience = true,//<2F>Ƿ<EFBFBD><C7B7><EFBFBD>֤Audience
|
||||
ValidateLifetime = true,//<2F>Ƿ<EFBFBD><C7B7><EFBFBD>֤ʧЧʱ<D0A7><CAB1>
|
||||
ClockSkew = TimeSpan.FromSeconds(30),
|
||||
ValidateIssuerSigningKey = true,//<2F>Ƿ<EFBFBD><C7B7><EFBFBD>֤SecurityKey
|
||||
ValidAudience = JwtConst.Domain,//Audience
|
||||
ValidIssuer = JwtConst.Domain,//Issuer<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0>ǩ<EFBFBD><C7A9>jwt<77><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(JwtConst.SecurityKey))//<2F>õ<EFBFBD>SecurityKey
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
services.AddControllers();
|
||||
services.AddSwaggerService();
|
||||
services.AddSession();
|
||||
|
||||
|
||||
|
||||
//<2F><><EFBFBD>ù<EFBFBD><C3B9><EFBFBD><EFBFBD><EFBFBD>
|
||||
Action<MvcOptions> filters = new Action<MvcOptions>(r => {
|
||||
//r.Filters.Add(typeof(DbContextFilter));
|
||||
});
|
||||
services.AddMvc(filters);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD>
|
||||
string connection1 = Configuration["ConnectionStringBySQL"];
|
||||
string connection2 = Configuration["ConnectionStringByMySQL"];
|
||||
string connection3 = Configuration["ConnectionStringBySQLite"];
|
||||
services.AddDbContext<DataContext>(options =>
|
||||
{
|
||||
options.UseSqlServer(connection1, b => b.MigrationsAssembly("CC.Yi.API"));//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>
|
||||
});
|
||||
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>Autofac
|
||||
//services.AddScoped(typeof(IBaseDal<>), typeof(BaseDal<>));
|
||||
//services.AddScoped(typeof(IstudentBll), typeof(studentBll));
|
||||
|
||||
//reidsע<73><D7A2>
|
||||
//services.AddSingleton(typeof(ICacheWriter), new RedisCacheService(new Microsoft.Extensions.Caching.Redis.RedisCacheOptions()
|
||||
//{
|
||||
// Configuration = Configuration.GetSection("Cache.ConnectionString").Value,
|
||||
// InstanceName = Configuration.GetSection("Cache.InstanceName").Value
|
||||
//}));
|
||||
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>Identity<74><79><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤
|
||||
//services.AddIdentity<result_user, IdentityRole>(options =>
|
||||
// {
|
||||
// options.Password.RequiredLength = 6;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳<EFBFBD><CCB3><EFBFBD>
|
||||
// options.Password.RequireDigit = false;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// options.Password.RequireLowercase = false;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Сд<D0A1><D0B4>ĸ
|
||||
// options.Password.RequireNonAlphanumeric = false;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
|
||||
// options.Password.RequireUppercase = false;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4>ĸ
|
||||
// //options.User.RequireUniqueEmail = false;//ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2>ظ<EFBFBD>
|
||||
// //options.User.AllowedUserNameCharacters="abcd"//<2F><><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
|
||||
//}).AddEntityFrameworkStores<DataContext>().AddDefaultTokenProviders();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
services.AddCors(options => options.AddPolicy("CorsPolicy",
|
||||
builder =>
|
||||
{
|
||||
builder.AllowAnyMethod()
|
||||
.SetIsOriginAllowed(_ => true)
|
||||
.AllowAnyHeader()
|
||||
.AllowCredentials();
|
||||
}));
|
||||
}
|
||||
|
||||
//<2F><>ʼ<EFBFBD><CABC>ʹ<EFBFBD>ú<EFBFBD><C3BA><EFBFBD>
|
||||
private void InitData(IServiceProvider serviceProvider)
|
||||
{
|
||||
//var serviceScope = serviceProvider.GetRequiredService<IServiceScopeFactory>().CreateScope();
|
||||
|
||||
//var context = serviceScope.ServiceProvider.GetService<DataContext>();
|
||||
//DbContentFactory.Initialize(context);//<2F><><EFBFBD>þ<EFBFBD>̬<EFBFBD><EFBFBD><E0B7BD>ע<EFBFBD><D7A2>
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
app.UseSwaggerService();
|
||||
}
|
||||
|
||||
//app.UseAuthentication();
|
||||
app.UseCors("CorsPolicy");
|
||||
app.UseHttpsRedirection();
|
||||
app.UseSession();
|
||||
app.UseRouting();
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllers();
|
||||
});
|
||||
InitData(app.ApplicationServices);
|
||||
}
|
||||
}
|
||||
}
|
||||
17
CC.Yi.Old/CC.Yi.API/appsettings.json
Normal file
17
CC.Yi.Old/CC.Yi.API/appsettings.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"Cache": {
|
||||
"InstanceName": "Redis",
|
||||
"ConnectionString": "127.0.0.1:12345,password=123456"
|
||||
},
|
||||
"ConnectionStringBySQL": "server=.;Database=YIDB;UId=sa;PWD=Qz52013142020.",
|
||||
"ConnectionStringByMySQL": "Data Source=.;Database=YIDB;User ID=root;Password=Qz52013142020.;pooling=true;port=3306;sslmode=none;CharSet=utf8;",
|
||||
"ConnectionStringBySQLite": "Filename=YIDB.db"
|
||||
}
|
||||
109
CC.Yi.Old/CC.Yi.BLL/BaseBll.cs
Normal file
109
CC.Yi.Old/CC.Yi.BLL/BaseBll.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
using CC.Yi.DALFactory;
|
||||
using CC.Yi.IBLL;
|
||||
using CC.Yi.IDAL;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace CC.Yi.BLL
|
||||
{
|
||||
public class BaseBll<T> : IBaseBll<T> where T : class, new()
|
||||
{
|
||||
public IBaseDal<T> CurrentDal;
|
||||
public BaseBll(IBaseDal<T> cd)
|
||||
{
|
||||
CurrentDal = cd;
|
||||
}
|
||||
|
||||
public IQueryable<T> GetAllEntities()
|
||||
{
|
||||
return CurrentDal.GetAllEntities();
|
||||
}
|
||||
|
||||
public IQueryable<T> GetEntities(Expression<Func<T, bool>> whereLambda)
|
||||
{
|
||||
return CurrentDal.GetEntities(whereLambda);
|
||||
}
|
||||
|
||||
public int GetCount(Expression<Func<T, bool>> whereLambda) //统计数量
|
||||
{
|
||||
return CurrentDal.GetCount(whereLambda);
|
||||
}
|
||||
|
||||
public IQueryable<IGrouping<S, T>> GetGroup<S>(Expression<Func<T, bool>> whereLambda, Expression<Func<T, S>> groupByLambda) //分组
|
||||
{
|
||||
return CurrentDal.GetGroup(whereLambda, groupByLambda);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public IQueryable<T> GetPageEntities<S>(int pageSize, int pageIndex, out int total, Expression<Func<T, bool>> whereLambda, Expression<Func<T, S>> orderByLambda, bool isAsc)
|
||||
{
|
||||
return CurrentDal.GetPageEntities(pageSize, pageIndex, out total, whereLambda, orderByLambda, isAsc);
|
||||
}
|
||||
|
||||
public T Add(T entity)
|
||||
{
|
||||
var myEntity=CurrentDal.Add(entity);
|
||||
DbSession.SaveChanges();
|
||||
return myEntity;
|
||||
}
|
||||
|
||||
public bool Add(IEnumerable<T> entities)
|
||||
{
|
||||
CurrentDal.AddRange(entities);
|
||||
return DbSession.SaveChanges() > 0;
|
||||
}
|
||||
|
||||
public bool Update(T entity)
|
||||
{
|
||||
CurrentDal.Update(entity);
|
||||
return DbSession.SaveChanges() > 0;
|
||||
}
|
||||
|
||||
public bool Update(T entity, params string[] propertyNames)
|
||||
{
|
||||
CurrentDal.Update(entity,propertyNames);
|
||||
return DbSession.SaveChanges() > 0;
|
||||
}
|
||||
|
||||
public bool Delete(T entity)
|
||||
{
|
||||
CurrentDal.Delete(entity);
|
||||
return DbSession.SaveChanges() > 0;
|
||||
}
|
||||
public IDbSession DbSession
|
||||
{
|
||||
get
|
||||
{
|
||||
return DbSessionFactory.GetCurrentDbSession();
|
||||
}
|
||||
}
|
||||
public bool Delete(int id)
|
||||
{
|
||||
CurrentDal.Detete(id);
|
||||
return DbSession.SaveChanges() > 0;
|
||||
}
|
||||
|
||||
public bool Delete(IEnumerable<int> ids)
|
||||
{
|
||||
foreach (var id in ids)
|
||||
{
|
||||
CurrentDal.Detete(id);
|
||||
}
|
||||
return DbSession.SaveChanges()>0;
|
||||
}
|
||||
public bool Delete(Expression<Func<T, bool>> where)
|
||||
{
|
||||
IQueryable<T> entities = CurrentDal.GetEntities(where);
|
||||
if (entities != null)
|
||||
{
|
||||
CurrentDal.DeteteRange(entities);
|
||||
|
||||
return DbSession.SaveChanges()>0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
32
CC.Yi.Old/CC.Yi.BLL/CC.Yi.BLL.csproj
Normal file
32
CC.Yi.Old/CC.Yi.BLL/CC.Yi.BLL.csproj
Normal file
@@ -0,0 +1,32 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CC.Yi.DALFactory\CC.Yi.DALFactory.csproj" />
|
||||
<ProjectReference Include="..\CC.Yi.IBLL\CC.Yi.IBLL.csproj" />
|
||||
<ProjectReference Include="..\CC.Yi.IDAL\CC.Yi.IDAL.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="T4BLL.tt">
|
||||
<Generator>TextTemplatingFileGenerator</Generator>
|
||||
<LastGenOutput>T4BLL.cs</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="T4BLL.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>T4BLL.tt</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -6,16 +6,14 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace CC.Yi.BLL
|
||||
{
|
||||
public partial class studentBll : BaseBll<student>, IstudentBll
|
||||
{
|
||||
public studentBll(IBaseDal<student> cd,DataContext _Db):base(cd,_Db)
|
||||
public studentBll(IBaseDal<student> cd):base(cd)
|
||||
{
|
||||
CurrentDal = cd;
|
||||
DbSession = _Db;
|
||||
}
|
||||
}
|
||||
}
|
||||
37
CC.Yi.Old/CC.Yi.BLL/T4BLL.tt
Normal file
37
CC.Yi.Old/CC.Yi.BLL/T4BLL.tt
Normal file
@@ -0,0 +1,37 @@
|
||||
<#@ template debug="false" hostspecific="true" language="C#" #>
|
||||
<#@ assembly name="System.Core" #>
|
||||
<#@ import namespace="System.Linq" #>
|
||||
<#@ import namespace="System.Text" #>
|
||||
<#@ import namespace="System.Collections.Generic" #>
|
||||
<#@ import namespace="System.IO" #>
|
||||
<#@ output extension=".cs" #>
|
||||
<#
|
||||
string solutionsPath = Host.ResolveAssemblyReference("$(SolutionDir)");//获取解决方案路径
|
||||
string txt;
|
||||
StreamReader sr = new StreamReader(solutionsPath+@"\T4Model\T4Model.txt");
|
||||
txt=sr.ReadToEnd();
|
||||
sr.Close();
|
||||
string[] ModelData= txt.Split(',');
|
||||
#>
|
||||
|
||||
using CC.Yi.IBLL;
|
||||
using CC.Yi.IDAL;
|
||||
using CC.Yi.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CC.Yi.BLL
|
||||
{
|
||||
<# foreach(string k in ModelData){
|
||||
#>
|
||||
public partial class <#=k #>Bll : BaseBll<<#=k #>>, I<#=k #>Bll
|
||||
{
|
||||
public <#=k #>Bll(IBaseDal<<#=k #>> cd):base(cd)
|
||||
{
|
||||
CurrentDal = cd;
|
||||
}
|
||||
}
|
||||
<# } #>
|
||||
}
|
||||
17
CC.Yi.Old/CC.Yi.Common/CC.Yi.Common.csproj
Normal file
17
CC.Yi.Old/CC.Yi.Common/CC.Yi.Common.csproj
Normal file
@@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Autofac.Extras.DynamicProxy" Version="6.0.0" />
|
||||
<PackageReference Include="Castle.Core" Version="4.4.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Redis" Version="2.2.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="NLog.Web.AspNetCore" Version="4.11.0" />
|
||||
<PackageReference Include="ServiceStack.Redis" Version="5.10.4" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
48
CC.Yi.Old/CC.Yi.Common/Cache/RedisCache.cs
Normal file
48
CC.Yi.Old/CC.Yi.Common/Cache/RedisCache.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using ServiceStack.Redis;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace CC.Yi.Common.Cache
|
||||
{
|
||||
public class RedisCache : ICacheWriter
|
||||
{
|
||||
private RedisClient client;
|
||||
public string redisIp { get; set; }
|
||||
|
||||
public RedisCache()
|
||||
{
|
||||
client = new RedisClient("127.0.0.1", 6379, "52013142020.");
|
||||
}
|
||||
|
||||
public bool AddCache<T>(string key, T value, DateTime expDate)
|
||||
{
|
||||
return client.Add<T>(key, value, expDate);
|
||||
}
|
||||
|
||||
public bool AddCache<T>(string key, T value)
|
||||
{
|
||||
return client.Add<T>(key, value);
|
||||
}
|
||||
|
||||
public bool RemoveCache(string key)
|
||||
{
|
||||
return client.Remove(key);
|
||||
}
|
||||
|
||||
public T GetCache<T>(string key)
|
||||
{
|
||||
return client.Get<T>(key);
|
||||
}
|
||||
|
||||
public bool SetCache<T>(string key,T value, DateTime expDate)
|
||||
{
|
||||
return client.Set<T>(key, value, expDate);
|
||||
}
|
||||
|
||||
public bool SetCache<T>(string key, T value)
|
||||
{
|
||||
return client.Set<T>(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
24
CC.Yi.Old/CC.Yi.Common/JsonHelper.cs
Normal file
24
CC.Yi.Old/CC.Yi.Common/JsonHelper.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
|
||||
namespace CC.Yi.Common
|
||||
{
|
||||
public static class JsonHelper
|
||||
{
|
||||
public static string JsonToString(object data=null, int code = 200, bool flag = true, string message = "成功")
|
||||
{
|
||||
return Newtonsoft.Json.JsonConvert.SerializeObject(new { code = code, flag = flag, message = message, data = data });
|
||||
}
|
||||
public static string JsonToString2(object data = null, int code = 200, bool flag = true, string message = "成功",int count=0)
|
||||
{
|
||||
return Newtonsoft.Json.JsonConvert.SerializeObject(new { code = code, flag = flag, message = message, count=count,data = data });
|
||||
}
|
||||
public static string ToString(object data)
|
||||
{
|
||||
return Newtonsoft.Json.JsonConvert.SerializeObject(data);
|
||||
}
|
||||
public static T ToJson<T>(string data)
|
||||
{
|
||||
return Newtonsoft.Json.JsonConvert.DeserializeObject<T>(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
40
CC.Yi.Old/CC.Yi.Common/Result.cs
Normal file
40
CC.Yi.Old/CC.Yi.Common/Result.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace CC.Yi.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// 结果数据
|
||||
/// </summary>
|
||||
public class Result
|
||||
{
|
||||
public bool status { get; set; }
|
||||
public int code { get; set; }
|
||||
public string msg { get; set; }
|
||||
public object data { get; set; }
|
||||
public static Result Instance(bool status, string msg)
|
||||
{
|
||||
return new Result() { status = status, code = 500, msg = msg };
|
||||
}
|
||||
public static Result Error(string msg = "fail")
|
||||
{
|
||||
return new Result() { status = false, code = 500, msg = msg };
|
||||
}
|
||||
public static Result Success(string msg = "succeed")
|
||||
{
|
||||
return new Result() { status = true, code = 200, msg = msg };
|
||||
}
|
||||
public Result SetData(object obj)
|
||||
{
|
||||
this.data = obj;
|
||||
return this;
|
||||
}
|
||||
public Result SetCode(int Code)
|
||||
{
|
||||
this.code = Code;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
113
CC.Yi.Old/CC.Yi.DAL/BaseDal.cs
Normal file
113
CC.Yi.Old/CC.Yi.DAL/BaseDal.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
using CC.Yi.IDAL;
|
||||
using CC.Yi.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace CC.Yi.DAL
|
||||
{
|
||||
public class BaseDal<T> : IBaseDal<T> where T : class, new()
|
||||
{
|
||||
public DbContext Db
|
||||
{
|
||||
get { return DbContentFactory.GetCurrentDbContent(); }
|
||||
}
|
||||
public IQueryable<T> GetEntities(Expression<Func<T, bool>> whereLambda)
|
||||
{
|
||||
return Db.Set<T>().Where(whereLambda).AsQueryable();
|
||||
}
|
||||
|
||||
public IQueryable<T> GetAllEntities()
|
||||
{
|
||||
return Db.Set<T>().AsQueryable();
|
||||
}
|
||||
|
||||
|
||||
public int GetCount(Expression<Func<T, bool>> whereLambda)
|
||||
{
|
||||
return Db.Set<T>().Where(whereLambda).Count();
|
||||
}
|
||||
|
||||
public IQueryable<IGrouping<S, T>> GetGroup<S>(Expression<Func<T, bool>> whereLambda, Expression<Func<T, S>> groupByLambda) //分组
|
||||
{
|
||||
return Db.Set<T>().Where(whereLambda).GroupBy<T, S>(groupByLambda).AsQueryable();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public IQueryable<T> GetPageEntities<S>(int pageSize, int pageIndex, out int total, Expression<Func<T, bool>> whereLambda, Expression<Func<T, S>> orderByLambda, bool isAsc)
|
||||
{
|
||||
total = Db.Set<T>().Where(whereLambda).Count();
|
||||
if (isAsc)
|
||||
{
|
||||
var pageData = Db.Set<T>().Where(whereLambda)
|
||||
.OrderBy<T, S>(orderByLambda)
|
||||
.Skip(pageSize * (pageIndex - 1))
|
||||
.Take(pageSize).AsQueryable();
|
||||
return pageData;
|
||||
}
|
||||
else
|
||||
{
|
||||
var pageData = Db.Set<T>().Where(whereLambda)
|
||||
.OrderByDescending<T, S>(orderByLambda)
|
||||
.Skip(pageSize * (pageIndex - 1))
|
||||
.Take(pageSize).AsQueryable();
|
||||
return pageData;
|
||||
}
|
||||
}
|
||||
|
||||
public T Add(T entity)
|
||||
{
|
||||
Db.Set<T>().Add(entity);
|
||||
//Db.SaveChanges();
|
||||
return entity;
|
||||
}
|
||||
public bool AddRange(IEnumerable<T> entities)
|
||||
{
|
||||
Db.Set<T>().AddRange(entities);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(T entity)
|
||||
{
|
||||
//所有字段均修改
|
||||
Db.Entry<T>(entity).State = EntityState.Modified;
|
||||
//return Db.SaveChanges() > 0;
|
||||
return true;
|
||||
}
|
||||
public bool Update(T entity, params string[] propertyNames)
|
||||
{
|
||||
EntityEntry entry = Db.Entry<T>(entity);
|
||||
entry.State = EntityState.Unchanged;
|
||||
foreach (var item in propertyNames)
|
||||
{
|
||||
entry.Property(item).IsModified = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(T entity)
|
||||
{
|
||||
Db.Entry<T>(entity).State = EntityState.Deleted;
|
||||
//return Db.SaveChanges() > 0;
|
||||
return true;
|
||||
}
|
||||
public bool Detete(int id)
|
||||
{
|
||||
var entity = Db.Set<T>().Find(id);//根据id找到实体
|
||||
Db.Set<T>().Remove(entity);//由于这里先Find找到了实体,所以这里可以用Remove标记该实体要移除(删除)。如果不是先Find到实体就需要用System.Data.Entity.EntityState.Deleted
|
||||
return true;
|
||||
}
|
||||
public bool DeteteRange(IEnumerable<T> entity)
|
||||
{
|
||||
Db.Set<T>().RemoveRange(entity);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
58
CC.Yi.Old/CC.Yi.DAL/DbContentFactory.cs
Normal file
58
CC.Yi.Old/CC.Yi.DAL/DbContentFactory.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using CC.Yi.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading;
|
||||
|
||||
|
||||
namespace CC.Yi.DAL
|
||||
{
|
||||
public class DbContentFactory
|
||||
{
|
||||
private static DataContext Webcontext;
|
||||
private static object myLock = new object();
|
||||
|
||||
public static void Initialize(DataContext webContext)
|
||||
{
|
||||
|
||||
Monitor.Enter(myLock);
|
||||
{
|
||||
Webcontext = webContext;
|
||||
}
|
||||
}
|
||||
public static DataContext GetCurrentDbContent()
|
||||
{
|
||||
|
||||
DataContext db = CallContext.GetData("DbContext") as DataContext;
|
||||
|
||||
if (db == null)//线程在数据槽里面没有此上下文
|
||||
{
|
||||
db = Webcontext;
|
||||
CallContext.SetData("DbContext", db);//放到数据槽中去,DbContext是key,db是value
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Monitor.Exit(myLock);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
return db;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static class CallContext
|
||||
{
|
||||
static ConcurrentDictionary<string, AsyncLocal<object>> state = new ConcurrentDictionary<string, AsyncLocal<object>>();
|
||||
|
||||
public static void SetData(string name, object data) =>
|
||||
state.GetOrAdd(name, _ => new AsyncLocal<object>()).Value = data;
|
||||
|
||||
public static object GetData(string name) =>
|
||||
state.TryGetValue(name, out AsyncLocal<object> data) ? data.Value : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
CC.Yi.Old/CC.Yi.DAL/T4DAL.cs
Normal file
12
CC.Yi.Old/CC.Yi.DAL/T4DAL.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using CC.Yi.IDAL;
|
||||
using CC.Yi.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace CC.Yi.DAL
|
||||
{
|
||||
public partial class studentDal : BaseDal<student>, IstudentDal
|
||||
{
|
||||
}
|
||||
}
|
||||
30
CC.Yi.Old/CC.Yi.DAL/T4DAL.tt
Normal file
30
CC.Yi.Old/CC.Yi.DAL/T4DAL.tt
Normal file
@@ -0,0 +1,30 @@
|
||||
<#@ template debug="false" hostspecific="true" language="C#" #>
|
||||
<#@ assembly name="System.Core" #>
|
||||
<#@ import namespace="System.Linq" #>
|
||||
<#@ import namespace="System.Text" #>
|
||||
<#@ import namespace="System.Collections.Generic" #>
|
||||
<#@ import namespace="System.IO" #>
|
||||
<#@ output extension=".cs" #>
|
||||
<#
|
||||
string solutionsPath = Host.ResolveAssemblyReference("$(SolutionDir)");//获取解决方案路径
|
||||
string txt;
|
||||
StreamReader sr = new StreamReader(solutionsPath+@"\T4Model\T4Model.txt");
|
||||
txt=sr.ReadToEnd();
|
||||
sr.Close();
|
||||
string[] ModelData= txt.Split(',');
|
||||
#>
|
||||
using CC.Yi.IDAL;
|
||||
using CC.Yi.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace CC.Yi.DAL
|
||||
{
|
||||
<# foreach(string k in ModelData){
|
||||
#>
|
||||
public partial class <#=k #>Dal : BaseDal<<#=k #>>, I<#=k #>Dal
|
||||
{
|
||||
}
|
||||
<# } #>
|
||||
}
|
||||
40
CC.Yi.Old/CC.Yi.DALFactory/CC.Yi.DALFactory.csproj
Normal file
40
CC.Yi.Old/CC.Yi.DALFactory/CC.Yi.DALFactory.csproj
Normal file
@@ -0,0 +1,40 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CC.Yi.DAL\CC.Yi.DAL.csproj" />
|
||||
<ProjectReference Include="..\CC.Yi.IDAL\CC.Yi.IDAL.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="T4DbSession.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>T4DbSession.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Update="T4StaticDalFactory.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>T4StaticDalFactory.tt</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="T4DbSession.tt">
|
||||
<Generator>TextTemplatingFileGenerator</Generator>
|
||||
<LastGenOutput>T4DbSession.cs</LastGenOutput>
|
||||
</None>
|
||||
<None Update="T4StaticDalFactory.tt">
|
||||
<Generator>TextTemplatingFileGenerator</Generator>
|
||||
<LastGenOutput>T4StaticDalFactory.cs</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
45
CC.Yi.Old/CC.Yi.DALFactory/DbSession.cs
Normal file
45
CC.Yi.Old/CC.Yi.DALFactory/DbSession.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using CC.Yi.DAL;
|
||||
using CC.Yi.IDAL;
|
||||
using CC.Yi.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
|
||||
namespace CC.Yi.DALFactory
|
||||
{
|
||||
public partial class DbSession : IDbSession
|
||||
{
|
||||
public int SaveChanges()
|
||||
{
|
||||
var context = DbContentFactory.GetCurrentDbContent();
|
||||
|
||||
var saved = false;
|
||||
while (!saved)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Attempt to save changes to the database
|
||||
context.SaveChanges();
|
||||
saved = true;
|
||||
}
|
||||
catch (DbUpdateConcurrencyException ex)
|
||||
{
|
||||
foreach (var entry in ex.Entries)
|
||||
{
|
||||
var databaseValues = entry.GetDatabaseValues();
|
||||
|
||||
// Refresh original values to bypass next concurrency check
|
||||
entry.OriginalValues.SetValues(databaseValues);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
public DataContext GetDbContent()
|
||||
{
|
||||
return DbContentFactory.GetCurrentDbContent();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
35
CC.Yi.Old/CC.Yi.DALFactory/DbSessionFactory.cs
Normal file
35
CC.Yi.Old/CC.Yi.DALFactory/DbSessionFactory.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using CC.Yi.IDAL;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CC.Yi.DALFactory
|
||||
{
|
||||
public class DbSessionFactory
|
||||
{
|
||||
public static IDbSession GetCurrentDbSession()
|
||||
{
|
||||
IDbSession db = CallContext.GetData("DbSession") as IDbSession;
|
||||
if (db == null)
|
||||
{
|
||||
db = new DbSession();
|
||||
CallContext.SetData("DbSession", db);
|
||||
}
|
||||
return db;
|
||||
}
|
||||
|
||||
private static class CallContext
|
||||
{
|
||||
static ConcurrentDictionary<string, AsyncLocal<object>> state = new ConcurrentDictionary<string, AsyncLocal<object>>();
|
||||
|
||||
public static void SetData(string name, object data) =>
|
||||
state.GetOrAdd(name, _ => new AsyncLocal<object>()).Value = data;
|
||||
|
||||
public static object GetData(string name) =>
|
||||
state.TryGetValue(name, out AsyncLocal<object> data) ? data.Value : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
24
CC.Yi.Old/CC.Yi.DALFactory/StaticDalFactory.cs
Normal file
24
CC.Yi.Old/CC.Yi.DALFactory/StaticDalFactory.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using CC.Yi.DAL;
|
||||
using CC.Yi.IDAL;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace CC.Yi.DALFactory
|
||||
{
|
||||
public partial class StaticDalFactory
|
||||
{
|
||||
private static class CallContext
|
||||
{
|
||||
static ConcurrentDictionary<string, AsyncLocal<object>> state = new ConcurrentDictionary<string, AsyncLocal<object>>();
|
||||
|
||||
public static void SetData(string name, object data) =>
|
||||
state.GetOrAdd(name, _ => new AsyncLocal<object>()).Value = data;
|
||||
|
||||
public static object GetData(string name) =>
|
||||
state.TryGetValue(name, out AsyncLocal<object> data) ? data.Value : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
18
CC.Yi.Old/CC.Yi.DALFactory/T4DbSession.cs
Normal file
18
CC.Yi.Old/CC.Yi.DALFactory/T4DbSession.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using CC.Yi.DAL;
|
||||
using CC.Yi.IDAL;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CC.Yi.DALFactory
|
||||
{
|
||||
public partial class DbSession : IDbSession
|
||||
{
|
||||
public IstudentDal studentDal
|
||||
{
|
||||
get { return StaticDalFactory.GetstudentDal(); }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
36
CC.Yi.Old/CC.Yi.DALFactory/T4DbSession.tt
Normal file
36
CC.Yi.Old/CC.Yi.DALFactory/T4DbSession.tt
Normal file
@@ -0,0 +1,36 @@
|
||||
<#@ template debug="false" hostspecific="true" language="C#" #>
|
||||
<#@ assembly name="System.Core" #>
|
||||
<#@ import namespace="System.Linq" #>
|
||||
<#@ import namespace="System.Text" #>
|
||||
<#@ import namespace="System.Collections.Generic" #>
|
||||
<#@ import namespace="System.IO" #>
|
||||
<#@ output extension=".cs" #>
|
||||
<#
|
||||
string solutionsPath = Host.ResolveAssemblyReference("$(SolutionDir)");//获取解决方案路径
|
||||
string txt;
|
||||
StreamReader sr = new StreamReader(solutionsPath+@"\T4Model\T4Model.txt");
|
||||
txt=sr.ReadToEnd();
|
||||
sr.Close();
|
||||
string[] ModelData= txt.Split(',');
|
||||
#>
|
||||
using CC.Yi.DAL;
|
||||
using CC.Yi.IDAL;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CC.Yi.DALFactory
|
||||
{
|
||||
public partial class DbSession : IDbSession
|
||||
{
|
||||
<# foreach(string k in ModelData){
|
||||
#>
|
||||
public I<#=k #>Dal <#=k #>Dal
|
||||
{
|
||||
get { return StaticDalFactory.Get<#=k #>Dal(); }
|
||||
}
|
||||
|
||||
<# } #>
|
||||
}
|
||||
}
|
||||
25
CC.Yi.Old/CC.Yi.DALFactory/T4StaticDalFactory.cs
Normal file
25
CC.Yi.Old/CC.Yi.DALFactory/T4StaticDalFactory.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using CC.Yi.DAL;
|
||||
using CC.Yi.IDAL;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace CC.Yi.DALFactory
|
||||
{
|
||||
public partial class StaticDalFactory
|
||||
{
|
||||
public static IstudentDal GetstudentDal()
|
||||
{
|
||||
IstudentDal Data = CallContext.GetData("studentDal") as IstudentDal;
|
||||
if (Data == null)
|
||||
{
|
||||
Data = new studentDal();
|
||||
CallContext.SetData("studentDal", Data);
|
||||
}
|
||||
return Data;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
43
CC.Yi.Old/CC.Yi.DALFactory/T4StaticDalFactory.tt
Normal file
43
CC.Yi.Old/CC.Yi.DALFactory/T4StaticDalFactory.tt
Normal file
@@ -0,0 +1,43 @@
|
||||
<#@ template debug="false" hostspecific="true" language="C#" #>
|
||||
<#@ assembly name="System.Core" #>
|
||||
<#@ import namespace="System.Linq" #>
|
||||
<#@ import namespace="System.Text" #>
|
||||
<#@ import namespace="System.Collections.Generic" #>
|
||||
<#@ import namespace="System.IO" #>
|
||||
<#@ output extension=".cs" #>
|
||||
<#
|
||||
string solutionsPath = Host.ResolveAssemblyReference("$(SolutionDir)");//获取解决方案路径
|
||||
string txt;
|
||||
StreamReader sr = new StreamReader(solutionsPath+@"\T4Model\T4Model.txt");
|
||||
txt=sr.ReadToEnd();
|
||||
sr.Close();
|
||||
string[] ModelData= txt.Split(',');
|
||||
#>
|
||||
using CC.Yi.DAL;
|
||||
using CC.Yi.IDAL;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace CC.Yi.DALFactory
|
||||
{
|
||||
public partial class StaticDalFactory
|
||||
{
|
||||
<# foreach(string k in ModelData){
|
||||
#>
|
||||
public static I<#=k #>Dal Get<#=k #>Dal()
|
||||
{
|
||||
I<#=k #>Dal Data = CallContext.GetData("<#=k #>Dal") as I<#=k #>Dal;
|
||||
if (Data == null)
|
||||
{
|
||||
Data = new <#=k #>Dal();
|
||||
CallContext.SetData("<#=k #>Dal", Data);
|
||||
}
|
||||
return Data;
|
||||
}
|
||||
|
||||
<# } #>
|
||||
}
|
||||
}
|
||||
78
CC.Yi.Old/CC.Yi.IBLL/IBaseBll.cs
Normal file
78
CC.Yi.Old/CC.Yi.IBLL/IBaseBll.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using Autofac.Extras.DynamicProxy;
|
||||
using CC.Yi.Common.Castle;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace CC.Yi.IBLL
|
||||
{
|
||||
[Intercept(typeof(CustomAutofacAop))]
|
||||
public interface IBaseBll<T> where T : class, new()
|
||||
{
|
||||
#region
|
||||
//得到全部实体
|
||||
#endregion
|
||||
IQueryable<T> GetAllEntities();
|
||||
|
||||
#region
|
||||
//通过表达式得到实体
|
||||
#endregion
|
||||
IQueryable<T> GetEntities(Expression<Func<T, bool>> whereLambda);
|
||||
|
||||
#region
|
||||
//通过表达式得到实体,分页版本
|
||||
#endregion
|
||||
IQueryable<T> GetPageEntities<S>(int pageSize, int pageIndex, out int total, Expression<Func<T, bool>> whereLambda, Expression<Func<T, S>> orderByLambda, bool isAsc);
|
||||
|
||||
#region
|
||||
//通过表达式统计数量
|
||||
#endregion
|
||||
int GetCount(Expression<Func<T, bool>> whereLambda);
|
||||
|
||||
#region
|
||||
//通过表达式分组
|
||||
#endregion
|
||||
IQueryable<IGrouping<S, T>> GetGroup<S>(Expression<Func<T, bool>> whereLambda, Expression<Func<T, S>> groupByLambda);
|
||||
|
||||
#region
|
||||
//添加实体
|
||||
#endregion
|
||||
T Add(T entity);
|
||||
|
||||
#region
|
||||
//添加多个实体
|
||||
#endregion
|
||||
bool Add(IEnumerable<T> entities);
|
||||
|
||||
#region
|
||||
//更新实体
|
||||
#endregion
|
||||
bool Update(T entity);
|
||||
|
||||
#region
|
||||
//更新实体部分属性
|
||||
#endregion
|
||||
bool Update(T entity, params string[] propertyNames);
|
||||
|
||||
#region
|
||||
//删除实体
|
||||
#endregion
|
||||
bool Delete(T entity);
|
||||
|
||||
#region
|
||||
//通过id删除实体
|
||||
#endregion
|
||||
bool Delete(int id);
|
||||
|
||||
#region
|
||||
//通过id列表删除多个实体
|
||||
#endregion
|
||||
bool Delete(IEnumerable<int> ids);
|
||||
|
||||
#region
|
||||
//通过表达式删除实体
|
||||
#endregion
|
||||
bool Delete(Expression<Func<T, bool>> where);
|
||||
}
|
||||
}
|
||||
40
CC.Yi.Old/CC.Yi.IDAL/CC.Yi.IDAL.csproj
Normal file
40
CC.Yi.Old/CC.Yi.IDAL/CC.Yi.IDAL.csproj
Normal file
@@ -0,0 +1,40 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Library</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CC.Yi.Model\CC.Yi.Model.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="T4IDAL.tt">
|
||||
<Generator>TextTemplatingFileGenerator</Generator>
|
||||
<LastGenOutput>T4IDAL.cs</LastGenOutput>
|
||||
</None>
|
||||
<None Update="T4IDbSession.tt">
|
||||
<Generator>TextTemplatingFileGenerator</Generator>
|
||||
<LastGenOutput>T4IDbSession.cs</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="T4IDAL.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>T4IDAL.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Update="T4IDbSession.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>T4IDbSession.tt</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
18
CC.Yi.Old/CC.Yi.IDAL/IDbSession.cs
Normal file
18
CC.Yi.Old/CC.Yi.IDAL/IDbSession.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using CC.Yi.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CC.Yi.IDAL
|
||||
{
|
||||
public partial interface IDbSession
|
||||
{
|
||||
DataContext GetDbContent();
|
||||
int SaveChanges();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
15
CC.Yi.Old/CC.Yi.IDAL/T4IDbSession.cs
Normal file
15
CC.Yi.Old/CC.Yi.IDAL/T4IDbSession.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using CC.Yi.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CC.Yi.IDAL
|
||||
{
|
||||
public partial interface IDbSession
|
||||
{
|
||||
IstudentDal studentDal{get;}
|
||||
|
||||
}
|
||||
}
|
||||
33
CC.Yi.Old/CC.Yi.IDAL/T4IDbSession.tt
Normal file
33
CC.Yi.Old/CC.Yi.IDAL/T4IDbSession.tt
Normal file
@@ -0,0 +1,33 @@
|
||||
<#@ template debug="false" hostspecific="true" language="C#" #>
|
||||
<#@ assembly name="System.Core" #>
|
||||
<#@ import namespace="System.Linq" #>
|
||||
<#@ import namespace="System.Text" #>
|
||||
<#@ import namespace="System.Collections.Generic" #>
|
||||
<#@ import namespace="System.IO" #>
|
||||
<#@ output extension=".cs" #>
|
||||
<#
|
||||
string solutionsPath = Host.ResolveAssemblyReference("$(SolutionDir)");//获取解决方案路径
|
||||
string txt;
|
||||
StreamReader sr = new StreamReader(solutionsPath+@"\T4Model\T4Model.txt");
|
||||
txt=sr.ReadToEnd();
|
||||
sr.Close();
|
||||
string[] ModelData= txt.Split(',');
|
||||
#>
|
||||
using CC.Yi.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CC.Yi.IDAL
|
||||
{
|
||||
public partial interface IDbSession
|
||||
{
|
||||
<# foreach(string k in ModelData){
|
||||
#>
|
||||
I<#=k #>Dal <#=k #>Dal{get;}
|
||||
|
||||
<# } #>
|
||||
}
|
||||
}
|
||||
43
CC.Yi.Old/CC.Yi.Model/CC.Yi.Model.csproj
Normal file
43
CC.Yi.Old/CC.Yi.Model/CC.Yi.Model.csproj
Normal file
@@ -0,0 +1,43 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="T4DataContext.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>T4DataContext.tt</DependentUpon>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="T4DataContext.tt">
|
||||
<Generator>TextTemplatingFileGenerator</Generator>
|
||||
<LastGenOutput>T4DataContext.cs</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="T4DataContext.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>T4DataContext.tt</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
14
CC.Yi.Old/CC.Yi.Model/DataContext.cs
Normal file
14
CC.Yi.Old/CC.Yi.Model/DataContext.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
|
||||
namespace CC.Yi.Model
|
||||
{
|
||||
public partial class DataContext : DbContext
|
||||
{
|
||||
public DataContext(DbContextOptions<DataContext> options) : base(options)
|
||||
{
|
||||
|
||||
}
|
||||
//public DbSet<result_user> result_user { get; set; }
|
||||
}
|
||||
}
|
||||
13
CC.Yi.Old/CC.Yi.Model/result_user.cs
Normal file
13
CC.Yi.Old/CC.Yi.Model/result_user.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace CC.Yi.Model
|
||||
{
|
||||
public class result_user : IdentityUser
|
||||
{
|
||||
//你可以在这里添加你额外需要的字段例如
|
||||
//public int level { get; set; }
|
||||
}
|
||||
}
|
||||
94
CC.Yi.Old/CC.Yi.sln
Normal file
94
CC.Yi.Old/CC.Yi.sln
Normal file
@@ -0,0 +1,94 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.30907.101
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DAL", "DAL", "{9D0D4A54-057E-46C3-BBFE-CA01F7ECEDAE}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BLL", "BLL", "{CC5F4204-DFB6-4BB5-9E49-BED084063ED8}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "API", "API", "{1A509C83-F994-4422-A74F-8FFA4805D849}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CC.Yi.API", "CC.Yi.API\CC.Yi.API.csproj", "{CDB5556F-43FF-44F6-B33D-AC642E5CD30C}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CC.Yi.BLL", "CC.Yi.BLL\CC.Yi.BLL.csproj", "{AE9B4D8A-0CED-49D1-81C7-EBD221E41AB6}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CC.Yi.IBLL", "CC.Yi.IBLL\CC.Yi.IBLL.csproj", "{74177F89-72D5-45FE-8A4F-91FAD9E03D36}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CC.Yi.DAL", "CC.Yi.DAL\CC.Yi.DAL.csproj", "{72FD0850-15FA-4A6F-B865-E1B38603307D}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CC.Yi.IDAL", "CC.Yi.IDAL\CC.Yi.IDAL.csproj", "{BD77D98A-9F28-4C2D-A260-C3BB919B58E7}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{123D1D39-849C-4220-A973-EB9760421CB3}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Model", "Model", "{38B8D898-4BBF-4DDB-8E29-6D6CEB7808C9}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CC.Yi.Model", "CC.Yi.Model\CC.Yi.Model.csproj", "{8827547B-E04B-4430-A0DF-E87FCA40E3AB}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CC.Yi.ViewModel", "CC.Yi.ViewModel\CC.Yi.ViewModel.csproj", "{32F323F1-E2FA-4186-AC33-263465012D15}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CC.Yi.Common", "CC.Yi.Common\CC.Yi.Common.csproj", "{9D6E5DD7-FA02-4532-8BAC-406FB80AFEAC}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CC.Yi.DALFactory", "CC.Yi.DALFactory\CC.Yi.DALFactory.csproj", "{ACB6D3EE-FADE-4F07-9D12-C9E3A5F72335}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{CDB5556F-43FF-44F6-B33D-AC642E5CD30C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{CDB5556F-43FF-44F6-B33D-AC642E5CD30C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CDB5556F-43FF-44F6-B33D-AC642E5CD30C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CDB5556F-43FF-44F6-B33D-AC642E5CD30C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{AE9B4D8A-0CED-49D1-81C7-EBD221E41AB6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{AE9B4D8A-0CED-49D1-81C7-EBD221E41AB6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AE9B4D8A-0CED-49D1-81C7-EBD221E41AB6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AE9B4D8A-0CED-49D1-81C7-EBD221E41AB6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{74177F89-72D5-45FE-8A4F-91FAD9E03D36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{74177F89-72D5-45FE-8A4F-91FAD9E03D36}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{74177F89-72D5-45FE-8A4F-91FAD9E03D36}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{74177F89-72D5-45FE-8A4F-91FAD9E03D36}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{72FD0850-15FA-4A6F-B865-E1B38603307D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{72FD0850-15FA-4A6F-B865-E1B38603307D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{72FD0850-15FA-4A6F-B865-E1B38603307D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{72FD0850-15FA-4A6F-B865-E1B38603307D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{BD77D98A-9F28-4C2D-A260-C3BB919B58E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BD77D98A-9F28-4C2D-A260-C3BB919B58E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BD77D98A-9F28-4C2D-A260-C3BB919B58E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BD77D98A-9F28-4C2D-A260-C3BB919B58E7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8827547B-E04B-4430-A0DF-E87FCA40E3AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8827547B-E04B-4430-A0DF-E87FCA40E3AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8827547B-E04B-4430-A0DF-E87FCA40E3AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8827547B-E04B-4430-A0DF-E87FCA40E3AB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{32F323F1-E2FA-4186-AC33-263465012D15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{32F323F1-E2FA-4186-AC33-263465012D15}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{32F323F1-E2FA-4186-AC33-263465012D15}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{32F323F1-E2FA-4186-AC33-263465012D15}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9D6E5DD7-FA02-4532-8BAC-406FB80AFEAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9D6E5DD7-FA02-4532-8BAC-406FB80AFEAC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9D6E5DD7-FA02-4532-8BAC-406FB80AFEAC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9D6E5DD7-FA02-4532-8BAC-406FB80AFEAC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{ACB6D3EE-FADE-4F07-9D12-C9E3A5F72335}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{ACB6D3EE-FADE-4F07-9D12-C9E3A5F72335}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{ACB6D3EE-FADE-4F07-9D12-C9E3A5F72335}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{ACB6D3EE-FADE-4F07-9D12-C9E3A5F72335}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{CDB5556F-43FF-44F6-B33D-AC642E5CD30C} = {1A509C83-F994-4422-A74F-8FFA4805D849}
|
||||
{AE9B4D8A-0CED-49D1-81C7-EBD221E41AB6} = {CC5F4204-DFB6-4BB5-9E49-BED084063ED8}
|
||||
{74177F89-72D5-45FE-8A4F-91FAD9E03D36} = {CC5F4204-DFB6-4BB5-9E49-BED084063ED8}
|
||||
{72FD0850-15FA-4A6F-B865-E1B38603307D} = {9D0D4A54-057E-46C3-BBFE-CA01F7ECEDAE}
|
||||
{BD77D98A-9F28-4C2D-A260-C3BB919B58E7} = {9D0D4A54-057E-46C3-BBFE-CA01F7ECEDAE}
|
||||
{8827547B-E04B-4430-A0DF-E87FCA40E3AB} = {38B8D898-4BBF-4DDB-8E29-6D6CEB7808C9}
|
||||
{32F323F1-E2FA-4186-AC33-263465012D15} = {38B8D898-4BBF-4DDB-8E29-6D6CEB7808C9}
|
||||
{9D6E5DD7-FA02-4532-8BAC-406FB80AFEAC} = {123D1D39-849C-4220-A973-EB9760421CB3}
|
||||
{ACB6D3EE-FADE-4F07-9D12-C9E3A5F72335} = {9D0D4A54-057E-46C3-BBFE-CA01F7ECEDAE}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {22DD3529-6AD4-413A-B7B3-D8335E6F47C9}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -29,13 +29,14 @@ namespace CC.Yi.API.Controllers
|
||||
|
||||
//private UserManager<result_user> _userManager;//处理用户相关逻辑:添加密码,修改密码,添加删除角色等等
|
||||
//private SignInManager<result_user> _signInManager;//处理注册登录的相关逻辑
|
||||
|
||||
private IpropBll _propBll;
|
||||
private IstudentBll _studentBll;
|
||||
public StudentController(ILogger<StudentController> logger, IstudentBll studentBll)
|
||||
public StudentController(ILogger<StudentController> logger, IstudentBll studentBll,IpropBll propBll)
|
||||
{
|
||||
_logger = logger;
|
||||
_logger.LogInformation("现在你进入了StudentController控制器");
|
||||
_studentBll = studentBll;
|
||||
_propBll = propBll;
|
||||
}
|
||||
#region
|
||||
//关于身份认证配置使用:
|
||||
@@ -55,6 +56,31 @@ namespace CC.Yi.API.Controllers
|
||||
// return Ok();
|
||||
//}
|
||||
|
||||
[HttpGet]
|
||||
public Result test0()
|
||||
{
|
||||
|
||||
_propBll.Add(new prop { name = "666" });
|
||||
|
||||
return Result.Success();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public Result test1()
|
||||
{
|
||||
var data = _studentBll.GetEntities(u => u.id == 1).Include(u=>u.props).FirstOrDefault();
|
||||
var myp = _propBll.GetEntities(u => u.id == 1).FirstOrDefault();
|
||||
data.props.Add(myp);
|
||||
data.props.Add(myp);
|
||||
_studentBll.Update(data);
|
||||
return Result.Success().SetData(new {data.id, data.name,props=
|
||||
data.props.Select(u=>new {
|
||||
u.id,
|
||||
u.name
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public Result GetReids()
|
||||
{
|
||||
76
CC.Yi/CC.Yi.API/Extension/SwaggerExtension.cs
Normal file
76
CC.Yi/CC.Yi.API/Extension/SwaggerExtension.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace CC.Yi.API.Extension
|
||||
{
|
||||
/// <summary>
|
||||
/// Swagger文档扩展方法
|
||||
/// </summary>
|
||||
public static class SwaggerExtension
|
||||
{
|
||||
public static IServiceCollection AddSwaggerService(this IServiceCollection services)
|
||||
{
|
||||
var apiInfo = new OpenApiInfo
|
||||
{
|
||||
Title = "Yi意框架-API接口",
|
||||
Version = "v1",
|
||||
Contact = new OpenApiContact { Name = "橙子", Email = "454313500@qq.com", Url = new System.Uri("https://jiftcc.com") }
|
||||
};
|
||||
#region 注册Swagger服务
|
||||
services.AddSwaggerGen(c =>
|
||||
{
|
||||
c.SwaggerDoc("v1", apiInfo);
|
||||
|
||||
//添加注释服务
|
||||
//为 Swagger JSON and UI设置xml文档注释路径
|
||||
//获取应用程序所在目录(绝对路径,不受工作目录影响,建议采用此方法获取路径使用windwos&Linux)
|
||||
var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location);
|
||||
var apiXmlPath = Path.Combine(basePath, @"ApiDoc.xml");//控制器层注释
|
||||
var entityXmlPath = Path.Combine(basePath, @"Model\ModelDoc.xml");//实体注释
|
||||
//c.IncludeXmlComments(apiXmlPath, true);//true表示显示控制器注释
|
||||
//c.IncludeXmlComments(entityXmlPath);
|
||||
|
||||
//添加控制器注释
|
||||
//c.DocumentFilter<SwaggerDocTag>();
|
||||
|
||||
//添加header验证信息
|
||||
//c.OperationFilter<SwaggerHeader>();
|
||||
//var security = new Dictionary<string, IEnumerable<string>> { { "Bearer", new string[] { } }, };
|
||||
|
||||
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme()
|
||||
{
|
||||
Description = "文本框里输入从服务器获取的Token。格式为:Bearer + 空格+token",//JWT授权(数据将在请求头中进行传输) 参数结构: \"Authorization: Bearer {token}\"
|
||||
Name = "Authorization",////jwt默认的参数名称
|
||||
In = ParameterLocation.Header,////jwt默认存放Authorization信息的位置(请求头中)
|
||||
Type = SecuritySchemeType.ApiKey,
|
||||
});
|
||||
c.AddSecurityRequirement(new OpenApiSecurityRequirement
|
||||
{
|
||||
{ new OpenApiSecurityScheme
|
||||
{
|
||||
Reference = new OpenApiReference()
|
||||
{
|
||||
Id = "Bearer",
|
||||
Type = ReferenceType.SecurityScheme
|
||||
}
|
||||
}, Array.Empty<string>() }
|
||||
});
|
||||
});
|
||||
#endregion
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
public static void UseSwaggerService(this IApplicationBuilder app)
|
||||
{
|
||||
//在 Startup.Configure 方法中,启用中间件为生成的 JSON 文档和 Swagger UI 提供服务:
|
||||
// Enable middleware to serve generated Swagger as a JSON endpoint.
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "JwtTest v1"));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
70
CC.Yi/CC.Yi.API/Migrations/20210526080428_yi2.Designer.cs
generated
Normal file
70
CC.Yi/CC.Yi.API/Migrations/20210526080428_yi2.Designer.cs
generated
Normal file
@@ -0,0 +1,70 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using CC.Yi.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
namespace CC.Yi.API.Migrations
|
||||
{
|
||||
[DbContext(typeof(DataContext))]
|
||||
[Migration("20210526080428_yi2")]
|
||||
partial class yi2
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "5.0.5");
|
||||
|
||||
modelBuilder.Entity("CC.Yi.Model.prop", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("name")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("studentid")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.HasIndex("studentid");
|
||||
|
||||
b.ToTable("prop");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CC.Yi.Model.student", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("name")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.ToTable("student");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CC.Yi.Model.prop", b =>
|
||||
{
|
||||
b.HasOne("CC.Yi.Model.student", "student")
|
||||
.WithMany("props")
|
||||
.HasForeignKey("studentid");
|
||||
|
||||
b.Navigation("student");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CC.Yi.Model.student", b =>
|
||||
{
|
||||
b.Navigation("props");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
41
CC.Yi/CC.Yi.API/Migrations/20210526080428_yi2.cs
Normal file
41
CC.Yi/CC.Yi.API/Migrations/20210526080428_yi2.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace CC.Yi.API.Migrations
|
||||
{
|
||||
public partial class yi2 : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "prop",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
name = table.Column<string>(type: "TEXT", nullable: true),
|
||||
studentid = table.Column<int>(type: "INTEGER", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_prop", x => x.id);
|
||||
table.ForeignKey(
|
||||
name: "FK_prop_student_studentid",
|
||||
column: x => x.studentid,
|
||||
principalTable: "student",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_prop_studentid",
|
||||
table: "prop",
|
||||
column: "studentid");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "prop");
|
||||
}
|
||||
}
|
||||
}
|
||||
68
CC.Yi/CC.Yi.API/Migrations/DataContextModelSnapshot.cs
Normal file
68
CC.Yi/CC.Yi.API/Migrations/DataContextModelSnapshot.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using CC.Yi.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
namespace CC.Yi.API.Migrations
|
||||
{
|
||||
[DbContext(typeof(DataContext))]
|
||||
partial class DataContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "5.0.5");
|
||||
|
||||
modelBuilder.Entity("CC.Yi.Model.prop", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("name")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("studentid")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.HasIndex("studentid");
|
||||
|
||||
b.ToTable("prop");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CC.Yi.Model.student", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("name")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.ToTable("student");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CC.Yi.Model.prop", b =>
|
||||
{
|
||||
b.HasOne("CC.Yi.Model.student", "student")
|
||||
.WithMany("props")
|
||||
.HasForeignKey("studentid");
|
||||
|
||||
b.Navigation("student");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CC.Yi.Model.student", b =>
|
||||
{
|
||||
b.Navigation("props");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
31
CC.Yi/CC.Yi.API/Properties/launchSettings.json
Normal file
31
CC.Yi/CC.Yi.API/Properties/launchSettings.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:55197",
|
||||
"sslPort": 44334
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"CC.Yi.API": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": "true",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:5001;http://localhost:5000",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
24
CC.Yi/CC.Yi.API/T4Startup.cs
Normal file
24
CC.Yi/CC.Yi.API/T4Startup.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Autofac;
|
||||
using Autofac.Extras.DynamicProxy;
|
||||
using CC.Yi.BLL;
|
||||
using CC.Yi.Common.Castle;
|
||||
using CC.Yi.DAL;
|
||||
using CC.Yi.IBLL;
|
||||
using CC.Yi.IDAL;
|
||||
using System;
|
||||
|
||||
|
||||
namespace CC.Yi.API
|
||||
{
|
||||
public partial class Startup
|
||||
{
|
||||
//动态 面向AOP思想的依赖注入 Autofac
|
||||
public void ConfigureContainer(ContainerBuilder builder)
|
||||
{
|
||||
builder.RegisterType(typeof(CustomAutofacAop));
|
||||
builder.RegisterGeneric(typeof(BaseDal<>)).As(typeof(IBaseDal<>));
|
||||
builder.RegisterType<studentBll>().As<IstudentBll>().EnableInterfaceInterceptors();//表示注入前后要执行Castle,AOP
|
||||
builder.RegisterType<propBll>().As<IpropBll>().EnableInterfaceInterceptors();//表示注入前后要执行Castle,AOP
|
||||
}
|
||||
}
|
||||
}
|
||||
40
CC.Yi/CC.Yi.API/T4Startup.tt
Normal file
40
CC.Yi/CC.Yi.API/T4Startup.tt
Normal file
@@ -0,0 +1,40 @@
|
||||
<#@ template debug="false" hostspecific="true" language="C#" #>
|
||||
<#@ assembly name="System.Core" #>
|
||||
<#@ import namespace="System.Linq" #>
|
||||
<#@ import namespace="System.Text" #>
|
||||
<#@ import namespace="System.Collections.Generic" #>
|
||||
<#@ import namespace="System.IO" #>
|
||||
<#@ output extension=".cs" #>
|
||||
<#
|
||||
string solutionsPath = Host.ResolveAssemblyReference("$(SolutionDir)");//获取解决方案路径
|
||||
string txt;
|
||||
StreamReader sr = new StreamReader(solutionsPath+@"\T4Model\T4Model.txt");
|
||||
txt=sr.ReadToEnd();
|
||||
sr.Close();
|
||||
string[] ModelData= txt.Split(',');
|
||||
#>
|
||||
using Autofac;
|
||||
using Autofac.Extras.DynamicProxy;
|
||||
using CC.Yi.BLL;
|
||||
using CC.Yi.Common.Castle;
|
||||
using CC.Yi.DAL;
|
||||
using CC.Yi.IBLL;
|
||||
using CC.Yi.IDAL;
|
||||
using System;
|
||||
|
||||
|
||||
namespace CC.Yi.API
|
||||
{
|
||||
public partial class Startup
|
||||
{
|
||||
//动态 面向AOP思想的依赖注入 Autofac
|
||||
public void ConfigureContainer(ContainerBuilder builder)
|
||||
{
|
||||
builder.RegisterType(typeof(CustomAutofacAop));
|
||||
builder.RegisterGeneric(typeof(BaseDal<>)).As(typeof(IBaseDal<>));
|
||||
<# foreach(string k in ModelData){#>
|
||||
builder.RegisterType<<#=k #>Bll>().As<I<#=k #>Bll>().EnableInterfaceInterceptors();//表示注入前后要执行Castle,AOP
|
||||
<# } #>
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
CC.Yi/CC.Yi.API/YIDB.db
Normal file
BIN
CC.Yi/CC.Yi.API/YIDB.db
Normal file
Binary file not shown.
BIN
CC.Yi/CC.Yi.API/YIDB.db-shm
Normal file
BIN
CC.Yi/CC.Yi.API/YIDB.db-shm
Normal file
Binary file not shown.
Binary file not shown.
9
CC.Yi/CC.Yi.API/appsettings.Development.json
Normal file
9
CC.Yi/CC.Yi.API/appsettings.Development.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
35
CC.Yi/CC.Yi.API/nlog.config
Normal file
35
CC.Yi/CC.Yi.API/nlog.config
Normal file
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
autoReload="true"
|
||||
throwExceptions="false"
|
||||
internalLogLevel="Warn"
|
||||
internalLogFile="Logs\internal-nlog.txt">
|
||||
|
||||
<!-- enable asp.net core layout renderers -->
|
||||
<extensions>
|
||||
<add assembly="NLog.Web.AspNetCore"/>
|
||||
</extensions>
|
||||
|
||||
<targets>
|
||||
<!-- 写入文件配置 -->
|
||||
<!-- write logs to file -->
|
||||
<target xsi:type="File" name="allfile" fileName="Logs\nlog-all-${shortdate}.log"
|
||||
layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring} ${newline}" />
|
||||
|
||||
<!-- another file log, only own logs. Uses some ASP.NET core renderers -->
|
||||
<target xsi:type="File" name="ownFile-web" fileName="Logs\nlog-own-${shortdate}.log"
|
||||
layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action} ${newline}" />
|
||||
</targets>
|
||||
|
||||
<rules>
|
||||
<!--All logs, including from Microsoft-->
|
||||
<!--minlevel 改为Trace 跟踪全部 Error 只捕获异常-->
|
||||
<logger name="*" minlevel="Trace" writeTo="allfile" />
|
||||
|
||||
<!--Skip non-critical Microsoft logs and so log only own logs-->
|
||||
<logger name="Microsoft.*" maxlevel="Info" final="true" />
|
||||
<!-- BlackHole without writeTo -->
|
||||
<logger name="*" minlevel="Trace" writeTo="ownFile-web" />
|
||||
</rules>
|
||||
</nlog>
|
||||
29
CC.Yi/CC.Yi.BLL/T4BLL.cs
Normal file
29
CC.Yi/CC.Yi.BLL/T4BLL.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
|
||||
using CC.Yi.IBLL;
|
||||
using CC.Yi.IDAL;
|
||||
using CC.Yi.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace CC.Yi.BLL
|
||||
{
|
||||
public partial class studentBll : BaseBll<student>, IstudentBll
|
||||
{
|
||||
public studentBll(IBaseDal<student> cd,DataContext _Db):base(cd,_Db)
|
||||
{
|
||||
CurrentDal = cd;
|
||||
DbSession = _Db;
|
||||
}
|
||||
}
|
||||
public partial class propBll : BaseBll<prop>, IpropBll
|
||||
{
|
||||
public propBll(IBaseDal<prop> cd,DataContext _Db):base(cd,_Db)
|
||||
{
|
||||
CurrentDal = cd;
|
||||
DbSession = _Db;
|
||||
}
|
||||
}
|
||||
}
|
||||
51
CC.Yi/CC.Yi.Common/Cache/CacheHelper.cs
Normal file
51
CC.Yi/CC.Yi.Common/Cache/CacheHelper.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using Autofac;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace CC.Yi.Common.Cache
|
||||
{
|
||||
public class CacheHelper
|
||||
{
|
||||
public static ICacheWriter CacheWriter { get; set; }
|
||||
static CacheHelper()
|
||||
{
|
||||
CacheHelper.CacheWriter = new RedisCache();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public bool AddCache<T>(string key, T value, DateTime expDate)
|
||||
{
|
||||
return CacheWriter.AddCache<T>(key,value,expDate);
|
||||
}
|
||||
|
||||
public bool AddCache<T>(string key, T value)
|
||||
{
|
||||
return CacheWriter.AddCache<T>(key, value);
|
||||
}
|
||||
|
||||
public bool RemoveCache(string key)
|
||||
{
|
||||
return CacheWriter.RemoveCache(key);
|
||||
}
|
||||
|
||||
public T GetCache<T>(string key)
|
||||
{
|
||||
return CacheWriter.GetCache<T>(key);
|
||||
}
|
||||
|
||||
public bool SetCache<T>(string key, T value, DateTime expDate)
|
||||
{
|
||||
return CacheWriter.SetCache<T>(key,value,expDate);
|
||||
}
|
||||
|
||||
public bool SetCache<T>(string key, T value)
|
||||
{
|
||||
return CacheWriter.SetCache<T>(key, value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
18
CC.Yi/CC.Yi.Common/Cache/ICacheWriter.cs
Normal file
18
CC.Yi/CC.Yi.Common/Cache/ICacheWriter.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CC.Yi.Common.Cache
|
||||
{
|
||||
public interface ICacheWriter
|
||||
{
|
||||
bool AddCache<T>(string key, T value, DateTime expDate);
|
||||
bool AddCache<T>(string key, T value);
|
||||
bool RemoveCache(string key);
|
||||
T GetCache<T>(string key);
|
||||
bool SetCache<T>(string key, T value, DateTime expDate);
|
||||
bool SetCache<T>(string key, T value);
|
||||
}
|
||||
}
|
||||
23
CC.Yi/CC.Yi.Common/Castle/CustomAutofacAop.cs
Normal file
23
CC.Yi/CC.Yi.Common/Castle/CustomAutofacAop.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Castle.DynamicProxy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace CC.Yi.Common.Castle
|
||||
{
|
||||
public class CustomAutofacAop : IInterceptor
|
||||
{
|
||||
public void Intercept(IInvocation invocation)
|
||||
{
|
||||
{
|
||||
|
||||
//这里写执行方法前
|
||||
}
|
||||
invocation.Proceed();//执行具体的实例
|
||||
{
|
||||
|
||||
//这里写执行方法后
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user