From 2bd67778bff6f5860152c78c34cf13bf76c4a4d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Mon, 31 May 2021 21:41:27 +0800 Subject: [PATCH] v3.0.0 v3.0.0 --- CC.Yi.Old/CC.Yi.API/CC.Yi.API.csproj | 50 +++ .../Controllers/StudentController.cs | 175 ++++++++++ .../CC.Yi.API}/Extension/SwaggerExtension.cs | 0 CC.Yi.Old/CC.Yi.API/Filter/DbContextFilter.cs | 22 ++ .../Migrations/20210319112041_yi1.Designer.cs | 40 +++ .../Migrations/20210319112041_yi1.cs | 29 ++ .../Migrations/20210320082935_yi2.Designer.cs | 40 +++ .../Migrations/20210320082935_yi2.cs | 31 ++ .../Migrations/20210325123550_yi3.Designer.cs | 93 ++++++ .../Migrations/20210325123550_yi3.cs | 42 +++ .../Migrations/20210325124241_yi4.Designer.cs | 301 +++++++++++++++++ .../Migrations/20210325124241_yi4.cs | 315 ++++++++++++++++++ .../Migrations/20210410090937_yi5.Designer.cs | 40 +++ .../Migrations/20210410090937_yi5.cs | 220 ++++++++++++ .../Migrations/DataContextModelSnapshot.cs | 10 +- CC.Yi.Old/CC.Yi.API/Program.cs | 62 ++++ .../CC.Yi.API}/Properties/launchSettings.json | 0 CC.Yi.Old/CC.Yi.API/Startup.cs | 164 +++++++++ .../CC.Yi.API}/T4Startup.cs | 0 .../CC.Yi.API}/T4Startup.tt | 0 .../CC.Yi.API}/appsettings.Development.json | 0 CC.Yi.Old/CC.Yi.API/appsettings.json | 17 + .../CC.Yi.API}/nlog.config | 0 CC.Yi.Old/CC.Yi.BLL/BaseBll.cs | 109 ++++++ CC.Yi.Old/CC.Yi.BLL/CC.Yi.BLL.csproj | 32 ++ {CC.Yi.BLL => CC.Yi.Old/CC.Yi.BLL}/T4BLL.cs | 4 +- CC.Yi.Old/CC.Yi.BLL/T4BLL.tt | 37 ++ CC.Yi.Old/CC.Yi.Common/CC.Yi.Common.csproj | 17 + .../CC.Yi.Common}/Cache/CacheHelper.cs | 0 .../CC.Yi.Common}/Cache/ICacheWriter.cs | 0 CC.Yi.Old/CC.Yi.Common/Cache/RedisCache.cs | 48 +++ .../CC.Yi.Common}/Castle/CustomAutofacAop.cs | 0 .../CC.Yi.Common}/HttpHelper.cs | 0 .../CC.Yi.Common/ImageHelper.cs | 0 CC.Yi.Old/CC.Yi.Common/JsonHelper.cs | 24 ++ .../CC.Yi.Common}/Jwt/JwtConst.cs | 0 CC.Yi.Old/CC.Yi.Common/Result.cs | 40 +++ CC.Yi.Old/CC.Yi.DAL/BaseDal.cs | 113 +++++++ .../CC.Yi.DAL}/CC.Yi.DAL.csproj | 0 CC.Yi.Old/CC.Yi.DAL/DbContentFactory.cs | 58 ++++ CC.Yi.Old/CC.Yi.DAL/T4DAL.cs | 12 + CC.Yi.Old/CC.Yi.DAL/T4DAL.tt | 30 ++ .../CC.Yi.DALFactory/CC.Yi.DALFactory.csproj | 40 +++ CC.Yi.Old/CC.Yi.DALFactory/DbSession.cs | 45 +++ .../CC.Yi.DALFactory/DbSessionFactory.cs | 35 ++ .../CC.Yi.DALFactory/StaticDalFactory.cs | 24 ++ CC.Yi.Old/CC.Yi.DALFactory/T4DbSession.cs | 18 + CC.Yi.Old/CC.Yi.DALFactory/T4DbSession.tt | 36 ++ .../CC.Yi.DALFactory/T4StaticDalFactory.cs | 25 ++ .../CC.Yi.DALFactory/T4StaticDalFactory.tt | 43 +++ .../CC.Yi.IBLL}/CC.Yi.IBLL.csproj | 0 CC.Yi.Old/CC.Yi.IBLL/IBaseBll.cs | 78 +++++ .../CC.Yi.IBLL}/T4IBLL.cs | 0 .../CC.Yi.IBLL}/T4IBLL.tt | 0 CC.Yi.Old/CC.Yi.IDAL/CC.Yi.IDAL.csproj | 40 +++ .../CC.Yi.IDAL}/IBaseDal.cs | 0 CC.Yi.Old/CC.Yi.IDAL/IDbSession.cs | 18 + .../CC.Yi.IDAL}/T4IDAL.cs | 0 .../CC.Yi.IDAL}/T4IDAL.tt | 0 CC.Yi.Old/CC.Yi.IDAL/T4IDbSession.cs | 15 + CC.Yi.Old/CC.Yi.IDAL/T4IDbSession.tt | 33 ++ CC.Yi.Old/CC.Yi.Model/CC.Yi.Model.csproj | 43 +++ CC.Yi.Old/CC.Yi.Model/DataContext.cs | 14 + .../CC.Yi.Model}/T4DataContext.cs | 0 .../CC.Yi.Model}/T4DataContext.tt | 0 CC.Yi.Old/CC.Yi.Model/result_user.cs | 13 + .../CC.Yi.Model}/student.cs | 0 .../CC.Yi.ViewModel}/CC.Yi.ViewModel.csproj | 0 CC.Yi.Old/CC.Yi.sln | 94 ++++++ {T4Model => CC.Yi.Old/T4Model}/T4Model.txt | 0 {T4Model => CC.Yi.Old/T4Model}/说明.txt | 0 .../CC.Yi.API}/CC.Yi.API.csproj | 0 .../Controllers/StudentController.cs | 30 +- CC.Yi/CC.Yi.API/Extension/SwaggerExtension.cs | 76 +++++ .../CC.Yi.API}/Filter/DbContextFilter.cs | 0 .../Migrations/20210413063257_y1.Designer.cs | 0 .../Migrations/20210413063257_y1.cs | 0 .../Migrations/20210526080428_yi2.Designer.cs | 70 ++++ .../Migrations/20210526080428_yi2.cs | 41 +++ .../Migrations/DataContextModelSnapshot.cs | 68 ++++ {CC.Yi.API => CC.Yi/CC.Yi.API}/Program.cs | 0 .../CC.Yi.API/Properties/launchSettings.json | 31 ++ {CC.Yi.API => CC.Yi/CC.Yi.API}/Startup.cs | 0 CC.Yi/CC.Yi.API/T4Startup.cs | 24 ++ CC.Yi/CC.Yi.API/T4Startup.tt | 40 +++ CC.Yi/CC.Yi.API/YIDB.db | Bin 0 -> 28672 bytes CC.Yi/CC.Yi.API/YIDB.db-shm | Bin 0 -> 32768 bytes .../YIDB.db => CC.Yi/CC.Yi.API/YIDB.db-wal | Bin 20480 -> 20632 bytes CC.Yi/CC.Yi.API/appsettings.Development.json | 9 + .../CC.Yi.API}/appsettings.json | 0 CC.Yi/CC.Yi.API/nlog.config | 35 ++ {CC.Yi.BLL => CC.Yi/CC.Yi.BLL}/BaseBll.cs | 0 .../CC.Yi.BLL}/CC.Yi.BLL.csproj | 0 CC.Yi/CC.Yi.BLL/T4BLL.cs | 29 ++ {CC.Yi.BLL => CC.Yi/CC.Yi.BLL}/T4BLL.tt | 0 .../CC.Yi.Common}/CC.Yi.Common.csproj | 0 CC.Yi/CC.Yi.Common/Cache/CacheHelper.cs | 51 +++ CC.Yi/CC.Yi.Common/Cache/ICacheWriter.cs | 18 + .../CC.Yi.Common}/Cache/RedisCache.cs | 0 CC.Yi/CC.Yi.Common/Castle/CustomAutofacAop.cs | 23 ++ CC.Yi/CC.Yi.Common/HttpHelper.cs | 76 +++++ .../CC.Yi.Common}/JsonHelper.cs | 0 CC.Yi/CC.Yi.Common/Jwt/JwtConst.cs | 12 + .../CC.Yi.Common}/Result.cs | 0 CC.Yi/CC.Yi.Common/imageHelper.cs | 167 ++++++++++ {CC.Yi.DAL => CC.Yi/CC.Yi.DAL}/BaseDal.cs | 0 CC.Yi/CC.Yi.DAL/CC.Yi.DAL.csproj | 31 ++ {CC.Yi.DAL => CC.Yi/CC.Yi.DAL}/T4DAL.cs | 7 + {CC.Yi.DAL => CC.Yi/CC.Yi.DAL}/T4DAL.tt | 0 CC.Yi/CC.Yi.IBLL/CC.Yi.IBLL.csproj | 32 ++ {CC.Yi.IBLL => CC.Yi/CC.Yi.IBLL}/IBaseBll.cs | 0 CC.Yi/CC.Yi.IBLL/T4IBLL.cs | 14 + CC.Yi/CC.Yi.IBLL/T4IBLL.tt | 29 ++ .../CC.Yi.IDAL}/CC.Yi.IDAL.csproj | 0 CC.Yi/CC.Yi.IDAL/IBaseDal.cs | 69 ++++ CC.Yi/CC.Yi.IDAL/T4IDAL.cs | 14 + CC.Yi/CC.Yi.IDAL/T4IDAL.tt | 29 ++ .../CC.Yi.Model}/CC.Yi.Model.csproj | 0 .../CC.Yi.Model}/DataContext.cs | 0 CC.Yi/CC.Yi.Model/T4DataContext.cs | 12 + CC.Yi/CC.Yi.Model/T4DataContext.tt | 29 ++ CC.Yi/CC.Yi.Model/prop.cs | 17 + CC.Yi/CC.Yi.Model/student.cs | 17 + CC.Yi/CC.Yi.ViewModel/CC.Yi.ViewModel.csproj | 8 + CC.Yi.sln => CC.Yi/CC.Yi.sln | 0 CC.Yi/T4Model/T4Model.txt | 1 + CC.Yi/T4Model/说明.txt | 5 + 127 files changed, 3895 insertions(+), 8 deletions(-) create mode 100644 CC.Yi.Old/CC.Yi.API/CC.Yi.API.csproj create mode 100644 CC.Yi.Old/CC.Yi.API/Controllers/StudentController.cs rename {CC.Yi.API => CC.Yi.Old/CC.Yi.API}/Extension/SwaggerExtension.cs (100%) create mode 100644 CC.Yi.Old/CC.Yi.API/Filter/DbContextFilter.cs create mode 100644 CC.Yi.Old/CC.Yi.API/Migrations/20210319112041_yi1.Designer.cs create mode 100644 CC.Yi.Old/CC.Yi.API/Migrations/20210319112041_yi1.cs create mode 100644 CC.Yi.Old/CC.Yi.API/Migrations/20210320082935_yi2.Designer.cs create mode 100644 CC.Yi.Old/CC.Yi.API/Migrations/20210320082935_yi2.cs create mode 100644 CC.Yi.Old/CC.Yi.API/Migrations/20210325123550_yi3.Designer.cs create mode 100644 CC.Yi.Old/CC.Yi.API/Migrations/20210325123550_yi3.cs create mode 100644 CC.Yi.Old/CC.Yi.API/Migrations/20210325124241_yi4.Designer.cs create mode 100644 CC.Yi.Old/CC.Yi.API/Migrations/20210325124241_yi4.cs create mode 100644 CC.Yi.Old/CC.Yi.API/Migrations/20210410090937_yi5.Designer.cs create mode 100644 CC.Yi.Old/CC.Yi.API/Migrations/20210410090937_yi5.cs rename {CC.Yi.API => CC.Yi.Old/CC.Yi.API}/Migrations/DataContextModelSnapshot.cs (61%) create mode 100644 CC.Yi.Old/CC.Yi.API/Program.cs rename {CC.Yi.API => CC.Yi.Old/CC.Yi.API}/Properties/launchSettings.json (100%) create mode 100644 CC.Yi.Old/CC.Yi.API/Startup.cs rename {CC.Yi.API => CC.Yi.Old/CC.Yi.API}/T4Startup.cs (100%) rename {CC.Yi.API => CC.Yi.Old/CC.Yi.API}/T4Startup.tt (100%) rename {CC.Yi.API => CC.Yi.Old/CC.Yi.API}/appsettings.Development.json (100%) create mode 100644 CC.Yi.Old/CC.Yi.API/appsettings.json rename {CC.Yi.API => CC.Yi.Old/CC.Yi.API}/nlog.config (100%) create mode 100644 CC.Yi.Old/CC.Yi.BLL/BaseBll.cs create mode 100644 CC.Yi.Old/CC.Yi.BLL/CC.Yi.BLL.csproj rename {CC.Yi.BLL => CC.Yi.Old/CC.Yi.BLL}/T4BLL.cs (68%) create mode 100644 CC.Yi.Old/CC.Yi.BLL/T4BLL.tt create mode 100644 CC.Yi.Old/CC.Yi.Common/CC.Yi.Common.csproj rename {CC.Yi.Common => CC.Yi.Old/CC.Yi.Common}/Cache/CacheHelper.cs (100%) rename {CC.Yi.Common => CC.Yi.Old/CC.Yi.Common}/Cache/ICacheWriter.cs (100%) create mode 100644 CC.Yi.Old/CC.Yi.Common/Cache/RedisCache.cs rename {CC.Yi.Common => CC.Yi.Old/CC.Yi.Common}/Castle/CustomAutofacAop.cs (100%) rename {CC.Yi.Common => CC.Yi.Old/CC.Yi.Common}/HttpHelper.cs (100%) rename CC.Yi.Common/imageHelper.cs => CC.Yi.Old/CC.Yi.Common/ImageHelper.cs (100%) create mode 100644 CC.Yi.Old/CC.Yi.Common/JsonHelper.cs rename {CC.Yi.Common => CC.Yi.Old/CC.Yi.Common}/Jwt/JwtConst.cs (100%) create mode 100644 CC.Yi.Old/CC.Yi.Common/Result.cs create mode 100644 CC.Yi.Old/CC.Yi.DAL/BaseDal.cs rename {CC.Yi.DAL => CC.Yi.Old/CC.Yi.DAL}/CC.Yi.DAL.csproj (100%) create mode 100644 CC.Yi.Old/CC.Yi.DAL/DbContentFactory.cs create mode 100644 CC.Yi.Old/CC.Yi.DAL/T4DAL.cs create mode 100644 CC.Yi.Old/CC.Yi.DAL/T4DAL.tt create mode 100644 CC.Yi.Old/CC.Yi.DALFactory/CC.Yi.DALFactory.csproj create mode 100644 CC.Yi.Old/CC.Yi.DALFactory/DbSession.cs create mode 100644 CC.Yi.Old/CC.Yi.DALFactory/DbSessionFactory.cs create mode 100644 CC.Yi.Old/CC.Yi.DALFactory/StaticDalFactory.cs create mode 100644 CC.Yi.Old/CC.Yi.DALFactory/T4DbSession.cs create mode 100644 CC.Yi.Old/CC.Yi.DALFactory/T4DbSession.tt create mode 100644 CC.Yi.Old/CC.Yi.DALFactory/T4StaticDalFactory.cs create mode 100644 CC.Yi.Old/CC.Yi.DALFactory/T4StaticDalFactory.tt rename {CC.Yi.IBLL => CC.Yi.Old/CC.Yi.IBLL}/CC.Yi.IBLL.csproj (100%) create mode 100644 CC.Yi.Old/CC.Yi.IBLL/IBaseBll.cs rename {CC.Yi.IBLL => CC.Yi.Old/CC.Yi.IBLL}/T4IBLL.cs (100%) rename {CC.Yi.IBLL => CC.Yi.Old/CC.Yi.IBLL}/T4IBLL.tt (100%) create mode 100644 CC.Yi.Old/CC.Yi.IDAL/CC.Yi.IDAL.csproj rename {CC.Yi.IDAL => CC.Yi.Old/CC.Yi.IDAL}/IBaseDal.cs (100%) create mode 100644 CC.Yi.Old/CC.Yi.IDAL/IDbSession.cs rename {CC.Yi.IDAL => CC.Yi.Old/CC.Yi.IDAL}/T4IDAL.cs (100%) rename {CC.Yi.IDAL => CC.Yi.Old/CC.Yi.IDAL}/T4IDAL.tt (100%) create mode 100644 CC.Yi.Old/CC.Yi.IDAL/T4IDbSession.cs create mode 100644 CC.Yi.Old/CC.Yi.IDAL/T4IDbSession.tt create mode 100644 CC.Yi.Old/CC.Yi.Model/CC.Yi.Model.csproj create mode 100644 CC.Yi.Old/CC.Yi.Model/DataContext.cs rename {CC.Yi.Model => CC.Yi.Old/CC.Yi.Model}/T4DataContext.cs (100%) rename {CC.Yi.Model => CC.Yi.Old/CC.Yi.Model}/T4DataContext.tt (100%) create mode 100644 CC.Yi.Old/CC.Yi.Model/result_user.cs rename {CC.Yi.Model => CC.Yi.Old/CC.Yi.Model}/student.cs (100%) rename {CC.Yi.ViewModel => CC.Yi.Old/CC.Yi.ViewModel}/CC.Yi.ViewModel.csproj (100%) create mode 100644 CC.Yi.Old/CC.Yi.sln rename {T4Model => CC.Yi.Old/T4Model}/T4Model.txt (100%) rename {T4Model => CC.Yi.Old/T4Model}/说明.txt (100%) rename {CC.Yi.API => CC.Yi/CC.Yi.API}/CC.Yi.API.csproj (100%) rename {CC.Yi.API => CC.Yi/CC.Yi.API}/Controllers/StudentController.cs (87%) create mode 100644 CC.Yi/CC.Yi.API/Extension/SwaggerExtension.cs rename {CC.Yi.API => CC.Yi/CC.Yi.API}/Filter/DbContextFilter.cs (100%) rename {CC.Yi.API => CC.Yi/CC.Yi.API}/Migrations/20210413063257_y1.Designer.cs (100%) rename {CC.Yi.API => CC.Yi/CC.Yi.API}/Migrations/20210413063257_y1.cs (100%) create mode 100644 CC.Yi/CC.Yi.API/Migrations/20210526080428_yi2.Designer.cs create mode 100644 CC.Yi/CC.Yi.API/Migrations/20210526080428_yi2.cs create mode 100644 CC.Yi/CC.Yi.API/Migrations/DataContextModelSnapshot.cs rename {CC.Yi.API => CC.Yi/CC.Yi.API}/Program.cs (100%) create mode 100644 CC.Yi/CC.Yi.API/Properties/launchSettings.json rename {CC.Yi.API => CC.Yi/CC.Yi.API}/Startup.cs (100%) create mode 100644 CC.Yi/CC.Yi.API/T4Startup.cs create mode 100644 CC.Yi/CC.Yi.API/T4Startup.tt create mode 100644 CC.Yi/CC.Yi.API/YIDB.db create mode 100644 CC.Yi/CC.Yi.API/YIDB.db-shm rename CC.Yi.API/YIDB.db => CC.Yi/CC.Yi.API/YIDB.db-wal (93%) create mode 100644 CC.Yi/CC.Yi.API/appsettings.Development.json rename {CC.Yi.API => CC.Yi/CC.Yi.API}/appsettings.json (100%) create mode 100644 CC.Yi/CC.Yi.API/nlog.config rename {CC.Yi.BLL => CC.Yi/CC.Yi.BLL}/BaseBll.cs (100%) rename {CC.Yi.BLL => CC.Yi/CC.Yi.BLL}/CC.Yi.BLL.csproj (100%) create mode 100644 CC.Yi/CC.Yi.BLL/T4BLL.cs rename {CC.Yi.BLL => CC.Yi/CC.Yi.BLL}/T4BLL.tt (100%) rename {CC.Yi.Common => CC.Yi/CC.Yi.Common}/CC.Yi.Common.csproj (100%) create mode 100644 CC.Yi/CC.Yi.Common/Cache/CacheHelper.cs create mode 100644 CC.Yi/CC.Yi.Common/Cache/ICacheWriter.cs rename {CC.Yi.Common => CC.Yi/CC.Yi.Common}/Cache/RedisCache.cs (100%) create mode 100644 CC.Yi/CC.Yi.Common/Castle/CustomAutofacAop.cs create mode 100644 CC.Yi/CC.Yi.Common/HttpHelper.cs rename {CC.Yi.Common => CC.Yi/CC.Yi.Common}/JsonHelper.cs (100%) create mode 100644 CC.Yi/CC.Yi.Common/Jwt/JwtConst.cs rename {CC.Yi.Common => CC.Yi/CC.Yi.Common}/Result.cs (100%) create mode 100644 CC.Yi/CC.Yi.Common/imageHelper.cs rename {CC.Yi.DAL => CC.Yi/CC.Yi.DAL}/BaseDal.cs (100%) create mode 100644 CC.Yi/CC.Yi.DAL/CC.Yi.DAL.csproj rename {CC.Yi.DAL => CC.Yi/CC.Yi.DAL}/T4DAL.cs (67%) rename {CC.Yi.DAL => CC.Yi/CC.Yi.DAL}/T4DAL.tt (100%) create mode 100644 CC.Yi/CC.Yi.IBLL/CC.Yi.IBLL.csproj rename {CC.Yi.IBLL => CC.Yi/CC.Yi.IBLL}/IBaseBll.cs (100%) create mode 100644 CC.Yi/CC.Yi.IBLL/T4IBLL.cs create mode 100644 CC.Yi/CC.Yi.IBLL/T4IBLL.tt rename {CC.Yi.IDAL => CC.Yi/CC.Yi.IDAL}/CC.Yi.IDAL.csproj (100%) create mode 100644 CC.Yi/CC.Yi.IDAL/IBaseDal.cs create mode 100644 CC.Yi/CC.Yi.IDAL/T4IDAL.cs create mode 100644 CC.Yi/CC.Yi.IDAL/T4IDAL.tt rename {CC.Yi.Model => CC.Yi/CC.Yi.Model}/CC.Yi.Model.csproj (100%) rename {CC.Yi.Model => CC.Yi/CC.Yi.Model}/DataContext.cs (100%) create mode 100644 CC.Yi/CC.Yi.Model/T4DataContext.cs create mode 100644 CC.Yi/CC.Yi.Model/T4DataContext.tt create mode 100644 CC.Yi/CC.Yi.Model/prop.cs create mode 100644 CC.Yi/CC.Yi.Model/student.cs create mode 100644 CC.Yi/CC.Yi.ViewModel/CC.Yi.ViewModel.csproj rename CC.Yi.sln => CC.Yi/CC.Yi.sln (100%) create mode 100644 CC.Yi/T4Model/T4Model.txt create mode 100644 CC.Yi/T4Model/说明.txt diff --git a/CC.Yi.Old/CC.Yi.API/CC.Yi.API.csproj b/CC.Yi.Old/CC.Yi.API/CC.Yi.API.csproj new file mode 100644 index 00000000..6b3e84cf --- /dev/null +++ b/CC.Yi.Old/CC.Yi.API/CC.Yi.API.csproj @@ -0,0 +1,50 @@ + + + + net5.0 + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + Always + + + + + + + + + + True + True + T4Startup.tt + + + + + + TextTemplatingFileGenerator + T4Startup.cs + + + + diff --git a/CC.Yi.Old/CC.Yi.API/Controllers/StudentController.cs b/CC.Yi.Old/CC.Yi.API/Controllers/StudentController.cs new file mode 100644 index 00000000..ecbe8d2f --- /dev/null +++ b/CC.Yi.Old/CC.Yi.API/Controllers/StudentController.cs @@ -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 _logger;//处理日志相关文件 + + //private UserManager _userManager;//处理用户相关逻辑:添加密码,修改密码,添加删除角色等等 + //private SignInManager _signInManager;//处理注册登录的相关逻辑 + + private IstudentBll _studentBll; + public StudentController(ILogger logger, IstudentBll studentBll) + { + + _logger = logger; + _logger.LogInformation("现在你进入了StudentController控制器"); + _studentBll = studentBll; + //_userManager = userManager; + //_signInManager = signInManager; + } + #region + //关于身份认证配置使用: + //在需要身份认证的控制器上打上 [Authorize] 特性标签 + #endregion + //[HttpGet] + //public async Task 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("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 GetTest()//查 + { + _logger.LogInformation("调用查方法"); + var data =await _studentBll.GetAllEntities().ToListAsync(); + return Result.Success("查询成功").SetData(data); + } + [HttpGet] + [DbContextFilter] + public Result AddTest()//增 + { + _logger.LogInformation("调用增方法"); + List students = new List() {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("修改失败"); + } + + } + } +} diff --git a/CC.Yi.API/Extension/SwaggerExtension.cs b/CC.Yi.Old/CC.Yi.API/Extension/SwaggerExtension.cs similarity index 100% rename from CC.Yi.API/Extension/SwaggerExtension.cs rename to CC.Yi.Old/CC.Yi.API/Extension/SwaggerExtension.cs diff --git a/CC.Yi.Old/CC.Yi.API/Filter/DbContextFilter.cs b/CC.Yi.Old/CC.Yi.API/Filter/DbContextFilter.cs new file mode 100644 index 00000000..82fd8aac --- /dev/null +++ b/CC.Yi.Old/CC.Yi.API/Filter/DbContextFilter.cs @@ -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); + + } + } +} diff --git a/CC.Yi.Old/CC.Yi.API/Migrations/20210319112041_yi1.Designer.cs b/CC.Yi.Old/CC.Yi.API/Migrations/20210319112041_yi1.Designer.cs new file mode 100644 index 00000000..fa669c28 --- /dev/null +++ b/CC.Yi.Old/CC.Yi.API/Migrations/20210319112041_yi1.Designer.cs @@ -0,0 +1,40 @@ +// +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("id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("name") + .HasColumnType("int"); + + b.HasKey("id"); + + b.ToTable("student"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/CC.Yi.Old/CC.Yi.API/Migrations/20210319112041_yi1.cs b/CC.Yi.Old/CC.Yi.API/Migrations/20210319112041_yi1.cs new file mode 100644 index 00000000..03299091 --- /dev/null +++ b/CC.Yi.Old/CC.Yi.API/Migrations/20210319112041_yi1.cs @@ -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(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + name = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_student", x => x.id); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "student"); + } + } +} diff --git a/CC.Yi.Old/CC.Yi.API/Migrations/20210320082935_yi2.Designer.cs b/CC.Yi.Old/CC.Yi.API/Migrations/20210320082935_yi2.Designer.cs new file mode 100644 index 00000000..c9bbf025 --- /dev/null +++ b/CC.Yi.Old/CC.Yi.API/Migrations/20210320082935_yi2.Designer.cs @@ -0,0 +1,40 @@ +// +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("id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("name") + .HasColumnType("nvarchar(max)"); + + b.HasKey("id"); + + b.ToTable("student"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/CC.Yi.Old/CC.Yi.API/Migrations/20210320082935_yi2.cs b/CC.Yi.Old/CC.Yi.API/Migrations/20210320082935_yi2.cs new file mode 100644 index 00000000..6875efa1 --- /dev/null +++ b/CC.Yi.Old/CC.Yi.API/Migrations/20210320082935_yi2.cs @@ -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( + name: "name", + table: "student", + type: "nvarchar(max)", + nullable: true, + oldClrType: typeof(int), + oldType: "int"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "name", + table: "student", + type: "int", + nullable: false, + defaultValue: 0, + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldNullable: true); + } + } +} diff --git a/CC.Yi.Old/CC.Yi.API/Migrations/20210325123550_yi3.Designer.cs b/CC.Yi.Old/CC.Yi.API/Migrations/20210325123550_yi3.Designer.cs new file mode 100644 index 00000000..2803473c --- /dev/null +++ b/CC.Yi.Old/CC.Yi.API/Migrations/20210325123550_yi3.Designer.cs @@ -0,0 +1,93 @@ +// +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("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasColumnType("nvarchar(max)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + b.Property("LockoutEnabled") + .HasColumnType("bit"); + + b.Property("LockoutEnd") + .HasColumnType("datetimeoffset"); + + b.Property("NormalizedEmail") + .HasColumnType("nvarchar(max)"); + + b.Property("NormalizedUserName") + .HasColumnType("nvarchar(max)"); + + b.Property("PasswordHash") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("bit"); + + b.Property("SecurityStamp") + .HasColumnType("nvarchar(max)"); + + b.Property("TwoFactorEnabled") + .HasColumnType("bit"); + + b.Property("UserName") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("result_user"); + }); + + modelBuilder.Entity("CC.Yi.Model.student", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("name") + .HasColumnType("nvarchar(max)"); + + b.HasKey("id"); + + b.ToTable("student"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/CC.Yi.Old/CC.Yi.API/Migrations/20210325123550_yi3.cs b/CC.Yi.Old/CC.Yi.API/Migrations/20210325123550_yi3.cs new file mode 100644 index 00000000..ba0128cc --- /dev/null +++ b/CC.Yi.Old/CC.Yi.API/Migrations/20210325123550_yi3.cs @@ -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(type: "nvarchar(450)", nullable: false), + UserName = table.Column(type: "nvarchar(max)", nullable: true), + NormalizedUserName = table.Column(type: "nvarchar(max)", nullable: true), + Email = table.Column(type: "nvarchar(max)", nullable: true), + NormalizedEmail = table.Column(type: "nvarchar(max)", nullable: true), + EmailConfirmed = table.Column(type: "bit", nullable: false), + PasswordHash = table.Column(type: "nvarchar(max)", nullable: true), + SecurityStamp = table.Column(type: "nvarchar(max)", nullable: true), + ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true), + PhoneNumber = table.Column(type: "nvarchar(max)", nullable: true), + PhoneNumberConfirmed = table.Column(type: "bit", nullable: false), + TwoFactorEnabled = table.Column(type: "bit", nullable: false), + LockoutEnd = table.Column(type: "datetimeoffset", nullable: true), + LockoutEnabled = table.Column(type: "bit", nullable: false), + AccessFailedCount = table.Column(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"); + } + } +} diff --git a/CC.Yi.Old/CC.Yi.API/Migrations/20210325124241_yi4.Designer.cs b/CC.Yi.Old/CC.Yi.API/Migrations/20210325124241_yi4.Designer.cs new file mode 100644 index 00000000..dff90a75 --- /dev/null +++ b/CC.Yi.Old/CC.Yi.API/Migrations/20210325124241_yi4.Designer.cs @@ -0,0 +1,301 @@ +// +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("id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("name") + .HasColumnType("nvarchar(max)"); + + b.HasKey("id"); + + b.ToTable("student"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("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", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Discriminator") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + b.Property("LockoutEnabled") + .HasColumnType("bit"); + + b.Property("LockoutEnd") + .HasColumnType("datetimeoffset"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("PasswordHash") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("bit"); + + b.Property("SecurityStamp") + .HasColumnType("nvarchar(max)"); + + b.Property("TwoFactorEnabled") + .HasColumnType("bit"); + + b.Property("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("Discriminator").HasValue("IdentityUser"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderKey") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderDisplayName") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("RoleId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .HasColumnType("nvarchar(450)"); + + b.Property("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", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", 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", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/CC.Yi.Old/CC.Yi.API/Migrations/20210325124241_yi4.cs b/CC.Yi.Old/CC.Yi.API/Migrations/20210325124241_yi4.cs new file mode 100644 index 00000000..4b105b4d --- /dev/null +++ b/CC.Yi.Old/CC.Yi.API/Migrations/20210325124241_yi4.cs @@ -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( + name: "UserName", + table: "AspNetUsers", + type: "nvarchar(256)", + maxLength: 256, + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "NormalizedUserName", + table: "AspNetUsers", + type: "nvarchar(256)", + maxLength: 256, + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "NormalizedEmail", + table: "AspNetUsers", + type: "nvarchar(256)", + maxLength: 256, + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Email", + table: "AspNetUsers", + type: "nvarchar(256)", + maxLength: 256, + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldNullable: true); + + migrationBuilder.AddColumn( + 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(type: "nvarchar(450)", nullable: false), + Name = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + NormalizedName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetRoles", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserClaims", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + UserId = table.Column(type: "nvarchar(450)", nullable: false), + ClaimType = table.Column(type: "nvarchar(max)", nullable: true), + ClaimValue = table.Column(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(type: "nvarchar(450)", nullable: false), + ProviderKey = table.Column(type: "nvarchar(450)", nullable: false), + ProviderDisplayName = table.Column(type: "nvarchar(max)", nullable: true), + UserId = table.Column(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(type: "nvarchar(450)", nullable: false), + LoginProvider = table.Column(type: "nvarchar(450)", nullable: false), + Name = table.Column(type: "nvarchar(450)", nullable: false), + Value = table.Column(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(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + RoleId = table.Column(type: "nvarchar(450)", nullable: false), + ClaimType = table.Column(type: "nvarchar(max)", nullable: true), + ClaimValue = table.Column(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(type: "nvarchar(450)", nullable: false), + RoleId = table.Column(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( + name: "UserName", + table: "result_user", + type: "nvarchar(max)", + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(256)", + oldMaxLength: 256, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "NormalizedUserName", + table: "result_user", + type: "nvarchar(max)", + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(256)", + oldMaxLength: 256, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "NormalizedEmail", + table: "result_user", + type: "nvarchar(max)", + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(256)", + oldMaxLength: 256, + oldNullable: true); + + migrationBuilder.AlterColumn( + 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"); + } + } +} diff --git a/CC.Yi.Old/CC.Yi.API/Migrations/20210410090937_yi5.Designer.cs b/CC.Yi.Old/CC.Yi.API/Migrations/20210410090937_yi5.Designer.cs new file mode 100644 index 00000000..6038f52c --- /dev/null +++ b/CC.Yi.Old/CC.Yi.API/Migrations/20210410090937_yi5.Designer.cs @@ -0,0 +1,40 @@ +// +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("id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("name") + .HasColumnType("nvarchar(max)"); + + b.HasKey("id"); + + b.ToTable("student"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/CC.Yi.Old/CC.Yi.API/Migrations/20210410090937_yi5.cs b/CC.Yi.Old/CC.Yi.API/Migrations/20210410090937_yi5.cs new file mode 100644 index 00000000..73cf0845 --- /dev/null +++ b/CC.Yi.Old/CC.Yi.API/Migrations/20210410090937_yi5.cs @@ -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(type: "nvarchar(450)", nullable: false), + ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true), + Name = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + NormalizedName = table.Column(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(type: "nvarchar(450)", nullable: false), + AccessFailedCount = table.Column(type: "int", nullable: false), + ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true), + Discriminator = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + EmailConfirmed = table.Column(type: "bit", nullable: false), + LockoutEnabled = table.Column(type: "bit", nullable: false), + LockoutEnd = table.Column(type: "datetimeoffset", nullable: true), + NormalizedEmail = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + NormalizedUserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + PasswordHash = table.Column(type: "nvarchar(max)", nullable: true), + PhoneNumber = table.Column(type: "nvarchar(max)", nullable: true), + PhoneNumberConfirmed = table.Column(type: "bit", nullable: false), + SecurityStamp = table.Column(type: "nvarchar(max)", nullable: true), + TwoFactorEnabled = table.Column(type: "bit", nullable: false), + UserName = table.Column(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(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ClaimType = table.Column(type: "nvarchar(max)", nullable: true), + ClaimValue = table.Column(type: "nvarchar(max)", nullable: true), + RoleId = table.Column(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(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ClaimType = table.Column(type: "nvarchar(max)", nullable: true), + ClaimValue = table.Column(type: "nvarchar(max)", nullable: true), + UserId = table.Column(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(type: "nvarchar(450)", nullable: false), + ProviderKey = table.Column(type: "nvarchar(450)", nullable: false), + ProviderDisplayName = table.Column(type: "nvarchar(max)", nullable: true), + UserId = table.Column(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(type: "nvarchar(450)", nullable: false), + RoleId = table.Column(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(type: "nvarchar(450)", nullable: false), + LoginProvider = table.Column(type: "nvarchar(450)", nullable: false), + Name = table.Column(type: "nvarchar(450)", nullable: false), + Value = table.Column(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"); + } + } +} diff --git a/CC.Yi.API/Migrations/DataContextModelSnapshot.cs b/CC.Yi.Old/CC.Yi.API/Migrations/DataContextModelSnapshot.cs similarity index 61% rename from CC.Yi.API/Migrations/DataContextModelSnapshot.cs rename to CC.Yi.Old/CC.Yi.API/Migrations/DataContextModelSnapshot.cs index d49b625c..1952adda 100644 --- a/CC.Yi.API/Migrations/DataContextModelSnapshot.cs +++ b/CC.Yi.Old/CC.Yi.API/Migrations/DataContextModelSnapshot.cs @@ -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("id") .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); b.Property("name") - .HasColumnType("TEXT"); + .HasColumnType("nvarchar(max)"); b.HasKey("id"); diff --git a/CC.Yi.Old/CC.Yi.API/Program.cs b/CC.Yi.Old/CC.Yi.API/Program.cs new file mode 100644 index 00000000..9fe2b1eb --- /dev/null +++ b/CC.Yi.Old/CC.Yi.API/Program.cs @@ -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("Yiܡ"); + var host = CreateHostBuilder(args).Build(); + //var scope = host.Services.CreateScope(); + //var services = scope.ServiceProvider; + //var context = services.GetRequiredService();//ȡ + //DbContentFactory.Initialize(context);//þ̬෽ע + host.Run(); + logger.Info("Yiɹ"); + } + 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(); + }).UseServiceProviderFactory(new AutofacServiceProviderFactory()) + .ConfigureLogging(logging => + { + // logging.ClearProviders(); // п̨ + logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace); + }).UseNLog();//nlog־ + + } +} diff --git a/CC.Yi.API/Properties/launchSettings.json b/CC.Yi.Old/CC.Yi.API/Properties/launchSettings.json similarity index 100% rename from CC.Yi.API/Properties/launchSettings.json rename to CC.Yi.Old/CC.Yi.API/Properties/launchSettings.json diff --git a/CC.Yi.Old/CC.Yi.API/Startup.cs b/CC.Yi.Old/CC.Yi.API/Startup.cs new file mode 100644 index 00000000..55003dc4 --- /dev/null +++ b/CC.Yi.Old/CC.Yi.API/Startup.cs @@ -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) + { + // Jwt + services.AddAuthorization(options => + { + //ûڲԵ֤ + options.AddPolicy("myadmin", policy => + policy.RequireRole("admin")); + }); + + + services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) + .AddJwtBearer(options => { + options.TokenValidationParameters = new TokenValidationParameters + { + ValidateIssuer = true,//Ƿ֤Issuer + ValidateAudience = true,//Ƿ֤Audience + ValidateLifetime = true,//Ƿ֤ʧЧʱ + ClockSkew = TimeSpan.FromSeconds(30), + ValidateIssuerSigningKey = true,//Ƿ֤SecurityKey + ValidAudience = JwtConst.Domain,//Audience + ValidIssuer = JwtConst.Domain,//Issuerǰǩjwtһ + IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(JwtConst.SecurityKey))//õSecurityKey + }; + }); + + + services.AddControllers(); + services.AddSwaggerService(); + services.AddSession(); + + + + //ù + Action filters = new Action(r => { + //r.Filters.Add(typeof(DbContextFilter)); + }); + services.AddMvc(filters); + + //ݿ + string connection1 = Configuration["ConnectionStringBySQL"]; + string connection2 = Configuration["ConnectionStringByMySQL"]; + string connection3 = Configuration["ConnectionStringBySQLite"]; + services.AddDbContext(options => + { + options.UseSqlServer(connection1, b => b.MigrationsAssembly("CC.Yi.API"));//ݿ + }); + + + //עתAutofac + //services.AddScoped(typeof(IBaseDal<>), typeof(BaseDal<>)); + //services.AddScoped(typeof(IstudentBll), typeof(studentBll)); + + //reidsע + //services.AddSingleton(typeof(ICacheWriter), new RedisCacheService(new Microsoft.Extensions.Caching.Redis.RedisCacheOptions() + //{ + // Configuration = Configuration.GetSection("Cache.ConnectionString").Value, + // InstanceName = Configuration.GetSection("Cache.InstanceName").Value + //})); + + + //Identity֤ + //services.AddIdentity(options => + // { + // options.Password.RequiredLength = 6;//̳ + // options.Password.RequireDigit = false;// + // options.Password.RequireLowercase = false;//Сдĸ + // options.Password.RequireNonAlphanumeric = false;//ַ + // options.Password.RequireUppercase = false;//дĸ + // //options.User.RequireUniqueEmail = false;//עǷԲظ + // //options.User.AllowedUserNameCharacters="abcd"//ַֻ + //}).AddEntityFrameworkStores().AddDefaultTokenProviders(); + + // + services.AddCors(options => options.AddPolicy("CorsPolicy", + builder => + { + builder.AllowAnyMethod() + .SetIsOriginAllowed(_ => true) + .AllowAnyHeader() + .AllowCredentials(); + })); + } + + //ʼʹú + private void InitData(IServiceProvider serviceProvider) + { + //var serviceScope = serviceProvider.GetRequiredService().CreateScope(); + + //var context = serviceScope.ServiceProvider.GetService(); + //DbContentFactory.Initialize(context);//þ̬෽ע + } + + + + 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); + } + } +} diff --git a/CC.Yi.API/T4Startup.cs b/CC.Yi.Old/CC.Yi.API/T4Startup.cs similarity index 100% rename from CC.Yi.API/T4Startup.cs rename to CC.Yi.Old/CC.Yi.API/T4Startup.cs diff --git a/CC.Yi.API/T4Startup.tt b/CC.Yi.Old/CC.Yi.API/T4Startup.tt similarity index 100% rename from CC.Yi.API/T4Startup.tt rename to CC.Yi.Old/CC.Yi.API/T4Startup.tt diff --git a/CC.Yi.API/appsettings.Development.json b/CC.Yi.Old/CC.Yi.API/appsettings.Development.json similarity index 100% rename from CC.Yi.API/appsettings.Development.json rename to CC.Yi.Old/CC.Yi.API/appsettings.Development.json diff --git a/CC.Yi.Old/CC.Yi.API/appsettings.json b/CC.Yi.Old/CC.Yi.API/appsettings.json new file mode 100644 index 00000000..429d06ac --- /dev/null +++ b/CC.Yi.Old/CC.Yi.API/appsettings.json @@ -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" +} diff --git a/CC.Yi.API/nlog.config b/CC.Yi.Old/CC.Yi.API/nlog.config similarity index 100% rename from CC.Yi.API/nlog.config rename to CC.Yi.Old/CC.Yi.API/nlog.config diff --git a/CC.Yi.Old/CC.Yi.BLL/BaseBll.cs b/CC.Yi.Old/CC.Yi.BLL/BaseBll.cs new file mode 100644 index 00000000..90cd98a0 --- /dev/null +++ b/CC.Yi.Old/CC.Yi.BLL/BaseBll.cs @@ -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 : IBaseBll where T : class, new() + { + public IBaseDal CurrentDal; + public BaseBll(IBaseDal cd) + { + CurrentDal = cd; + } + + public IQueryable GetAllEntities() + { + return CurrentDal.GetAllEntities(); + } + + public IQueryable GetEntities(Expression> whereLambda) + { + return CurrentDal.GetEntities(whereLambda); + } + + public int GetCount(Expression> whereLambda) //统计数量 + { + return CurrentDal.GetCount(whereLambda); + } + + public IQueryable> GetGroup(Expression> whereLambda, Expression> groupByLambda) //分组 + { + return CurrentDal.GetGroup(whereLambda, groupByLambda); + + } + + + public IQueryable GetPageEntities(int pageSize, int pageIndex, out int total, Expression> whereLambda, Expression> 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 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 ids) + { + foreach (var id in ids) + { + CurrentDal.Detete(id); + } + return DbSession.SaveChanges()>0; + } + public bool Delete(Expression> where) + { + IQueryable entities = CurrentDal.GetEntities(where); + if (entities != null) + { + CurrentDal.DeteteRange(entities); + + return DbSession.SaveChanges()>0; + } + return false; + } + } +} diff --git a/CC.Yi.Old/CC.Yi.BLL/CC.Yi.BLL.csproj b/CC.Yi.Old/CC.Yi.BLL/CC.Yi.BLL.csproj new file mode 100644 index 00000000..ce6c0299 --- /dev/null +++ b/CC.Yi.Old/CC.Yi.BLL/CC.Yi.BLL.csproj @@ -0,0 +1,32 @@ + + + + netcoreapp3.1 + + + + + + + + + + + TextTemplatingFileGenerator + T4BLL.cs + + + + + + + + + + True + True + T4BLL.tt + + + + diff --git a/CC.Yi.BLL/T4BLL.cs b/CC.Yi.Old/CC.Yi.BLL/T4BLL.cs similarity index 68% rename from CC.Yi.BLL/T4BLL.cs rename to CC.Yi.Old/CC.Yi.BLL/T4BLL.cs index a74dc943..da68edd2 100644 --- a/CC.Yi.BLL/T4BLL.cs +++ b/CC.Yi.Old/CC.Yi.BLL/T4BLL.cs @@ -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, IstudentBll { - public studentBll(IBaseDal cd,DataContext _Db):base(cd,_Db) + public studentBll(IBaseDal cd):base(cd) { CurrentDal = cd; - DbSession = _Db; } } } \ No newline at end of file diff --git a/CC.Yi.Old/CC.Yi.BLL/T4BLL.tt b/CC.Yi.Old/CC.Yi.BLL/T4BLL.tt new file mode 100644 index 00000000..dcda0135 --- /dev/null +++ b/CC.Yi.Old/CC.Yi.BLL/T4BLL.tt @@ -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; + } + } +<# } #> +} \ No newline at end of file diff --git a/CC.Yi.Old/CC.Yi.Common/CC.Yi.Common.csproj b/CC.Yi.Old/CC.Yi.Common/CC.Yi.Common.csproj new file mode 100644 index 00000000..2d1ddc8f --- /dev/null +++ b/CC.Yi.Old/CC.Yi.Common/CC.Yi.Common.csproj @@ -0,0 +1,17 @@ + + + + netcoreapp3.1 + + + + + + + + + + + + + diff --git a/CC.Yi.Common/Cache/CacheHelper.cs b/CC.Yi.Old/CC.Yi.Common/Cache/CacheHelper.cs similarity index 100% rename from CC.Yi.Common/Cache/CacheHelper.cs rename to CC.Yi.Old/CC.Yi.Common/Cache/CacheHelper.cs diff --git a/CC.Yi.Common/Cache/ICacheWriter.cs b/CC.Yi.Old/CC.Yi.Common/Cache/ICacheWriter.cs similarity index 100% rename from CC.Yi.Common/Cache/ICacheWriter.cs rename to CC.Yi.Old/CC.Yi.Common/Cache/ICacheWriter.cs diff --git a/CC.Yi.Old/CC.Yi.Common/Cache/RedisCache.cs b/CC.Yi.Old/CC.Yi.Common/Cache/RedisCache.cs new file mode 100644 index 00000000..3e695f02 --- /dev/null +++ b/CC.Yi.Old/CC.Yi.Common/Cache/RedisCache.cs @@ -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(string key, T value, DateTime expDate) + { + return client.Add(key, value, expDate); + } + + public bool AddCache(string key, T value) + { + return client.Add(key, value); + } + + public bool RemoveCache(string key) + { + return client.Remove(key); + } + + public T GetCache(string key) + { + return client.Get(key); + } + + public bool SetCache(string key,T value, DateTime expDate) + { + return client.Set(key, value, expDate); + } + + public bool SetCache(string key, T value) + { + return client.Set(key, value); + } + } +} diff --git a/CC.Yi.Common/Castle/CustomAutofacAop.cs b/CC.Yi.Old/CC.Yi.Common/Castle/CustomAutofacAop.cs similarity index 100% rename from CC.Yi.Common/Castle/CustomAutofacAop.cs rename to CC.Yi.Old/CC.Yi.Common/Castle/CustomAutofacAop.cs diff --git a/CC.Yi.Common/HttpHelper.cs b/CC.Yi.Old/CC.Yi.Common/HttpHelper.cs similarity index 100% rename from CC.Yi.Common/HttpHelper.cs rename to CC.Yi.Old/CC.Yi.Common/HttpHelper.cs diff --git a/CC.Yi.Common/imageHelper.cs b/CC.Yi.Old/CC.Yi.Common/ImageHelper.cs similarity index 100% rename from CC.Yi.Common/imageHelper.cs rename to CC.Yi.Old/CC.Yi.Common/ImageHelper.cs diff --git a/CC.Yi.Old/CC.Yi.Common/JsonHelper.cs b/CC.Yi.Old/CC.Yi.Common/JsonHelper.cs new file mode 100644 index 00000000..bf4c8dfa --- /dev/null +++ b/CC.Yi.Old/CC.Yi.Common/JsonHelper.cs @@ -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(string data) + { + return Newtonsoft.Json.JsonConvert.DeserializeObject(data); + } + } +} diff --git a/CC.Yi.Common/Jwt/JwtConst.cs b/CC.Yi.Old/CC.Yi.Common/Jwt/JwtConst.cs similarity index 100% rename from CC.Yi.Common/Jwt/JwtConst.cs rename to CC.Yi.Old/CC.Yi.Common/Jwt/JwtConst.cs diff --git a/CC.Yi.Old/CC.Yi.Common/Result.cs b/CC.Yi.Old/CC.Yi.Common/Result.cs new file mode 100644 index 00000000..6f210764 --- /dev/null +++ b/CC.Yi.Old/CC.Yi.Common/Result.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace CC.Yi.Common +{ + /// + /// 结果数据 + /// + 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; + } + } +} \ No newline at end of file diff --git a/CC.Yi.Old/CC.Yi.DAL/BaseDal.cs b/CC.Yi.Old/CC.Yi.DAL/BaseDal.cs new file mode 100644 index 00000000..4839e885 --- /dev/null +++ b/CC.Yi.Old/CC.Yi.DAL/BaseDal.cs @@ -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 : IBaseDal where T : class, new() + { + public DbContext Db + { + get { return DbContentFactory.GetCurrentDbContent(); } + } + public IQueryable GetEntities(Expression> whereLambda) + { + return Db.Set().Where(whereLambda).AsQueryable(); + } + + public IQueryable GetAllEntities() + { + return Db.Set().AsQueryable(); + } + + + public int GetCount(Expression> whereLambda) + { + return Db.Set().Where(whereLambda).Count(); + } + + public IQueryable> GetGroup(Expression> whereLambda, Expression> groupByLambda) //分组 + { + return Db.Set().Where(whereLambda).GroupBy(groupByLambda).AsQueryable(); + + } + + + + public IQueryable GetPageEntities(int pageSize, int pageIndex, out int total, Expression> whereLambda, Expression> orderByLambda, bool isAsc) + { + total = Db.Set().Where(whereLambda).Count(); + if (isAsc) + { + var pageData = Db.Set().Where(whereLambda) + .OrderBy(orderByLambda) + .Skip(pageSize * (pageIndex - 1)) + .Take(pageSize).AsQueryable(); + return pageData; + } + else + { + var pageData = Db.Set().Where(whereLambda) + .OrderByDescending(orderByLambda) + .Skip(pageSize * (pageIndex - 1)) + .Take(pageSize).AsQueryable(); + return pageData; + } + } + + public T Add(T entity) + { + Db.Set().Add(entity); + //Db.SaveChanges(); + return entity; + } + public bool AddRange(IEnumerable entities) + { + Db.Set().AddRange(entities); + return true; + } + + public bool Update(T entity) + { + //所有字段均修改 + Db.Entry(entity).State = EntityState.Modified; + //return Db.SaveChanges() > 0; + return true; + } + public bool Update(T entity, params string[] propertyNames) + { + EntityEntry entry = Db.Entry(entity); + entry.State = EntityState.Unchanged; + foreach (var item in propertyNames) + { + entry.Property(item).IsModified = true; + } + return true; + } + + public bool Delete(T entity) + { + Db.Entry(entity).State = EntityState.Deleted; + //return Db.SaveChanges() > 0; + return true; + } + public bool Detete(int id) + { + var entity = Db.Set().Find(id);//根据id找到实体 + Db.Set().Remove(entity);//由于这里先Find找到了实体,所以这里可以用Remove标记该实体要移除(删除)。如果不是先Find到实体就需要用System.Data.Entity.EntityState.Deleted + return true; + } + public bool DeteteRange(IEnumerable entity) + { + Db.Set().RemoveRange(entity); + return true; + } + + + } +} diff --git a/CC.Yi.DAL/CC.Yi.DAL.csproj b/CC.Yi.Old/CC.Yi.DAL/CC.Yi.DAL.csproj similarity index 100% rename from CC.Yi.DAL/CC.Yi.DAL.csproj rename to CC.Yi.Old/CC.Yi.DAL/CC.Yi.DAL.csproj diff --git a/CC.Yi.Old/CC.Yi.DAL/DbContentFactory.cs b/CC.Yi.Old/CC.Yi.DAL/DbContentFactory.cs new file mode 100644 index 00000000..73113740 --- /dev/null +++ b/CC.Yi.Old/CC.Yi.DAL/DbContentFactory.cs @@ -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> state = new ConcurrentDictionary>(); + + public static void SetData(string name, object data) => + state.GetOrAdd(name, _ => new AsyncLocal()).Value = data; + + public static object GetData(string name) => + state.TryGetValue(name, out AsyncLocal data) ? data.Value : null; + } + } +} diff --git a/CC.Yi.Old/CC.Yi.DAL/T4DAL.cs b/CC.Yi.Old/CC.Yi.DAL/T4DAL.cs new file mode 100644 index 00000000..ad7c9133 --- /dev/null +++ b/CC.Yi.Old/CC.Yi.DAL/T4DAL.cs @@ -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, IstudentDal + { + } +} \ No newline at end of file diff --git a/CC.Yi.Old/CC.Yi.DAL/T4DAL.tt b/CC.Yi.Old/CC.Yi.DAL/T4DAL.tt new file mode 100644 index 00000000..618fe8e4 --- /dev/null +++ b/CC.Yi.Old/CC.Yi.DAL/T4DAL.tt @@ -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 + { + } +<# } #> +} \ No newline at end of file diff --git a/CC.Yi.Old/CC.Yi.DALFactory/CC.Yi.DALFactory.csproj b/CC.Yi.Old/CC.Yi.DALFactory/CC.Yi.DALFactory.csproj new file mode 100644 index 00000000..7019acb0 --- /dev/null +++ b/CC.Yi.Old/CC.Yi.DALFactory/CC.Yi.DALFactory.csproj @@ -0,0 +1,40 @@ + + + + netcoreapp3.1 + + + + + + + + + + + + + + True + True + T4DbSession.tt + + + True + True + T4StaticDalFactory.tt + + + + + + TextTemplatingFileGenerator + T4DbSession.cs + + + TextTemplatingFileGenerator + T4StaticDalFactory.cs + + + + diff --git a/CC.Yi.Old/CC.Yi.DALFactory/DbSession.cs b/CC.Yi.Old/CC.Yi.DALFactory/DbSession.cs new file mode 100644 index 00000000..b6de042d --- /dev/null +++ b/CC.Yi.Old/CC.Yi.DALFactory/DbSession.cs @@ -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(); + } + + } +} diff --git a/CC.Yi.Old/CC.Yi.DALFactory/DbSessionFactory.cs b/CC.Yi.Old/CC.Yi.DALFactory/DbSessionFactory.cs new file mode 100644 index 00000000..afa24d06 --- /dev/null +++ b/CC.Yi.Old/CC.Yi.DALFactory/DbSessionFactory.cs @@ -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> state = new ConcurrentDictionary>(); + + public static void SetData(string name, object data) => + state.GetOrAdd(name, _ => new AsyncLocal()).Value = data; + + public static object GetData(string name) => + state.TryGetValue(name, out AsyncLocal data) ? data.Value : null; + } + } +} diff --git a/CC.Yi.Old/CC.Yi.DALFactory/StaticDalFactory.cs b/CC.Yi.Old/CC.Yi.DALFactory/StaticDalFactory.cs new file mode 100644 index 00000000..a91adf99 --- /dev/null +++ b/CC.Yi.Old/CC.Yi.DALFactory/StaticDalFactory.cs @@ -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> state = new ConcurrentDictionary>(); + + public static void SetData(string name, object data) => + state.GetOrAdd(name, _ => new AsyncLocal()).Value = data; + + public static object GetData(string name) => + state.TryGetValue(name, out AsyncLocal data) ? data.Value : null; + } + } +} diff --git a/CC.Yi.Old/CC.Yi.DALFactory/T4DbSession.cs b/CC.Yi.Old/CC.Yi.DALFactory/T4DbSession.cs new file mode 100644 index 00000000..6a94b709 --- /dev/null +++ b/CC.Yi.Old/CC.Yi.DALFactory/T4DbSession.cs @@ -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(); } + } + + } +} \ No newline at end of file diff --git a/CC.Yi.Old/CC.Yi.DALFactory/T4DbSession.tt b/CC.Yi.Old/CC.Yi.DALFactory/T4DbSession.tt new file mode 100644 index 00000000..541800d5 --- /dev/null +++ b/CC.Yi.Old/CC.Yi.DALFactory/T4DbSession.tt @@ -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(); } + } + +<# } #> + } +} \ No newline at end of file diff --git a/CC.Yi.Old/CC.Yi.DALFactory/T4StaticDalFactory.cs b/CC.Yi.Old/CC.Yi.DALFactory/T4StaticDalFactory.cs new file mode 100644 index 00000000..9b6f14b9 --- /dev/null +++ b/CC.Yi.Old/CC.Yi.DALFactory/T4StaticDalFactory.cs @@ -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; + } + + } +} \ No newline at end of file diff --git a/CC.Yi.Old/CC.Yi.DALFactory/T4StaticDalFactory.tt b/CC.Yi.Old/CC.Yi.DALFactory/T4StaticDalFactory.tt new file mode 100644 index 00000000..f6194b8f --- /dev/null +++ b/CC.Yi.Old/CC.Yi.DALFactory/T4StaticDalFactory.tt @@ -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; + } + +<# } #> + } +} \ No newline at end of file diff --git a/CC.Yi.IBLL/CC.Yi.IBLL.csproj b/CC.Yi.Old/CC.Yi.IBLL/CC.Yi.IBLL.csproj similarity index 100% rename from CC.Yi.IBLL/CC.Yi.IBLL.csproj rename to CC.Yi.Old/CC.Yi.IBLL/CC.Yi.IBLL.csproj diff --git a/CC.Yi.Old/CC.Yi.IBLL/IBaseBll.cs b/CC.Yi.Old/CC.Yi.IBLL/IBaseBll.cs new file mode 100644 index 00000000..ff781ea7 --- /dev/null +++ b/CC.Yi.Old/CC.Yi.IBLL/IBaseBll.cs @@ -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 where T : class, new() + { + #region + //得到全部实体 + #endregion + IQueryable GetAllEntities(); + + #region + //通过表达式得到实体 + #endregion + IQueryable GetEntities(Expression> whereLambda); + + #region + //通过表达式得到实体,分页版本 + #endregion + IQueryable GetPageEntities(int pageSize, int pageIndex, out int total, Expression> whereLambda, Expression> orderByLambda, bool isAsc); + + #region + //通过表达式统计数量 + #endregion + int GetCount(Expression> whereLambda); + + #region + //通过表达式分组 + #endregion + IQueryable> GetGroup(Expression> whereLambda, Expression> groupByLambda); + + #region + //添加实体 + #endregion + T Add(T entity); + + #region + //添加多个实体 + #endregion + bool Add(IEnumerable 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 ids); + + #region + //通过表达式删除实体 + #endregion + bool Delete(Expression> where); + } +} diff --git a/CC.Yi.IBLL/T4IBLL.cs b/CC.Yi.Old/CC.Yi.IBLL/T4IBLL.cs similarity index 100% rename from CC.Yi.IBLL/T4IBLL.cs rename to CC.Yi.Old/CC.Yi.IBLL/T4IBLL.cs diff --git a/CC.Yi.IBLL/T4IBLL.tt b/CC.Yi.Old/CC.Yi.IBLL/T4IBLL.tt similarity index 100% rename from CC.Yi.IBLL/T4IBLL.tt rename to CC.Yi.Old/CC.Yi.IBLL/T4IBLL.tt diff --git a/CC.Yi.Old/CC.Yi.IDAL/CC.Yi.IDAL.csproj b/CC.Yi.Old/CC.Yi.IDAL/CC.Yi.IDAL.csproj new file mode 100644 index 00000000..91214ffd --- /dev/null +++ b/CC.Yi.Old/CC.Yi.IDAL/CC.Yi.IDAL.csproj @@ -0,0 +1,40 @@ + + + + Library + netcoreapp3.1 + + + + + + + + + TextTemplatingFileGenerator + T4IDAL.cs + + + TextTemplatingFileGenerator + T4IDbSession.cs + + + + + + + + + + True + True + T4IDAL.tt + + + True + True + T4IDbSession.tt + + + + diff --git a/CC.Yi.IDAL/IBaseDal.cs b/CC.Yi.Old/CC.Yi.IDAL/IBaseDal.cs similarity index 100% rename from CC.Yi.IDAL/IBaseDal.cs rename to CC.Yi.Old/CC.Yi.IDAL/IBaseDal.cs diff --git a/CC.Yi.Old/CC.Yi.IDAL/IDbSession.cs b/CC.Yi.Old/CC.Yi.IDAL/IDbSession.cs new file mode 100644 index 00000000..633da7f1 --- /dev/null +++ b/CC.Yi.Old/CC.Yi.IDAL/IDbSession.cs @@ -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(); + } + + + +} diff --git a/CC.Yi.IDAL/T4IDAL.cs b/CC.Yi.Old/CC.Yi.IDAL/T4IDAL.cs similarity index 100% rename from CC.Yi.IDAL/T4IDAL.cs rename to CC.Yi.Old/CC.Yi.IDAL/T4IDAL.cs diff --git a/CC.Yi.IDAL/T4IDAL.tt b/CC.Yi.Old/CC.Yi.IDAL/T4IDAL.tt similarity index 100% rename from CC.Yi.IDAL/T4IDAL.tt rename to CC.Yi.Old/CC.Yi.IDAL/T4IDAL.tt diff --git a/CC.Yi.Old/CC.Yi.IDAL/T4IDbSession.cs b/CC.Yi.Old/CC.Yi.IDAL/T4IDbSession.cs new file mode 100644 index 00000000..aab497df --- /dev/null +++ b/CC.Yi.Old/CC.Yi.IDAL/T4IDbSession.cs @@ -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;} + + } +} \ No newline at end of file diff --git a/CC.Yi.Old/CC.Yi.IDAL/T4IDbSession.tt b/CC.Yi.Old/CC.Yi.IDAL/T4IDbSession.tt new file mode 100644 index 00000000..b0d2226a --- /dev/null +++ b/CC.Yi.Old/CC.Yi.IDAL/T4IDbSession.tt @@ -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;} + +<# } #> + } +} \ No newline at end of file diff --git a/CC.Yi.Old/CC.Yi.Model/CC.Yi.Model.csproj b/CC.Yi.Old/CC.Yi.Model/CC.Yi.Model.csproj new file mode 100644 index 00000000..f620b157 --- /dev/null +++ b/CC.Yi.Old/CC.Yi.Model/CC.Yi.Model.csproj @@ -0,0 +1,43 @@ + + + + netcoreapp3.1 + + + + + True + True + T4DataContext.tt + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + TextTemplatingFileGenerator + T4DataContext.cs + + + + + + + + + + True + True + T4DataContext.tt + + + + diff --git a/CC.Yi.Old/CC.Yi.Model/DataContext.cs b/CC.Yi.Old/CC.Yi.Model/DataContext.cs new file mode 100644 index 00000000..98a047bd --- /dev/null +++ b/CC.Yi.Old/CC.Yi.Model/DataContext.cs @@ -0,0 +1,14 @@ +using Microsoft.EntityFrameworkCore; +using System; + +namespace CC.Yi.Model +{ + public partial class DataContext : DbContext + { + public DataContext(DbContextOptions options) : base(options) + { + + } + //public DbSet result_user { get; set; } + } +} diff --git a/CC.Yi.Model/T4DataContext.cs b/CC.Yi.Old/CC.Yi.Model/T4DataContext.cs similarity index 100% rename from CC.Yi.Model/T4DataContext.cs rename to CC.Yi.Old/CC.Yi.Model/T4DataContext.cs diff --git a/CC.Yi.Model/T4DataContext.tt b/CC.Yi.Old/CC.Yi.Model/T4DataContext.tt similarity index 100% rename from CC.Yi.Model/T4DataContext.tt rename to CC.Yi.Old/CC.Yi.Model/T4DataContext.tt diff --git a/CC.Yi.Old/CC.Yi.Model/result_user.cs b/CC.Yi.Old/CC.Yi.Model/result_user.cs new file mode 100644 index 00000000..9c60b1a8 --- /dev/null +++ b/CC.Yi.Old/CC.Yi.Model/result_user.cs @@ -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; } + } +} diff --git a/CC.Yi.Model/student.cs b/CC.Yi.Old/CC.Yi.Model/student.cs similarity index 100% rename from CC.Yi.Model/student.cs rename to CC.Yi.Old/CC.Yi.Model/student.cs diff --git a/CC.Yi.ViewModel/CC.Yi.ViewModel.csproj b/CC.Yi.Old/CC.Yi.ViewModel/CC.Yi.ViewModel.csproj similarity index 100% rename from CC.Yi.ViewModel/CC.Yi.ViewModel.csproj rename to CC.Yi.Old/CC.Yi.ViewModel/CC.Yi.ViewModel.csproj diff --git a/CC.Yi.Old/CC.Yi.sln b/CC.Yi.Old/CC.Yi.sln new file mode 100644 index 00000000..6e606c50 --- /dev/null +++ b/CC.Yi.Old/CC.Yi.sln @@ -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 diff --git a/T4Model/T4Model.txt b/CC.Yi.Old/T4Model/T4Model.txt similarity index 100% rename from T4Model/T4Model.txt rename to CC.Yi.Old/T4Model/T4Model.txt diff --git a/T4Model/说明.txt b/CC.Yi.Old/T4Model/说明.txt similarity index 100% rename from T4Model/说明.txt rename to CC.Yi.Old/T4Model/说明.txt diff --git a/CC.Yi.API/CC.Yi.API.csproj b/CC.Yi/CC.Yi.API/CC.Yi.API.csproj similarity index 100% rename from CC.Yi.API/CC.Yi.API.csproj rename to CC.Yi/CC.Yi.API/CC.Yi.API.csproj diff --git a/CC.Yi.API/Controllers/StudentController.cs b/CC.Yi/CC.Yi.API/Controllers/StudentController.cs similarity index 87% rename from CC.Yi.API/Controllers/StudentController.cs rename to CC.Yi/CC.Yi.API/Controllers/StudentController.cs index cdacfe7e..610c7c95 100644 --- a/CC.Yi.API/Controllers/StudentController.cs +++ b/CC.Yi/CC.Yi.API/Controllers/StudentController.cs @@ -29,13 +29,14 @@ namespace CC.Yi.API.Controllers //private UserManager _userManager;//处理用户相关逻辑:添加密码,修改密码,添加删除角色等等 //private SignInManager _signInManager;//处理注册登录的相关逻辑 - + private IpropBll _propBll; private IstudentBll _studentBll; - public StudentController(ILogger logger, IstudentBll studentBll) + public StudentController(ILogger 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() { diff --git a/CC.Yi/CC.Yi.API/Extension/SwaggerExtension.cs b/CC.Yi/CC.Yi.API/Extension/SwaggerExtension.cs new file mode 100644 index 00000000..6db50f61 --- /dev/null +++ b/CC.Yi/CC.Yi.API/Extension/SwaggerExtension.cs @@ -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 +{ + /// + /// Swagger文档扩展方法 + /// + 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(); + + //添加header验证信息 + //c.OperationFilter(); + //var security = new Dictionary> { { "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() } + }); + }); + #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")); + } + + } +} diff --git a/CC.Yi.API/Filter/DbContextFilter.cs b/CC.Yi/CC.Yi.API/Filter/DbContextFilter.cs similarity index 100% rename from CC.Yi.API/Filter/DbContextFilter.cs rename to CC.Yi/CC.Yi.API/Filter/DbContextFilter.cs diff --git a/CC.Yi.API/Migrations/20210413063257_y1.Designer.cs b/CC.Yi/CC.Yi.API/Migrations/20210413063257_y1.Designer.cs similarity index 100% rename from CC.Yi.API/Migrations/20210413063257_y1.Designer.cs rename to CC.Yi/CC.Yi.API/Migrations/20210413063257_y1.Designer.cs diff --git a/CC.Yi.API/Migrations/20210413063257_y1.cs b/CC.Yi/CC.Yi.API/Migrations/20210413063257_y1.cs similarity index 100% rename from CC.Yi.API/Migrations/20210413063257_y1.cs rename to CC.Yi/CC.Yi.API/Migrations/20210413063257_y1.cs diff --git a/CC.Yi/CC.Yi.API/Migrations/20210526080428_yi2.Designer.cs b/CC.Yi/CC.Yi.API/Migrations/20210526080428_yi2.Designer.cs new file mode 100644 index 00000000..bdcbf50b --- /dev/null +++ b/CC.Yi/CC.Yi.API/Migrations/20210526080428_yi2.Designer.cs @@ -0,0 +1,70 @@ +// +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("id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("name") + .HasColumnType("TEXT"); + + b.Property("studentid") + .HasColumnType("INTEGER"); + + b.HasKey("id"); + + b.HasIndex("studentid"); + + b.ToTable("prop"); + }); + + modelBuilder.Entity("CC.Yi.Model.student", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("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 + } + } +} diff --git a/CC.Yi/CC.Yi.API/Migrations/20210526080428_yi2.cs b/CC.Yi/CC.Yi.API/Migrations/20210526080428_yi2.cs new file mode 100644 index 00000000..26a83772 --- /dev/null +++ b/CC.Yi/CC.Yi.API/Migrations/20210526080428_yi2.cs @@ -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(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + name = table.Column(type: "TEXT", nullable: true), + studentid = table.Column(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"); + } + } +} diff --git a/CC.Yi/CC.Yi.API/Migrations/DataContextModelSnapshot.cs b/CC.Yi/CC.Yi.API/Migrations/DataContextModelSnapshot.cs new file mode 100644 index 00000000..0de6dc1e --- /dev/null +++ b/CC.Yi/CC.Yi.API/Migrations/DataContextModelSnapshot.cs @@ -0,0 +1,68 @@ +// +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("id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("name") + .HasColumnType("TEXT"); + + b.Property("studentid") + .HasColumnType("INTEGER"); + + b.HasKey("id"); + + b.HasIndex("studentid"); + + b.ToTable("prop"); + }); + + modelBuilder.Entity("CC.Yi.Model.student", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("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 + } + } +} diff --git a/CC.Yi.API/Program.cs b/CC.Yi/CC.Yi.API/Program.cs similarity index 100% rename from CC.Yi.API/Program.cs rename to CC.Yi/CC.Yi.API/Program.cs diff --git a/CC.Yi/CC.Yi.API/Properties/launchSettings.json b/CC.Yi/CC.Yi.API/Properties/launchSettings.json new file mode 100644 index 00000000..9942be97 --- /dev/null +++ b/CC.Yi/CC.Yi.API/Properties/launchSettings.json @@ -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" + } + } + } +} diff --git a/CC.Yi.API/Startup.cs b/CC.Yi/CC.Yi.API/Startup.cs similarity index 100% rename from CC.Yi.API/Startup.cs rename to CC.Yi/CC.Yi.API/Startup.cs diff --git a/CC.Yi/CC.Yi.API/T4Startup.cs b/CC.Yi/CC.Yi.API/T4Startup.cs new file mode 100644 index 00000000..bd132110 --- /dev/null +++ b/CC.Yi/CC.Yi.API/T4Startup.cs @@ -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().As().EnableInterfaceInterceptors();//表示注入前后要执行Castle,AOP + builder.RegisterType().As().EnableInterfaceInterceptors();//表示注入前后要执行Castle,AOP + } + } +} \ No newline at end of file diff --git a/CC.Yi/CC.Yi.API/T4Startup.tt b/CC.Yi/CC.Yi.API/T4Startup.tt new file mode 100644 index 00000000..166ebfc5 --- /dev/null +++ b/CC.Yi/CC.Yi.API/T4Startup.tt @@ -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>().AsBll>().EnableInterfaceInterceptors();//表示注入前后要执行Castle,AOP +<# } #> + } + } +} \ No newline at end of file diff --git a/CC.Yi/CC.Yi.API/YIDB.db b/CC.Yi/CC.Yi.API/YIDB.db new file mode 100644 index 0000000000000000000000000000000000000000..f6766b9e8731fac782f26a72175a3fc3f5b7892a GIT binary patch literal 28672 zcmeI)!B5&y90%~%7GXoNJIs;E<)ynwToh2m;}||%BNkTc0*9qR>6Ru63MH9`9W?tB zcHeE;#Xn(xz^=>wgT>5b$L+A=UQ3IhxWwBe-xnV6UfbV$zt1Zqg}~PHlI>XZRja*U zcjywiM?{f4p_C93;x)o+P~5g#gCYb^{_z+h3+ta^@*fhO+9A_l< z1Rwwb2tWV=5P$###!#RZ4#yW~gtvCHVZBkS=0Ur4V0N5t!)iKq!)-+hI?Ef3s@fW> zQsv4%3N33?arac{oYFs3NuE5Kh{R`Rgm+1&zO!e!d$=|1$20OzORRrjEJ}G%?1sVz zGT1uPsa7_qwp}XGLRs4~^gQpUN@c^FqCzXWx|!E&bc5Ase%mOk8jrilG~=-!s#)K+ z6l$<)FG|pTF~N(0_#pn~!J&%1p#qKI(Vb$ktTT08^9CQvnd+>_bfy*977Z+17Jg9D zby{O3#w~Tm6H*ICESju@!twceq2?KN4)^%=p4qVuyH<18y40K)lDo8V&dv8RKQehd zD@Edogm5z1i`iRDKkv{`jDacMU;+G4H(vvu?r~L!#B({}r0h-3G+A-ee%-D+cB|QW zW_O%c`)FjRI6U!@`*3MLjebm(uU79IxaMrSCeXm?6`VPhcB|3dbzWHQ4xj9$usk(Y z498#Q1meAv{MD&Wq{ZI0<@8c&Whs-*nMY}F zQZtP0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U NAV7cs0RsOh@C0=*DWCuV literal 0 HcmV?d00001 diff --git a/CC.Yi.API/YIDB.db b/CC.Yi/CC.Yi.API/YIDB.db-wal similarity index 93% rename from CC.Yi.API/YIDB.db rename to CC.Yi/CC.Yi.API/YIDB.db-wal index 5aff9324290cc7eb81903b73d5b526d0cb5c0f03..6aeec3c8f37eaaf0f65b5cd14202fc3c123c1d87 100644 GIT binary patch delta 301 zcmZozz&K+eqlZ`j4TYo3}$9#Kq+<*hPma-Nkh|fu7TNUQ&&HImO1q(AXCno?#%~@Um literal 20480 zcmeI)Jx|*}7zgk>JG|7$xC4?!vz$DEKp`)LthmUf7KxJ@Q<0&vT%*dfyYkuSbG*^lq}Ig67h$FG`U7O;15a^YpHMxGKu zAp49FLPXvccpHYmJB8tZ@9Crdtgc8(hhJpnHz~;9$m&<+cD2qs2nav`0uX=z1Rwwb z2tWV=5cnSgox-BJwMDy`_x3zUFVFe&o|^`jy&yW994;K#hVB^5(VsUBHgW7mfBmu$k3%n03-@vV*pD z?ASV=XIkgT9i7y%&6aL=*^$v@`iavvEuOt)SkCq!TYpU&bBxnGkt}UqpVB3@(V#c& zhsC+B@uC&JPrNLQqx5B%W^r;gby65#_|#+mmNCj{@_O>?&nRX_qDQ3-i|Hh>-#g1* z2T95oJCT-`W(teyn+7Fes>kap+QZJQDb&1zSm7j!f2nav` z0uX=z1Rwwb2tWV=5P$##=3ih<+p~pYSY#L diff --git a/CC.Yi/CC.Yi.API/appsettings.Development.json b/CC.Yi/CC.Yi.API/appsettings.Development.json new file mode 100644 index 00000000..8983e0fc --- /dev/null +++ b/CC.Yi/CC.Yi.API/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/CC.Yi.API/appsettings.json b/CC.Yi/CC.Yi.API/appsettings.json similarity index 100% rename from CC.Yi.API/appsettings.json rename to CC.Yi/CC.Yi.API/appsettings.json diff --git a/CC.Yi/CC.Yi.API/nlog.config b/CC.Yi/CC.Yi.API/nlog.config new file mode 100644 index 00000000..ff359770 --- /dev/null +++ b/CC.Yi/CC.Yi.API/nlog.config @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CC.Yi.BLL/BaseBll.cs b/CC.Yi/CC.Yi.BLL/BaseBll.cs similarity index 100% rename from CC.Yi.BLL/BaseBll.cs rename to CC.Yi/CC.Yi.BLL/BaseBll.cs diff --git a/CC.Yi.BLL/CC.Yi.BLL.csproj b/CC.Yi/CC.Yi.BLL/CC.Yi.BLL.csproj similarity index 100% rename from CC.Yi.BLL/CC.Yi.BLL.csproj rename to CC.Yi/CC.Yi.BLL/CC.Yi.BLL.csproj diff --git a/CC.Yi/CC.Yi.BLL/T4BLL.cs b/CC.Yi/CC.Yi.BLL/T4BLL.cs new file mode 100644 index 00000000..267e456b --- /dev/null +++ b/CC.Yi/CC.Yi.BLL/T4BLL.cs @@ -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, IstudentBll + { + public studentBll(IBaseDal cd,DataContext _Db):base(cd,_Db) + { + CurrentDal = cd; + DbSession = _Db; + } + } + public partial class propBll : BaseBll, IpropBll + { + public propBll(IBaseDal cd,DataContext _Db):base(cd,_Db) + { + CurrentDal = cd; + DbSession = _Db; + } + } +} \ No newline at end of file diff --git a/CC.Yi.BLL/T4BLL.tt b/CC.Yi/CC.Yi.BLL/T4BLL.tt similarity index 100% rename from CC.Yi.BLL/T4BLL.tt rename to CC.Yi/CC.Yi.BLL/T4BLL.tt diff --git a/CC.Yi.Common/CC.Yi.Common.csproj b/CC.Yi/CC.Yi.Common/CC.Yi.Common.csproj similarity index 100% rename from CC.Yi.Common/CC.Yi.Common.csproj rename to CC.Yi/CC.Yi.Common/CC.Yi.Common.csproj diff --git a/CC.Yi/CC.Yi.Common/Cache/CacheHelper.cs b/CC.Yi/CC.Yi.Common/Cache/CacheHelper.cs new file mode 100644 index 00000000..e77f8fbc --- /dev/null +++ b/CC.Yi/CC.Yi.Common/Cache/CacheHelper.cs @@ -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(string key, T value, DateTime expDate) + { + return CacheWriter.AddCache(key,value,expDate); + } + + public bool AddCache(string key, T value) + { + return CacheWriter.AddCache(key, value); + } + + public bool RemoveCache(string key) + { + return CacheWriter.RemoveCache(key); + } + + public T GetCache(string key) + { + return CacheWriter.GetCache(key); + } + + public bool SetCache(string key, T value, DateTime expDate) + { + return CacheWriter.SetCache(key,value,expDate); + } + + public bool SetCache(string key, T value) + { + return CacheWriter.SetCache(key, value); + } + + } +} diff --git a/CC.Yi/CC.Yi.Common/Cache/ICacheWriter.cs b/CC.Yi/CC.Yi.Common/Cache/ICacheWriter.cs new file mode 100644 index 00000000..712f6857 --- /dev/null +++ b/CC.Yi/CC.Yi.Common/Cache/ICacheWriter.cs @@ -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(string key, T value, DateTime expDate); + bool AddCache(string key, T value); + bool RemoveCache(string key); + T GetCache(string key); + bool SetCache(string key, T value, DateTime expDate); + bool SetCache(string key, T value); + } +} diff --git a/CC.Yi.Common/Cache/RedisCache.cs b/CC.Yi/CC.Yi.Common/Cache/RedisCache.cs similarity index 100% rename from CC.Yi.Common/Cache/RedisCache.cs rename to CC.Yi/CC.Yi.Common/Cache/RedisCache.cs diff --git a/CC.Yi/CC.Yi.Common/Castle/CustomAutofacAop.cs b/CC.Yi/CC.Yi.Common/Castle/CustomAutofacAop.cs new file mode 100644 index 00000000..526d39ef --- /dev/null +++ b/CC.Yi/CC.Yi.Common/Castle/CustomAutofacAop.cs @@ -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();//执行具体的实例 + { + + //这里写执行方法后 + } + } + } +} diff --git a/CC.Yi/CC.Yi.Common/HttpHelper.cs b/CC.Yi/CC.Yi.Common/HttpHelper.cs new file mode 100644 index 00000000..6bfdfb18 --- /dev/null +++ b/CC.Yi/CC.Yi.Common/HttpHelper.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; + +namespace CC.Yi.Common +{ + public static class HttpHelper + { + public static string HttpGet(string Url, string postDataStr="") + { + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url + (postDataStr == "" ? "" : "?") + postDataStr); + request.Method = "GET"; + request.ContentType = "text/html;charset=UTF-8"; + + HttpWebResponse response = (HttpWebResponse)request.GetResponse(); + Stream myResponseStream = response.GetResponseStream(); + StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8")); + string retString = myStreamReader.ReadToEnd(); + myStreamReader.Close(); + myResponseStream.Close(); + + return retString; + } + + public static bool HttpIOGet(string Url, string file, string postDataStr="") + { + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url + (postDataStr == "" ? "" : "?") + postDataStr); + request.Method = "GET"; + request.ContentType = "text/html;charset=UTF-8"; + + HttpWebResponse response = (HttpWebResponse)request.GetResponse(); + Stream myResponseStream = response.GetResponseStream(); + FileStream writer = new FileStream(file, FileMode.OpenOrCreate, FileAccess.Write); + byte[] buffer = new byte[1024]; + int c; + while ((c = myResponseStream.Read(buffer, 0, buffer.Length)) > 0) + { + writer.Write(buffer, 0, c); + } + writer.Close(); + myResponseStream.Close(); + + return true; + } + + public static string HttpPost(string Url, string postDataStr="") + { + CookieContainer cookie = new CookieContainer(); + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url); + request.Method = "POST"; + request.ContentType = "application/x-www-form-urlencoded"; + request.ContentLength = Encoding.UTF8.GetByteCount(postDataStr); + request.CookieContainer = cookie; + Stream myRequestStream = request.GetRequestStream(); + StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("gb2312")); + myStreamWriter.Write(postDataStr); + myStreamWriter.Close(); + + HttpWebResponse response = (HttpWebResponse)request.GetResponse(); + + response.Cookies = cookie.GetCookies(response.ResponseUri); + Stream myResponseStream = response.GetResponseStream(); + StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8")); + string retString = myStreamReader.ReadToEnd(); + myStreamReader.Close(); + myResponseStream.Close(); + + return retString; + } + } +} diff --git a/CC.Yi.Common/JsonHelper.cs b/CC.Yi/CC.Yi.Common/JsonHelper.cs similarity index 100% rename from CC.Yi.Common/JsonHelper.cs rename to CC.Yi/CC.Yi.Common/JsonHelper.cs diff --git a/CC.Yi/CC.Yi.Common/Jwt/JwtConst.cs b/CC.Yi/CC.Yi.Common/Jwt/JwtConst.cs new file mode 100644 index 00000000..1e7713ff --- /dev/null +++ b/CC.Yi/CC.Yi.Common/Jwt/JwtConst.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CC.Yi.Common.Jwt +{ + public class JwtConst + { + public const string SecurityKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDI2a2EJ7m872v0afyoSDJT2o1+SitIeJSWtLJU8/Wz2m7gStexajkeD+Lka6DSTy8gt9UwfgVQo6uKjVLG5Ex7PiGOODVqAEghBuS7JzIYU5RvI543nNDAPfnJsas96mSA7L/mD7RTE2drj6hf3oZjJpMPZUQI/B1Qjb5H3K3PNwIDAQAB"; + public const string Domain = "http://localhost:5000"; + } +} diff --git a/CC.Yi.Common/Result.cs b/CC.Yi/CC.Yi.Common/Result.cs similarity index 100% rename from CC.Yi.Common/Result.cs rename to CC.Yi/CC.Yi.Common/Result.cs diff --git a/CC.Yi/CC.Yi.Common/imageHelper.cs b/CC.Yi/CC.Yi.Common/imageHelper.cs new file mode 100644 index 00000000..170aba9c --- /dev/null +++ b/CC.Yi/CC.Yi.Common/imageHelper.cs @@ -0,0 +1,167 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.IO; +using System.IO.Compression; +using System.Drawing; + +namespace CC.Yi.Common +{ + public class SimilarPhoto + { + Image SourceImg; + public SimilarPhoto(string filePath) + { + SourceImg = Image.FromFile(filePath); + } + public SimilarPhoto(Stream stream) + { + SourceImg = Image.FromStream(stream); + } + public String GetHash() + { + Image image = ReduceSize(); + Byte[] grayValues = ReduceColor(image); + Byte average = CalcAverage(grayValues); + String reslut = ComputeBits(grayValues, average); + return reslut; + } + // Step 1 : Reduce size to 8*8 + private Image ReduceSize(int width = 8, int height = 8) + { + Image image = SourceImg.GetThumbnailImage(width, height, () => { return false; }, IntPtr.Zero); + return image; + } + // Step 2 : Reduce Color + private Byte[] ReduceColor(Image image) + { + Bitmap bitMap = new Bitmap(image); + Byte[] grayValues = new Byte[image.Width * image.Height]; + for (int x = 0; x < image.Width; x++) + for (int y = 0; y < image.Height; y++) + { + Color color = bitMap.GetPixel(x, y); + byte grayValue = (byte)((color.R * 30 + color.G * 59 + color.B * 11) / 100); + grayValues[x * image.Width + y] = grayValue; + } + return grayValues; + } + // Step 3 : Average the colors + private Byte CalcAverage(byte[] values) + { + int sum = 0; + for (int i = 0; i < values.Length; i++) + sum += (int)values[i]; + return Convert.ToByte(sum / values.Length); + } + // Step 4 : Compute the bits + private String ComputeBits(byte[] values, byte averageValue) + { + char[] result = new char[values.Length]; + for (int i = 0; i < values.Length; i++) + { + if (values[i] < averageValue) + result[i] = '0'; + else + result[i] = '1'; + } + SourceImg.Dispose(); + return new String(result); + } + // Compare hash + public static Int32 CalcSimilarDegree(string a, string b) + { + if (a.Length != b.Length) + throw new ArgumentException(); + int count = 0; + for (int i = 0; i < a.Length; i++) + { + if (a[i] != b[i]) + count++; + } + return count; + } + } + public static class imageHelper + { + public static int Compare(string filePath1, string filePath2) + { + SimilarPhoto photo1 = new SimilarPhoto(filePath1); + SimilarPhoto photo2 = new SimilarPhoto(filePath2); + return SimilarPhoto.CalcSimilarDegree(photo1.GetHash(), photo2.GetHash()); + } + public static bool ByStringToSave(string name, string iss) + { + iss = iss.Replace("data:image/png;base64,", "").Replace("data:image/jgp;base64,", "") + .Replace("data:image/jpg;base64,", "").Replace("data:image/jpeg;base64,", ""); + byte[] arr = Convert.FromBase64String(iss); + MemoryStream ms = new MemoryStream(arr); + Bitmap bmp = new Bitmap(ms); + string StudentWorkImages = "StudentWorkImages"; + + if (Directory.Exists(@"./wwwroot/" + StudentWorkImages) == false)//如果不存在就创建file文件夹 + { + Directory.CreateDirectory(@"./wwwroot/" + StudentWorkImages); + } + + + + bmp.Save(@"./wwwroot/" + StudentWorkImages + "/" + name + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg); + ms.Close(); + return true; + } + public static bool CreateZip() + { + string file_path = @"./wwwroot/StudentWorkImages.zip"; + string file_path2 = @"./wwwroot/StudentWorkImages/"; + if (File.Exists(file_path)) + { + File.Delete(file_path); + } + + ZipFile.CreateFromDirectory(file_path2, file_path); + return true; + } + public static bool DeleteAll() + { + string file_path = @"./wwwroot/StudentWorkImages/"; + if (Directory.Exists(file_path)) + { + DelectDir(file_path); + return true; + } + else + return false; + } + public static bool DeleteByString(string name) + { + File.Delete(@"./wwwroot/StudentWorkImages/" + name + ".jpg"); + return true; + } + public static void DelectDir(string srcPath) + { + try + { + DirectoryInfo dir = new DirectoryInfo(srcPath); + FileSystemInfo[] fileinfo = dir.GetFileSystemInfos(); //返回目录中所有文件和子目录 + foreach (FileSystemInfo i in fileinfo) + { + if (i is DirectoryInfo) //判断是否文件夹 + { + DirectoryInfo subdir = new DirectoryInfo(i.FullName); + subdir.Delete(true); //删除子目录和文件 + } + else + { + File.Delete(i.FullName); //删除指定文件 + } + } + } + catch (Exception e) + { + Console.Write(e.ToString()); + } + } + } +} diff --git a/CC.Yi.DAL/BaseDal.cs b/CC.Yi/CC.Yi.DAL/BaseDal.cs similarity index 100% rename from CC.Yi.DAL/BaseDal.cs rename to CC.Yi/CC.Yi.DAL/BaseDal.cs diff --git a/CC.Yi/CC.Yi.DAL/CC.Yi.DAL.csproj b/CC.Yi/CC.Yi.DAL/CC.Yi.DAL.csproj new file mode 100644 index 00000000..ac766382 --- /dev/null +++ b/CC.Yi/CC.Yi.DAL/CC.Yi.DAL.csproj @@ -0,0 +1,31 @@ + + + + netcoreapp3.1 + + + + + + + + + + TextTemplatingFileGenerator + T4DAL.cs + + + + + + + + + + True + True + T4DAL.tt + + + + diff --git a/CC.Yi.DAL/T4DAL.cs b/CC.Yi/CC.Yi.DAL/T4DAL.cs similarity index 67% rename from CC.Yi.DAL/T4DAL.cs rename to CC.Yi/CC.Yi.DAL/T4DAL.cs index 7f13bb7a..7b2b7ca8 100644 --- a/CC.Yi.DAL/T4DAL.cs +++ b/CC.Yi/CC.Yi.DAL/T4DAL.cs @@ -14,4 +14,11 @@ namespace CC.Yi.DAL Db = _Db; } } + public partial class propDal : BaseDal, IpropDal + { + public propDal(DataContext _Db):base(_Db) + { + Db = _Db; + } + } } \ No newline at end of file diff --git a/CC.Yi.DAL/T4DAL.tt b/CC.Yi/CC.Yi.DAL/T4DAL.tt similarity index 100% rename from CC.Yi.DAL/T4DAL.tt rename to CC.Yi/CC.Yi.DAL/T4DAL.tt diff --git a/CC.Yi/CC.Yi.IBLL/CC.Yi.IBLL.csproj b/CC.Yi/CC.Yi.IBLL/CC.Yi.IBLL.csproj new file mode 100644 index 00000000..778e1962 --- /dev/null +++ b/CC.Yi/CC.Yi.IBLL/CC.Yi.IBLL.csproj @@ -0,0 +1,32 @@ + + + + Library + netcoreapp3.1 + + + + + + + + + + TextTemplatingFileGenerator + T4IBLL.cs + + + + + + + + + + True + True + T4IBLL.tt + + + + diff --git a/CC.Yi.IBLL/IBaseBll.cs b/CC.Yi/CC.Yi.IBLL/IBaseBll.cs similarity index 100% rename from CC.Yi.IBLL/IBaseBll.cs rename to CC.Yi/CC.Yi.IBLL/IBaseBll.cs diff --git a/CC.Yi/CC.Yi.IBLL/T4IBLL.cs b/CC.Yi/CC.Yi.IBLL/T4IBLL.cs new file mode 100644 index 00000000..afee28ec --- /dev/null +++ b/CC.Yi/CC.Yi.IBLL/T4IBLL.cs @@ -0,0 +1,14 @@ +using CC.Yi.Model; +using System; +using System.Collections.Generic; +using System.Text; + +namespace CC.Yi.IBLL +{ + public partial interface IstudentBll : IBaseBll + { + } + public partial interface IpropBll : IBaseBll + { + } +} \ No newline at end of file diff --git a/CC.Yi/CC.Yi.IBLL/T4IBLL.tt b/CC.Yi/CC.Yi.IBLL/T4IBLL.tt new file mode 100644 index 00000000..9aff10f0 --- /dev/null +++ b/CC.Yi/CC.Yi.IBLL/T4IBLL.tt @@ -0,0 +1,29 @@ +<#@ 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 System; +using System.Collections.Generic; +using System.Text; + +namespace CC.Yi.IBLL +{ +<# foreach(string k in ModelData){ + #> + public partial interface I<#=k #>Bll : IBaseBll<<#=k #>> + { + } +<# } #> +} \ No newline at end of file diff --git a/CC.Yi.IDAL/CC.Yi.IDAL.csproj b/CC.Yi/CC.Yi.IDAL/CC.Yi.IDAL.csproj similarity index 100% rename from CC.Yi.IDAL/CC.Yi.IDAL.csproj rename to CC.Yi/CC.Yi.IDAL/CC.Yi.IDAL.csproj diff --git a/CC.Yi/CC.Yi.IDAL/IBaseDal.cs b/CC.Yi/CC.Yi.IDAL/IBaseDal.cs new file mode 100644 index 00000000..f4daf158 --- /dev/null +++ b/CC.Yi/CC.Yi.IDAL/IBaseDal.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; + +namespace CC.Yi.IDAL +{ + public interface IBaseDal where T : class, new() + { + #region + //得到全部实体 + #endregion + IQueryable GetAllEntities(); + + #region + //通过表达式得到实体 + #endregion + IQueryable GetEntities(Expression> whereLambda); + + #region + //通过表达式得到实体,分页版本 + #endregion + IQueryable GetPageEntities(int pageSize, int pageIndex, out int total, Expression> whereLambda, Expression> orderByLambda, bool isAsc); + + #region + //通过表达式统计数量 + #endregion + int GetCount(Expression> whereLambda); + + #region + //通过表达式分组 + #endregion + IQueryable> GetGroup(Expression> whereLambda, Expression> groupByLambda); + + #region + //添加单个实体 + #endregion + T Add(T entity); + + #region + //添加多个实体 + #endregion + bool AddRange(IEnumerable 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 Detete(int id); + + #region + //删除多个实体 + #endregion + bool DeteteRange(IEnumerable entity); + } +} diff --git a/CC.Yi/CC.Yi.IDAL/T4IDAL.cs b/CC.Yi/CC.Yi.IDAL/T4IDAL.cs new file mode 100644 index 00000000..cdedb67f --- /dev/null +++ b/CC.Yi/CC.Yi.IDAL/T4IDAL.cs @@ -0,0 +1,14 @@ +using CC.Yi.Model; +using System; +using System.Collections.Generic; +using System.Text; + +namespace CC.Yi.IDAL +{ + public partial interface IstudentDal:IBaseDal + { + } + public partial interface IpropDal:IBaseDal + { + } +} \ No newline at end of file diff --git a/CC.Yi/CC.Yi.IDAL/T4IDAL.tt b/CC.Yi/CC.Yi.IDAL/T4IDAL.tt new file mode 100644 index 00000000..7faf648f --- /dev/null +++ b/CC.Yi/CC.Yi.IDAL/T4IDAL.tt @@ -0,0 +1,29 @@ +<#@ 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 System; +using System.Collections.Generic; +using System.Text; + +namespace CC.Yi.IDAL +{ +<# foreach(string k in ModelData){ + #> + public partial interface I<#=k #>Dal:IBaseDal<<#=k #>> + { + } +<# } #> +} \ No newline at end of file diff --git a/CC.Yi.Model/CC.Yi.Model.csproj b/CC.Yi/CC.Yi.Model/CC.Yi.Model.csproj similarity index 100% rename from CC.Yi.Model/CC.Yi.Model.csproj rename to CC.Yi/CC.Yi.Model/CC.Yi.Model.csproj diff --git a/CC.Yi.Model/DataContext.cs b/CC.Yi/CC.Yi.Model/DataContext.cs similarity index 100% rename from CC.Yi.Model/DataContext.cs rename to CC.Yi/CC.Yi.Model/DataContext.cs diff --git a/CC.Yi/CC.Yi.Model/T4DataContext.cs b/CC.Yi/CC.Yi.Model/T4DataContext.cs new file mode 100644 index 00000000..fc848fa3 --- /dev/null +++ b/CC.Yi/CC.Yi.Model/T4DataContext.cs @@ -0,0 +1,12 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Text; +namespace CC.Yi.Model +{ + public partial class DataContext :DbContext + { + public DbSet student { get; set; } + public DbSet prop { get; set; } + } +} \ No newline at end of file diff --git a/CC.Yi/CC.Yi.Model/T4DataContext.tt b/CC.Yi/CC.Yi.Model/T4DataContext.tt new file mode 100644 index 00000000..2fa74f5b --- /dev/null +++ b/CC.Yi/CC.Yi.Model/T4DataContext.tt @@ -0,0 +1,29 @@ +<#@ 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 Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Text; +namespace CC.Yi.Model +{ + public partial class DataContext :DbContext + { +<# foreach(string k in ModelData){ + #> + public DbSet<<#=k #>> <#=k #> { get; set; } +<# } #> + } +} \ No newline at end of file diff --git a/CC.Yi/CC.Yi.Model/prop.cs b/CC.Yi/CC.Yi.Model/prop.cs new file mode 100644 index 00000000..89ef8db1 --- /dev/null +++ b/CC.Yi/CC.Yi.Model/prop.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Text; + +namespace CC.Yi.Model +{ + public class prop + { + [Key] + [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] + public int id { get; set; } + public string name { get; set; } + public student student { get; set; } + } +} diff --git a/CC.Yi/CC.Yi.Model/student.cs b/CC.Yi/CC.Yi.Model/student.cs new file mode 100644 index 00000000..068d3e42 --- /dev/null +++ b/CC.Yi/CC.Yi.Model/student.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Text; + +namespace CC.Yi.Model +{ + public class student + { + [Key] + [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] + public int id { get; set; } + public string name { get; set; } + public List props { get; set; } + } +} diff --git a/CC.Yi/CC.Yi.ViewModel/CC.Yi.ViewModel.csproj b/CC.Yi/CC.Yi.ViewModel/CC.Yi.ViewModel.csproj new file mode 100644 index 00000000..cefa80a0 --- /dev/null +++ b/CC.Yi/CC.Yi.ViewModel/CC.Yi.ViewModel.csproj @@ -0,0 +1,8 @@ + + + + Library + netcoreapp3.1 + + + diff --git a/CC.Yi.sln b/CC.Yi/CC.Yi.sln similarity index 100% rename from CC.Yi.sln rename to CC.Yi/CC.Yi.sln diff --git a/CC.Yi/T4Model/T4Model.txt b/CC.Yi/T4Model/T4Model.txt new file mode 100644 index 00000000..917deacb --- /dev/null +++ b/CC.Yi/T4Model/T4Model.txt @@ -0,0 +1 @@ +student,prop \ No newline at end of file diff --git a/CC.Yi/T4Model/说明.txt b/CC.Yi/T4Model/说明.txt new file mode 100644 index 00000000..7abbdd18 --- /dev/null +++ b/CC.Yi/T4Model/说明.txt @@ -0,0 +1,5 @@ +这里存放T4要生成的模型 +使用英文的 , 分隔 +例如: +student,teacher +点击 生成->转换所有t4模板 即可完成生成 \ No newline at end of file