From 8673e8fd857f1be4cc4b7f84a3b1b5f3159d65c8 Mon Sep 17 00:00:00 2001 From: "454313500@qq.com" <454313500@qq.com> Date: Sat, 10 Apr 2021 18:28:45 +0800 Subject: [PATCH] v1.1.2 --- CC.Yi.API/Controllers/StudentController.cs | 43 +-- .../Migrations/20210410090937_yi5.Designer.cs | 40 +++ CC.Yi.API/Migrations/20210410090937_yi5.cs | 220 +++++++++++++++ .../Migrations/DataContextModelSnapshot.cs | 261 ------------------ CC.Yi.API/Startup.cs | 62 +++-- CC.Yi.API/appsettings.json | 5 +- CC.Yi.Common/JsonHelper.cs | 16 +- CC.Yi.Common/Result.cs | 40 +++ CC.Yi.DALFactory/DbSession.cs | 2 +- CC.Yi.Model/DataContext.cs | 7 +- CC.Yi.Model/T4DataContext.cs | 4 +- CC.Yi.Model/T4DataContext.tt | 4 +- 12 files changed, 386 insertions(+), 318 deletions(-) create mode 100644 CC.Yi.API/Migrations/20210410090937_yi5.Designer.cs create mode 100644 CC.Yi.API/Migrations/20210410090937_yi5.cs create mode 100644 CC.Yi.Common/Result.cs diff --git a/CC.Yi.API/Controllers/StudentController.cs b/CC.Yi.API/Controllers/StudentController.cs index 311e2508..c194db1f 100644 --- a/CC.Yi.API/Controllers/StudentController.cs +++ b/CC.Yi.API/Controllers/StudentController.cs @@ -1,7 +1,9 @@ using CC.Yi.IBLL; using CC.Yi.Model; +using Common; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -16,18 +18,18 @@ namespace CC.Yi.API.Controllers { private readonly ILogger _logger;//处理日志相关文件 - private UserManager _userManager;//处理用户相关逻辑:添加密码,修改密码,添加删除角色等等 - private SignInManager _signInManager;//处理注册登录的相关逻辑 + //private UserManager _userManager;//处理用户相关逻辑:添加密码,修改密码,添加删除角色等等 + //private SignInManager _signInManager;//处理注册登录的相关逻辑 private IstudentBll _studentBll; - public StudentController(ILogger logger, IstudentBll studentBll, UserManager userManager, SignInManager signInManager) + public StudentController(ILogger logger, IstudentBll studentBll) { _logger = logger; _logger.LogInformation("现在你进入了StudentController控制器"); _studentBll = studentBll; - _userManager = userManager; - _signInManager = signInManager; + //_userManager = userManager; + //_signInManager = signInManager; } #region //关于身份认证配置使用: @@ -54,45 +56,52 @@ namespace CC.Yi.API.Controllers //注意:请确保你的数据库中存在合理的数据 #endregion [HttpGet] - public IActionResult GetTest()//查 + public async Task GetTest()//查 { _logger.LogInformation("调用查方法"); - var data = _studentBll.GetAllEntities().ToList(); - return Content(Common.JsonHelper.JsonToString(data)); + var data =await _studentBll.GetAllEntities().ToListAsync(); + return Result.Success("查询成功").SetData(data); } [HttpGet] - public IActionResult AddTest()//增 + public Result AddTest()//增 { _logger.LogInformation("调用增方法"); List students = new List() {new student { name = "学生a" } ,new student { name="学生d"} }; - _studentBll.Add(students); - return Content("ok"); + if (_studentBll.Add(students)) + { + return Result.Success("增加成功"); + } + else + { + return Result.Error("增加失败"); + } + } [HttpGet] - public IActionResult RemoveTest()//删 + public Result RemoveTest()//删 { _logger.LogInformation("调用删方法"); if (_studentBll.Delete(u=>u.name=="学生a")) { - return Content("ok"); + return Result.Success("删除成功"); } else { - return Content("no"); + return Result.Error("删除失败"); } } [HttpGet] - public IActionResult UpdateTest()//改 + public Result UpdateTest()//改 { _logger.LogInformation("调用改方法"); if (_studentBll.Update(new student { id=2, name = "学生a" }, "name")) { - return Content("ok"); + return Result.Success("修改成功"); } else { - return Content("no"); + return Result.Error("修改失败"); } } diff --git a/CC.Yi.API/Migrations/20210410090937_yi5.Designer.cs b/CC.Yi.API/Migrations/20210410090937_yi5.Designer.cs new file mode 100644 index 00000000..6038f52c --- /dev/null +++ b/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.API/Migrations/20210410090937_yi5.cs b/CC.Yi.API/Migrations/20210410090937_yi5.cs new file mode 100644 index 00000000..73cf0845 --- /dev/null +++ b/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.API/Migrations/DataContextModelSnapshot.cs index 9ea1d271..1952adda 100644 --- a/CC.Yi.API/Migrations/DataContextModelSnapshot.cs +++ b/CC.Yi.API/Migrations/DataContextModelSnapshot.cs @@ -1,5 +1,4 @@ // -using System; using CC.Yi.Model; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -33,266 +32,6 @@ namespace CC.Yi.API.Migrations 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.API/Startup.cs b/CC.Yi.API/Startup.cs index 9ffc7e32..abe98ff5 100644 --- a/CC.Yi.API/Startup.cs +++ b/CC.Yi.API/Startup.cs @@ -38,50 +38,62 @@ namespace CC.Yi.API // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - + services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "CC.Yi.API", Version = "v1" }); }); - string connection = Configuration["ConnectionStringBySQL"]; + services.AddSession(); + services.AddMvc(); + string connection1 = Configuration["ConnectionStringBySQL"]; string connection2 = Configuration["ConnectionStringByMySQL"]; + string connection3 = Configuration["ConnectionStringBySQLite"]; services.AddDbContext(options => { - options.UseSqlServer(connection, b => b.MigrationsAssembly("CC.Yi.API"));//ݿ + options.UseSqlServer(connection1, b => b.MigrationsAssembly("CC.Yi.API"));//ݿ }); //עתAutofac //services.AddScoped(typeof(IBaseDal<>), typeof(BaseDal<>)); //services.AddScoped(typeof(IstudentBll), typeof(studentBll)); - services.AddSingleton(typeof(ICacheWriter), new RedisCacheService(new Microsoft.Extensions.Caching.Redis.RedisCacheOptions() - { - Configuration = Configuration.GetSection("Cache.ConnectionString").Value, - InstanceName = Configuration.GetSection("Cache.InstanceName").Value - })); + + //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 => + //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 => { - 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(); + builder.AllowAnyMethod() + .SetIsOriginAllowed(_ => true) + .AllowAnyHeader() + .AllowCredentials(); + })); } private void InitData(IServiceProvider serviceProvider) { var serviceScope = serviceProvider.GetRequiredService().CreateScope(); - - var context = serviceScope.ServiceProvider.GetService(); - DbContentFactory.Initialize(context);//þ̬෽ע - + + var context = serviceScope.ServiceProvider.GetService(); + DbContentFactory.Initialize(context);//þ̬෽ע } @@ -89,7 +101,7 @@ namespace CC.Yi.API // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { - + if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); @@ -97,10 +109,10 @@ namespace CC.Yi.API app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "CC.Yi.API v1")); } - app.UseAuthentication(); - + //app.UseAuthentication(); + app.UseCors("CorsPolicy"); app.UseHttpsRedirection(); - + app.UseSession(); app.UseRouting(); app.UseAuthorization(); diff --git a/CC.Yi.API/appsettings.json b/CC.Yi.API/appsettings.json index b5156473..429d06ac 100644 --- a/CC.Yi.API/appsettings.json +++ b/CC.Yi.API/appsettings.json @@ -11,6 +11,7 @@ "InstanceName": "Redis", "ConnectionString": "127.0.0.1:12345,password=123456" }, - "ConnectionStringBySQL": "server=.;Database=cctest;UId=sa;PWD=Qz52013142020.", - "ConnectionStringByMySQL": "Data Source=.;Database=cctest;User ID=root;Password=Qz52013142020.;pooling=true;port=3306;sslmode=none;CharSet=utf8;" + "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.Common/JsonHelper.cs b/CC.Yi.Common/JsonHelper.cs index b427195b..bf4c8dfa 100644 --- a/CC.Yi.Common/JsonHelper.cs +++ b/CC.Yi.Common/JsonHelper.cs @@ -4,9 +4,21 @@ namespace CC.Yi.Common { public static class JsonHelper { - public static string JsonToString(object q) + public static string JsonToString(object data=null, int code = 200, bool flag = true, string message = "成功") { - return Newtonsoft.Json.JsonConvert.SerializeObject(q); + 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/Result.cs b/CC.Yi.Common/Result.cs new file mode 100644 index 00000000..0b4940ce --- /dev/null +++ b/CC.Yi.Common/Result.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace 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) + { + 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.DALFactory/DbSession.cs b/CC.Yi.DALFactory/DbSession.cs index b6de042d..7fa154f4 100644 --- a/CC.Yi.DALFactory/DbSession.cs +++ b/CC.Yi.DALFactory/DbSession.cs @@ -18,7 +18,7 @@ namespace CC.Yi.DALFactory try { // Attempt to save changes to the database - context.SaveChanges(); + context.SaveChangesAsync(); saved = true; } catch (DbUpdateConcurrencyException ex) diff --git a/CC.Yi.Model/DataContext.cs b/CC.Yi.Model/DataContext.cs index 71992485..98a047bd 100644 --- a/CC.Yi.Model/DataContext.cs +++ b/CC.Yi.Model/DataContext.cs @@ -1,15 +1,14 @@ -using Microsoft.AspNetCore.Identity.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using System; namespace CC.Yi.Model { - public partial class DataContext : IdentityDbContext + public partial class DataContext : DbContext { public DataContext(DbContextOptions options) : base(options) { } - public DbSet result_user { get; set; } + //public DbSet result_user { get; set; } } } diff --git a/CC.Yi.Model/T4DataContext.cs b/CC.Yi.Model/T4DataContext.cs index df21a4f0..584f6d63 100644 --- a/CC.Yi.Model/T4DataContext.cs +++ b/CC.Yi.Model/T4DataContext.cs @@ -2,11 +2,9 @@ using System; using System.Collections.Generic; using System.Text; -using Microsoft.AspNetCore.Identity.EntityFrameworkCore; - namespace CC.Yi.Model { - public partial class DataContext :IdentityDbContext + public partial class DataContext :DbContext { public DbSet student { get; set; } } diff --git a/CC.Yi.Model/T4DataContext.tt b/CC.Yi.Model/T4DataContext.tt index 61baf89b..2fa74f5b 100644 --- a/CC.Yi.Model/T4DataContext.tt +++ b/CC.Yi.Model/T4DataContext.tt @@ -17,11 +17,9 @@ using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Text; -using Microsoft.AspNetCore.Identity.EntityFrameworkCore; - namespace CC.Yi.Model { - public partial class DataContext :IdentityDbContext + public partial class DataContext :DbContext { <# foreach(string k in ModelData){ #>