v3.0.1
This commit is contained in:
橙子
2021-06-02 20:00:25 +08:00
parent 6ea91cbaf6
commit e5063e1a4d
57 changed files with 1665 additions and 359 deletions

View File

@@ -8,7 +8,7 @@
<PackageReference Include="Autofac" Version="6.1.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.4">
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

View File

@@ -29,14 +29,12 @@ namespace CC.Yi.API.Controllers
//private UserManager<result_user> _userManager;//处理用户相关逻辑:添加密码,修改密码,添加删除角色等等
//private SignInManager<result_user> _signInManager;//处理注册登录的相关逻辑
private IpropBll _propBll;
private IstudentBll _studentBll;
public StudentController(ILogger<StudentController> logger, IstudentBll studentBll,IpropBll propBll)
public StudentController(ILogger<StudentController> logger, IstudentBll studentBll)
{
_logger = logger;
_logger.LogInformation("现在你进入了StudentController控制器");
_logger.LogInformation("现在你进入了StudentController控制器");//nlog日志模块
_studentBll = studentBll;
_propBll = propBll;
}
#region
//关于身份认证配置使用:
@@ -56,42 +54,20 @@ 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
})
});
}
#region
//redis操作
#endregion
[HttpGet]
public Result GetReids()
{
var data = CacheHelper.CacheWriter.GetCache<string>("key01");
return Result.Success(data);
}
#region
//下面,权限验证
#endregion
//发送令牌
[HttpGet]
public Result Login(string role)
{
@@ -116,7 +92,7 @@ namespace CC.Yi.API.Controllers
var tokenData = new JwtSecurityTokenHandler().WriteToken(token);
return Result.Success("欢迎你!管理员!").SetData(new { token = tokenData });
}
}//发送令牌
[HttpGet]
[Authorize(Policy = "myadmin")]//基于策略的验证
@@ -140,49 +116,32 @@ namespace CC.Yi.API.Controllers
public async Task<Result> GetTest()//查
{
_logger.LogInformation("调用查方法");
var data =await _studentBll.GetAllEntities().ToListAsync();
var data = await _studentBll.GetAllEntities().ToListAsync();
return Result.Success().SetData(data);
}
[HttpGet]
public Result AddTest()//增
{
_logger.LogInformation("调用增方法");
List<student> students = new List<student>() { new student { name = "学生a" }, new student { name = "学生d" } };
if (_studentBll.Add(students))
{
return Result.Success();
}
else
{
return Result.Error();
}
List<student> students = new List<student>() { new student { name = "学生a" } };
_studentBll.Add(students);
return Result.Success();
}
[HttpGet]
public Result RemoveTest()//删
{
_logger.LogInformation("调用删方法");
if (_studentBll.Delete(u => u.name == "学生a"))
{
return Result.Success();
}
else
{
return Result.Error();
}
_studentBll.Delete(u => u.id==1);
return Result.Success();
}
[HttpGet]
public Result UpdateTest()//改
public Result UpdateTest()//改
{
_logger.LogInformation("调用改方法");
if (_studentBll.Update(new student { id = 2, name = "学生a" }, "name"))
{
return Result.Success();
}
else
{
return Result.Error();
}
_studentBll.Update(new student { id = 1, name = "学生b" }, "name");
return Result.Success();
}
}
}

View File

@@ -0,0 +1,72 @@
using CC.Yi.Common;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace CC.Yi.API.Extension
{
public class ErrorHandExtension
{
private readonly RequestDelegate next;
public ErrorHandExtension(RequestDelegate next)
{
this.next = next;
}
public async Task Invoke(HttpContext context)
{
try
{
await next(context);
}
catch (Exception ex)
{
var statusCode = context.Response.StatusCode;
if (ex is ArgumentException)
{
statusCode = 200;
}
await HandleExceptionAsync(context, statusCode, ex.Message);
}
finally
{
var statusCode = context.Response.StatusCode;
var msg = "";
switch (statusCode)
{
case 401: msg = "未授权";break;
case 403: msg = "未授权"; break;
case 404: msg = "未找到服务"; break;
case 502: msg = "请求错误"; break;
}
if (!string.IsNullOrWhiteSpace(msg))
{
await HandleExceptionAsync(context, statusCode, msg);
}
}
}
//异常错误信息捕获将错误信息用Json方式返回
private static Task HandleExceptionAsync(HttpContext context, int statusCode, string msg)
{
var result = JsonConvert.SerializeObject( Result.Error(msg).SetCode(statusCode));
context.Response.ContentType = "application/json;charset=utf-8";
return context.Response.WriteAsync(result);
}
}
//扩展方法
public static class ErrorHandlingExtensions
{
public static IApplicationBuilder UseErrorHandling(this IApplicationBuilder builder)
{
return builder.UseMiddleware<ErrorHandExtension>();
}
}
}

View File

@@ -69,7 +69,7 @@ namespace CC.Yi.API.Extension
//在 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"));
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Yi"));
}
}

View File

@@ -0,0 +1,71 @@
using CC.Yi.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace CC.Yi.API.Init
{
public static class InitDb
{
public static bool Init(DataContext Db)
{
//if (!Db.Set<user>().Any())
//{
// user initUser = new user
// {
// username = "cc",
// password = "123",
// user_extra = new user_extra(),
// time = DateTime.Now,
// roles = new List<role>{
// new role{
// role_name="管理员",
// actions=new List<action>{
// new action{ action_name="首页",router="/index",icon="mdi-view-dashboard"},
// new action{action_name="用户管理",router="/user",icon="mdi-account-box"},
// new action{ action_name="角色管理",router="/role",icon="mdi-gavel"},
// new action{ action_name="权限管理",router="/action",icon="mdi-lock"}
// }
// },
// new role{ role_name="l-1"},
// new role{ role_name="l-2"},
// new role{ role_name="l-3"},
// new role{ role_name="l-4"},
// new role{ role_name="l-5"},
// new role{ role_name="l-6"},
// new role{ role_name="l-7"},
// new role{ role_name="l-8"},
// new role{ role_name="l-9"},
// new role{ role_name="l-10"},
// new role{ role_name="l-11"},
// new role{ role_name="l-12"},
// new role{ role_name="普通用户"}
// }
// };
// Db.Set<user>().Update(initUser);
// //-------------------------------------------------------------------------------------添加管理员账户
// List<level> levels = new List<level>
// {
// new level{num=0, name="小白0",max_char=50,experience=0},
// new level{num=1, name="小白1",max_char=100,experience=5},
// new level{num=2, name="小白2",max_char=200,experience=10},
// new level{num=3, name="小白3",max_char=300,experience=15},
// new level{num=4, name="小白4",max_char=400,experience=20},
// new level{num=5, name="小白5",max_char=500,experience=25},
// new level{num=6, name="小白6",max_char=600,experience=30},
// new level{num=7, name="小白7",max_char=700,experience=35},
// new level{num=8, name="小白8",max_char=800,experience=40},
// new level{num=9, name="小白9",max_char=900,experience=45},
// new level{num=10, name="小白10",max_char=1000,experience=50},
// new level{num=11, name="小白11",max_char=1100,experience=55}
// };
// Db.Set<level>().AddRange(levels);
// //---------------------------------------------------------------------------------------添加等级表
// return Db.SaveChanges()>0;
//}
return false;
}
}
}

View File

@@ -1,70 +0,0 @@
// <auto-generated />
using System;
using CC.Yi.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace CC.Yi.API.Migrations
{
[DbContext(typeof(DataContext))]
[Migration("20210526080428_yi2")]
partial class yi2
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "5.0.5");
modelBuilder.Entity("CC.Yi.Model.prop", b =>
{
b.Property<int>("id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("name")
.HasColumnType("TEXT");
b.Property<int?>("studentid")
.HasColumnType("INTEGER");
b.HasKey("id");
b.HasIndex("studentid");
b.ToTable("prop");
});
modelBuilder.Entity("CC.Yi.Model.student", b =>
{
b.Property<int>("id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("name")
.HasColumnType("TEXT");
b.HasKey("id");
b.ToTable("student");
});
modelBuilder.Entity("CC.Yi.Model.prop", b =>
{
b.HasOne("CC.Yi.Model.student", "student")
.WithMany("props")
.HasForeignKey("studentid");
b.Navigation("student");
});
modelBuilder.Entity("CC.Yi.Model.student", b =>
{
b.Navigation("props");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -1,41 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace CC.Yi.API.Migrations
{
public partial class yi2 : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "prop",
columns: table => new
{
id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
name = table.Column<string>(type: "TEXT", nullable: true),
studentid = table.Column<int>(type: "INTEGER", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_prop", x => x.id);
table.ForeignKey(
name: "FK_prop_student_studentid",
column: x => x.studentid,
principalTable: "student",
principalColumn: "id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "IX_prop_studentid",
table: "prop",
column: "studentid");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "prop");
}
}
}

View File

@@ -1,68 +0,0 @@
// <auto-generated />
using System;
using CC.Yi.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace CC.Yi.API.Migrations
{
[DbContext(typeof(DataContext))]
partial class DataContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "5.0.5");
modelBuilder.Entity("CC.Yi.Model.prop", b =>
{
b.Property<int>("id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("name")
.HasColumnType("TEXT");
b.Property<int?>("studentid")
.HasColumnType("INTEGER");
b.HasKey("id");
b.HasIndex("studentid");
b.ToTable("prop");
});
modelBuilder.Entity("CC.Yi.Model.student", b =>
{
b.Property<int>("id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("name")
.HasColumnType("TEXT");
b.HasKey("id");
b.ToTable("student");
});
modelBuilder.Entity("CC.Yi.Model.prop", b =>
{
b.HasOne("CC.Yi.Model.student", "student")
.WithMany("props")
.HasForeignKey("studentid");
b.Navigation("student");
});
modelBuilder.Entity("CC.Yi.Model.student", b =>
{
b.Navigation("props");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -17,17 +17,16 @@ namespace CC.Yi.API
{
public static void Main(string[] args)
{
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ݿ⣬<DDBF><E2A3AC><EFBFBD>޸<EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
//<2F><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><E0A3AC>ģ<EFBFBD>Ͳ<EFBFBD><CDB2>У<EFBFBD>ʹ<EFBFBD><CAB9>Add-Migration xxxǨ<78>ƣ<EFBFBD><C6A3><EFBFBD>ʹ<EFBFBD><CAB9>Update-Database<73><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>
//<2F><>T4Model<65><6C><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>T4
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><ECBAAF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>ֱ<EFBFBD><D6B1>ʹ<EFBFBD><CAB9>
var logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();
try
{
logger.Debug("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Yi<59><69><EFBFBD><EFBFBD><EFBFBD>ܡ<EFBFBD><DCA1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
var host = CreateHostBuilder(args).Build();
//var scope = host.Services.CreateScope();
//var services = scope.ServiceProvider;
//var context = services.GetRequiredService<Model.DataContext>();//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
//DbContentFactory.Initialize(context);//<2F><><EFBFBD>þ<EFBFBD>̬<EFBFBD><EFBFBD><E0B7BD>ע<EFBFBD><D7A2>
host.Run();
logger.Info("Yi<59><69><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD>");
}
@@ -42,10 +41,6 @@ namespace CC.Yi.API
// 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) =>

View File

@@ -3,6 +3,7 @@ using Autofac.Extras.DynamicProxy;
using CC.Yi.API.Extension;
using CC.Yi.BLL;
using CC.Yi.Common.Castle;
using CC.Yi.Common.Json;
using CC.Yi.Common.Jwt;
using CC.Yi.DAL;
using CC.Yi.IBLL;
@@ -11,6 +12,7 @@ using CC.Yi.Model;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
@@ -44,60 +46,65 @@ namespace CC.Yi.API
services.AddAuthorization(options =>
{
//<2F><><EFBFBD>û<EFBFBD><C3BB>ڲ<EFBFBD><DAB2>Ե<EFBFBD><D4B5><EFBFBD>֤
options.AddPolicy("myadmin", policy =>
policy.RequireRole("admin"));
options.AddPolicy("myadmin", policy =>policy.RequireRole("admin"));
});
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options => {
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,//<2F>Ƿ<EFBFBD><C7B7><EFBFBD>֤Issuer
ValidateAudience = true,//<2F>Ƿ<EFBFBD><C7B7><EFBFBD>֤Audience
ValidateLifetime = true,//<2F>Ƿ<EFBFBD><C7B7><EFBFBD>֤ʧЧʱ<D0A7><CAB1>
ClockSkew = TimeSpan.FromSeconds(30),
ClockSkew = TimeSpan.FromDays(1),
ValidateIssuerSigningKey = true,//<2F>Ƿ<EFBFBD><C7B7><EFBFBD>֤SecurityKey
ValidAudience = JwtConst.Domain,//Audience
ValidIssuer = JwtConst.Domain,//Issuer<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0>ǩ<EFBFBD><C7A9>jwt<77><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(JwtConst.SecurityKey))//<2F>õ<EFBFBD>SecurityKey
};
});
services.AddControllers();
services.AddSwaggerService();
services.AddSession();
//ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD>
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
//<2F><><EFBFBD>ù<EFBFBD><C3B9><EFBFBD><EFBFBD><EFBFBD>
Action<MvcOptions> filters = new Action<MvcOptions>(r => {
Action<MvcOptions> filters = new Action<MvcOptions>(r =>
{
//r.Filters.Add(typeof(DbContextFilter));
});
services.AddMvc(filters);
services.AddControllers(filters).AddJsonOptions(options => {
options.JsonSerializerOptions.Converters.Add(new DatetimeJsonConverter());
options.JsonSerializerOptions.Converters.Add(new TimeSpanJsonConverter());
});
services.AddSwaggerService();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD>
string connection1 = Configuration["ConnectionStringBySQL"];
string connection2 = Configuration["ConnectionStringByMySQL"];
string connection3 = Configuration["ConnectionStringBySQLite"];
string connection4 = Configuration["ConnectionStringByOracle"];
//var serverVersion = new MySqlServerVersion(new Version(8, 0, 21));//mysql<71>
services.AddDbContext<DataContext>(options =>
{
options.UseSqlite(connection3, b => b.MigrationsAssembly("CC.Yi.API"));//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>
//options.UseSqlServer(connection1);//sqlserver<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//options.UseMySql(connection2, serverVersion);//mysql<71><6C><EFBFBD><EFBFBD>
options.UseSqlite(connection3);//sqlite<74><65><EFBFBD><EFBFBD>
//options.UseOracle(connection4);//oracle<6C><65><EFBFBD><EFBFBD>
});
//<2F><><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>Autofac
//services.AddScoped(typeof(IBaseDal<>), typeof(BaseDal<>));
//services.AddScoped(typeof(IstudentBll), typeof(studentBll));
//<2F><><EFBFBD><EFBFBD>Identity<74><79><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤
//services.AddIdentity<result_user, IdentityRole>(options =>
// {
// options.Password.RequiredLength = 6;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳<EFBFBD><CCB3><EFBFBD>
// options.Password.RequireDigit = false;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// options.Password.RequireLowercase = false;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Сд<D0A1><D0B4>ĸ
// options.Password.RequireNonAlphanumeric = false;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
// options.Password.RequireUppercase = false;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4>ĸ
// //options.User.RequireUniqueEmail = false;//ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2>ظ<EFBFBD>
// //options.User.AllowedUserNameCharacters="abcd"//<2F><><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
//}).AddEntityFrameworkStores<DataContext>().AddDefaultTokenProviders();
services.AddCors(options => options.AddPolicy("CorsPolicy",//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
builder =>
{
@@ -111,10 +118,15 @@ namespace CC.Yi.API
//<2F><>ʼ<EFBFBD><CABC>ʹ<EFBFBD>ú<EFBFBD><C3BA><EFBFBD>
private void InitData(IServiceProvider serviceProvider)
{
//var serviceScope = serviceProvider.GetRequiredService<IServiceScopeFactory>().CreateScope();
//var context = serviceScope.ServiceProvider.GetService<DataContext>();
//DbContentFactory.Initialize(context);//<2F><><EFBFBD>þ<EFBFBD>̬<EFBFBD><EFBFBD><E0B7BD>ע<EFBFBD><D7A2>
using (var serviceScope = serviceProvider.GetRequiredService<IServiceScopeFactory>().CreateScope())
{
var Db = serviceScope.ServiceProvider.GetService<DataContext>();
var log = serviceScope.ServiceProvider.GetService<Logger<string>>();
if (Init.InitDb.Init(Db))
{
log.LogInformation("<22><><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD>");
}
}
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -123,14 +135,23 @@ namespace CC.Yi.API
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
//<2F><><EFBFBD>ÿ<EFBFBD><C3BF>ӻ<EFBFBD><D3BB>ӿ<EFBFBD>
app.UseSwaggerService();
}
//<2F><><EFBFBD>þ<EFBFBD>̬<EFBFBD>ļ<EFBFBD>
app.UseStaticFiles();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><ECB3A3>׽
app.UseErrorHandling();
//<2F><><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
app.UseCors("CorsPolicy");
app.UseHttpsRedirection();
app.UseSession();
app.UseRouting();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤
app.UseAuthentication();
app.UseAuthorization();
@@ -138,6 +159,8 @@ namespace CC.Yi.API
{
endpoints.MapControllers();
});
//<2F><>ʼ<EFBFBD><CABC>
InitData(app.ApplicationServices);
}
}

View File

@@ -18,7 +18,6 @@ namespace CC.Yi.API
builder.RegisterType(typeof(CustomAutofacAop));
builder.RegisterGeneric(typeof(BaseDal<>)).As(typeof(IBaseDal<>));
builder.RegisterType<studentBll>().As<IstudentBll>().EnableInterfaceInterceptors();//表示注入前后要执行CastleAOP
builder.RegisterType<propBll>().As<IpropBll>().EnableInterfaceInterceptors();//表示注入前后要执行CastleAOP
}
}
}

Binary file not shown.

View File

@@ -7,8 +7,8 @@
}
},
"AllowedHosts": "*",
"ConnectionStringBySQL": "server=.;Database=YIDB;UId=sa;PWD=52013142020.",
"ConnectionStringByMySQL": "Data Source=.;Database=YIDB;User ID=root;Password=52013142020.;pooling=true;port=3306;sslmode=none;CharSet=utf8;",
"ConnectionStringBySQLite": "Filename=YIDB.db"
"ConnectionStringBySQL": "server=.;Database=YIDB;UId=sa;PWD=Qz52013142020.",
"ConnectionStringByMySQL": "Data Source=49.235.212.122;Database=YIDB;User ID=root;Password=Qz52013142020.;pooling=true;port=3306;sslmode=none;CharSet=utf8;",
"ConnectionStringBySQLite": "Filename=YIDB.db",
"ConnectionStringByOracle": "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=IP<49><50>ַ)(PORT=<3D>˿ں<CBBF>))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)));User Id=<3D><>¼<EFBFBD>˺<EFBFBD>;Password=<3D><><EFBFBD><EFBFBD>;"
}

View File

@@ -14,11 +14,11 @@
<targets>
<!-- 写入文件配置 -->
<!-- write logs to file -->
<target xsi:type="File" name="allfile" fileName="Logs\nlog-all-${shortdate}.log"
<target xsi:type="File" name="allfile" fileName="Logs/nlog-all-${shortdate}.log"
layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring} ${newline}" />
<!-- another file log, only own logs. Uses some ASP.NET core renderers -->
<target xsi:type="File" name="ownFile-web" fileName="Logs\nlog-own-${shortdate}.log"
<target xsi:type="File" name="ownFile-web" fileName="Logs/nlog-own-${shortdate}.log"
layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action} ${newline}" />
</targets>

View File

@@ -6,19 +6,26 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
namespace CC.Yi.BLL
{
public class BaseBll<T> : IBaseBll<T> where T : class, new()
{
public IBaseDal<T> CurrentDal;
public DbContext DbSession;
public DbContext Db;
public BaseBll(IBaseDal<T> cd, DataContext _Db)
{
CurrentDal = cd;
DbSession = _Db;
Db = _Db;
}
public async Task<T> GetEntityById(int id)
{
return await CurrentDal.GetEntityById(id);
}
public IQueryable<T> GetAllEntities()
{
return CurrentDal.GetAllEntities();
@@ -40,7 +47,6 @@ namespace CC.Yi.BLL
}
public IQueryable<T> GetPageEntities<S>(int pageSize, int pageIndex, out int total, Expression<Func<T, bool>> whereLambda, Expression<Func<T, S>> orderByLambda, bool isAsc)
{
return CurrentDal.GetPageEntities(pageSize, pageIndex, out total, whereLambda, orderByLambda, isAsc);
@@ -48,38 +54,38 @@ namespace CC.Yi.BLL
public T Add(T entity)
{
CurrentDal.Add(entity);
DbSession.SaveChanges();
return entity;
T entityData= CurrentDal.Add(entity);
Db.SaveChanges();
return entityData;
}
public bool Add(IEnumerable<T> entities)
{
CurrentDal.AddRange(entities);
return DbSession.SaveChanges() > 0;
return Db.SaveChanges() > 0;
}
public bool Update(T entity)
{
CurrentDal.Update(entity);
return DbSession.SaveChanges() > 0;
return Db.SaveChanges() > 0;
}
public bool Update(T entity, params string[] propertyNames)
{
CurrentDal.Update(entity,propertyNames);
return DbSession.SaveChanges() > 0;
return Db.SaveChanges() > 0;
}
public bool Delete(T entity)
{
CurrentDal.Delete(entity);
return DbSession.SaveChanges() > 0;
return Db.SaveChanges() > 0;
}
public bool Delete(int id)
{
CurrentDal.Detete(id);
return DbSession.SaveChanges() > 0;
return Db.SaveChanges() > 0;
}
public bool Delete(IEnumerable<int> ids)
@@ -88,7 +94,7 @@ namespace CC.Yi.BLL
{
CurrentDal.Detete(id);
}
return DbSession.SaveChanges()>0;
return Db.SaveChanges()>0;
}
public bool Delete(Expression<Func<T, bool>> where)
{
@@ -97,7 +103,7 @@ namespace CC.Yi.BLL
{
CurrentDal.DeteteRange(entities);
return DbSession.SaveChanges()>0;
return Db.SaveChanges()>0;
}
return false;
}

View File

@@ -7,6 +7,7 @@
<ItemGroup>
<ProjectReference Include="..\CC.Yi.IBLL\CC.Yi.IBLL.csproj" />
<ProjectReference Include="..\CC.Yi.IDAL\CC.Yi.IDAL.csproj" />
<ProjectReference Include="..\CC.Yi.ViewModel\CC.Yi.ViewModel.csproj" />
</ItemGroup>
<ItemGroup>

View File

@@ -15,15 +15,18 @@ namespace CC.Yi.BLL
public studentBll(IBaseDal<student> cd,DataContext _Db):base(cd,_Db)
{
CurrentDal = cd;
DbSession = _Db;
Db = _Db;
}
}
public partial class propBll : BaseBll<prop>, IpropBll
{
public propBll(IBaseDal<prop> cd,DataContext _Db):base(cd,_Db)
public async Task<bool> DelListByUpdateList(List<int> Ids)
{
CurrentDal = cd;
DbSession = _Db;
var entitys = await CurrentDal.GetEntities(u => Ids.Contains(u.id)).ToListAsync();
foreach (var entity in entitys)
{
entity.is_delete = (short)ViewModel.Enum.DelFlagEnum.Deleted;
}
return Db.SaveChanges() > 0;
}
}
}

View File

@@ -32,8 +32,19 @@ namespace CC.Yi.BLL
public <#=k #>Bll(IBaseDal<<#=k #>> cd,DataContext _Db):base(cd,_Db)
{
CurrentDal = cd;
DbSession = _Db;
Db = _Db;
}
public async Task<bool> DelListByUpdateList(List<int> Ids)
{
var entitys = await CurrentDal.GetEntities(u => Ids.Contains(u.id)).ToListAsync();
foreach (var entity in entitys)
{
entity.is_delete = (short)ViewModel.Enum.DelFlagEnum.Deleted;
}
return Db.SaveChanges() > 0;
}
}
<# } #>
}

View File

@@ -7,10 +7,36 @@
<ItemGroup>
<PackageReference Include="Autofac.Extras.DynamicProxy" Version="6.0.0" />
<PackageReference Include="Castle.Core" Version="4.4.1" />
<PackageReference Include="MongoDB.Driver" Version="2.12.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.11.0" />
<PackageReference Include="ServiceStack.Redis" Version="5.10.4" />
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
</ItemGroup>
<ItemGroup>
<None Update="T4Vue\T4Api.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>T4Api.vue</LastGenOutput>
</None>
<None Update="T4Vue\T4Api.vue">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>T4Api.tt</DependentUpon>
</None>
<None Update="T4Vue\T4Component.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>T4Component.vue</LastGenOutput>
</None>
<None Update="T4Vue\T4Component.vue">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>T4Component.tt</DependentUpon>
</None>
</ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
</Project>

View File

@@ -17,33 +17,33 @@ namespace CC.Yi.Common.Cache
public bool AddCache<T>(string key, T value, DateTime expDate)
public static bool AddCache<T>(string key, T value, DateTime expDate)
{
return CacheWriter.AddCache<T>(key,value,expDate);
}
public bool AddCache<T>(string key, T value)
public static bool AddCache<T>(string key, T value)
{
return CacheWriter.AddCache<T>(key, value);
}
public bool RemoveCache(string key)
public static bool RemoveCache(string key)
{
return CacheWriter.RemoveCache(key);
}
public T GetCache<T>(string key)
public static T GetCache<T>(string key)
{
return CacheWriter.GetCache<T>(key);
}
public bool SetCache<T>(string key, T value, DateTime expDate)
public static bool SetCache<T>(string key, T value, DateTime expDate)
{
return CacheWriter.SetCache<T>(key,value,expDate);
}
public bool SetCache<T>(string key, T value)
{
public static bool SetCache<T>(string key, T value)
{
return CacheWriter.SetCache<T>(key, value);
}

View File

@@ -8,39 +8,92 @@ namespace CC.Yi.Common.Cache
public class RedisCache : ICacheWriter
{
private RedisClient client;
private string ip = "49.235.212.122";
private int port = 6379;
private string pwd = "Qz52013142020.";
public RedisCache()
{
client = new RedisClient("127.0.0.1", 6379, "52013142020.");
}
public void Dispose()
{
client.Dispose();
}
public bool AddCache<T>(string key, T value, DateTime expDate)
{
return client.Add<T>(key, value, expDate);
try
{
using (client = new RedisClient(ip, port, pwd))
{
return client.Add<T>(key, value, expDate);
}
}
catch
{
return false;
}
}
public bool AddCache<T>(string key, T value)
{
return client.Add<T>(key, value);
return client.Add<T>(key, value);
}
public bool RemoveCache(string key)
{
return client.Remove(key);
return client.Remove(key);
}
public T GetCache<T>(string key)
{
return client.Get<T>(key);
try
{
using (client = new RedisClient(ip, port, pwd))
{
return client.Get<T>(key);
}
}
catch
{
object p = new object();
return (T)p;
}
}
public bool SetCache<T>(string key,T value, DateTime expDate)
public bool SetCache<T>(string key, T value, DateTime expDate)
{
return client.Set<T>(key, value, expDate);
try
{
using (client = new RedisClient(ip, port, pwd))
{
return client.Set<T>(key, value, expDate);
}
}
catch
{
return false;
}
}
public bool SetCache<T>(string key, T value)
{
return client.Set<T>(key, value);
try
{
using (client = new RedisClient(ip, port, pwd))
{
return client.Set<T>(key, value);
}
}
catch
{
object p = new object();
return false;
}
}
}
}

View File

@@ -0,0 +1,113 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Mail;
using System.Net.Sockets;
using System.Text;
namespace CC.Yi.Common
{
public class EmailHelper
{
public static bool sendMail(string subject, string body, string toMail)
{
try
{
string fromMail = "454313500@qq.com";
string pwdMail = "yvjioburildgbhdf";
MailMessage message = new MailMessage();
//设置发件人,发件人需要与设置的邮件发送服务器的邮箱一致
System.Net.Mail.MailAddress fromAddr = new System.Net.Mail.MailAddress(fromMail, "江西服装学院论坛");
message.From = fromAddr;
//设置收件人,可添加多个,添加方法与下面的一样
message.To.Add(toMail);
//设置邮件标题
message.Subject = subject;
//设置邮件内容
message.Body = body;
//设置邮件发送服务器,服务器根据你使用的邮箱而不同,可以到相应的 邮箱管理后台查看,下面是QQ的
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.qq.com", 25)
;
//设置发送人的邮箱账号和密码POP3/SMTP服务要开启, 密码要是POP3/SMTP等服务的授权码
client.Credentials = new System.Net.NetworkCredential(fromMail, pwdMail);//vtirsfsthwuadjfe fhszmpegwoqnecja
//启用ssl,也就是安全发送
client.EnableSsl = true;
//发送邮件
client.Send(message);
return true;
}
catch
{
return false;
}
}
public static void ()
{
using (TcpClient client = new TcpClient("pop.qq.com", 110))
using (NetworkStream n = client.GetStream())
{
GetEmail.ReadLine(n); // Read the welcome message.
GetEmail.SendCommand(n, "USER 1040079213@qq.com");
GetEmail.SendCommand(n, "PASS odfaizoqdiupbfgi");
GetEmail.SendCommand(n, "LIST"); // Retrieve message IDs
List<int> messageIDs = new List<int>();
while (true)
{
string line = GetEmail.ReadLine(n); // e.g., "11876"
if (line == ".") break;
messageIDs.Add(int.Parse(line.Split(' ')[0])); // Message ID
}
foreach (int id in messageIDs) // Retrieve each message.
{
GetEmail.SendCommand(n, "RETR " + id);
string randomFile = Guid.NewGuid().ToString() + ".eml";
using (StreamWriter writer = File.CreateText(randomFile))
while (true)
{
string line = GetEmail.ReadLine(n); // Read next line of message.
if (line == ".") break; // Single dot = end of message.
if (line == "..") line = "."; // "Escape out" double dot.
writer.WriteLine(line); // Write to output file.
}
GetEmail.SendCommand(n, "DELE " + id); // Delete message off server.
}
GetEmail.SendCommand(n, "QUIT");
}
}
}
//接受邮件pop
public class GetEmail
{
public static void SendCommand(Stream stream, string line)
{
byte[] data = Encoding.UTF8.GetBytes(line + "\r\n");
stream.Write(data, 0, data.Length);
string response = ReadLine(stream);
if (!response.StartsWith("+OK"))
throw new Exception("POP Error: " + response);
}
public static string ReadLine(Stream s)
{
List<byte> lineBuffer = new List<byte>();
while (true)
{
int b = s.ReadByte();
if (b == 10 || b < 0) break;
if (b != 13) lineBuffer.Add((byte)b);
}
return Encoding.UTF8.GetString(lineBuffer.ToArray());
}
}
}

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace CC.Yi.Common.Json
{
public class DatetimeJsonConverter: JsonConverter<DateTime>
{
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.String)
{
if (DateTime.TryParse(reader.GetString(), out DateTime date))
return date;
}
return reader.GetDateTime();
}
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString("yyyy-MM-dd HH:mm:ss"));
}
}
}

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Json;
namespace CC.Yi.Common.Json
{
/// <summary>
/// https://blog.csdn.net/sD7O95O/article/details/103797885
/// </summary>
public class DefaultJsonOptions
{
public static JsonSerializerOptions Get()
{
var options = new JsonSerializerOptions();
//options.Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping;
options.IgnoreNullValues = true;//排除所有属性值为 null 属性
//// 自定义名称策略
//options.PropertyNamingPolicy = new LowerCaseNamingPolicy();
return options;
}
}
}

View File

@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace CC.Yi.Common.Json
{
public class EnumJsonConverter : JsonConverter<Enum>
{
public override bool CanConvert(Type typeToConvert)
{
return typeToConvert.IsEnum;
}
//未实现
public override Enum Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.Number)
{
int num;
reader.TryGetInt32(out num);
return (Enum)Enum.Parse(typeToConvert,num.ToString());
}
if (reader.TokenType == JsonTokenType.String)
{
string str = reader.GetString();
return (Enum)Enum.Parse(typeToConvert, str);
}
return null;
}
public override void Write(Utf8JsonWriter writer, Enum value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString());
}
}
}

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json;
namespace CC.Yi.Common.Json
{
/// <summary>
/// 自定义名称策略
/// </summary>
public class LowerCaseNamingPolicy : JsonNamingPolicy
{
public override string ConvertName(string name) => name.ToLower();
}
}

View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace CC.Yi.Common.Json
{
public class TimeSpanJsonConverter : JsonConverter<TimeSpan>
{
public override TimeSpan Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
//if (TimeSpan.TryParse(reader.GetString(), out TimeSpan date))
// return date;
TimeSpan.TryParse(reader.GetString(), out TimeSpan date);
return date;
}
public override void Write(Utf8JsonWriter writer, TimeSpan value, JsonSerializerOptions options)
{
// writer.WriteStringValue(value.ToString("HH:mm:ss"));
writer.WriteStringValue(value.ToString());
}
}
}

View File

@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace CC.Yi.Common
{
public static class LinqHelper
{
//T是列表类型S是排序的属性
public static IQueryable GetPageEntities<T,S>(IQueryable<T> myData, int pageSize, int pageIndex, out int total, Expression<Func<T, bool>> whereLambda=null, Expression<Func<T, S>> orderByLambda=null, bool isAsc=false)
{
total = myData.Where(whereLambda).Count();
if (isAsc)
{
var pageData = myData.Where(whereLambda)
.OrderBy<T,S>(orderByLambda)
.Skip(pageSize * (pageIndex - 1))
.Take(pageSize).AsQueryable();
return pageData;
}
else
{
var pageData = myData.Where(whereLambda)
.OrderByDescending<T, S>(orderByLambda)
.Skip(pageSize * (pageIndex - 1))
.Take(pageSize).AsQueryable();
return pageData;
}
}
}
}

View File

@@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace CC.Yi.Common
{
public class RandomHelper
{
public static string replaceBianLiang(string content)
{
content = content.Replace("{当前时间}", DateTime.Now.TimeOfDay.ToString());
string[] bianliang = new string[] { "{随机字母}", "{随机数字}", "{随机汉字}" };
Regex r;
int count;
string readstr = "";
foreach (string str in bianliang)
{
count = (content.Length - content.Replace(str, "").Length) / str.Length;
if (str == "{随机汉字}") readstr = RandChina(count);
if (str == "{随机数字}") readstr = GenerateCheckCodeNum(count);
if (str == "{随机字母}") readstr = GenerateRandomLetter(count);
if (count > readstr.Length) count = readstr.Length;
r = new Regex(str.Replace("{", "\\{").Replace("}", "\\}"));
for (int i = 0; i < count; i++)
{
content = r.Replace(content, readstr.Substring(i, 1), 1);
}
}
return content;
}
/// <summary>
/// 随机生成字母
/// </summary>
/// <param name="Length"></param>
/// <returns></returns>
public static string GenerateRandomLetter(int Length)
{
char[] Pattern = new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
string result = "";
int n = Pattern.Length;
Random random = new Random(~unchecked((int)DateTime.Now.Ticks));
for (int i = 0; i < Length; i++)
{
int rnd = random.Next(0, n);
result += Pattern[rnd];
}
return result;
}
/// <summary>
/// 随机生成数字
/// </summary>
/// <param name="codeCount"></param>
/// <returns></returns>
public static string GenerateCheckCodeNum(int codeCount)
{
int rep = 0;
string str = string.Empty;
long num2 = DateTime.Now.Ticks + rep;
rep++;
Random random = new Random(((int)(((ulong)num2) & 0xffffffffL)) | ((int)(num2 >> rep)));
for (int i = 0; i < codeCount; i++)
{
int num = random.Next();
str = str + ((char)(0x30 + ((ushort)(num % 10)))).ToString();
}
return str;
}
/// <summary>
/// 此函数为生成指定数目的汉字
/// </summary>
/// <param name="charLen">汉字数目</param>
/// <returns>所有汉字</returns>
public static string RandChina(int charLen)
{
int area, code;//汉字由区位和码位组成(都为0-94,其中区位16-55为一级汉字区,56-87为二级汉字区,1-9为特殊字符区)
StringBuilder strtem = new StringBuilder();
Random rand = new Random();
for (int i = 0; i < charLen; i++)
{
area = rand.Next(16, 88);
if (area == 55)//第55区只有89个字符
{
code = rand.Next(1, 90);
}
else
{
code = rand.Next(1, 94);
}
strtem.Append(Encoding.GetEncoding("GB2312").GetString(new byte[] { Convert.ToByte(area + 160), Convert.ToByte(code + 160) }));
}
return strtem.ToString();
}
}
}

View File

@@ -0,0 +1,58 @@
<#@ 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=".vue" #>
<#
string solutionsPath = Host.ResolveAssemblyReference("$(SolutionDir)");//获取解决方案路径
List<string> ModelData=new List<string>();
StreamReader sr = new StreamReader(solutionsPath+@"\T4Model\T4Vue.txt");
string p;
while((p =sr.ReadLine())!=null)
{
ModelData.Add(p);
}
sr.Close();
string Model= ModelData[0];
string BModel=Model.Substring(0,1).ToUpper()+Model.Substring(1);
string[] Data=ModelData[1].Split(',');
string[] Name=ModelData[2].Split(',');
string[] Default=ModelData[3].Split(',');
#>
/*
import myaxios from '@/utils/myaxios'
export default {
get<#=BModel#>s() {
return myaxios({
url: '/<#=BModel#>/get<#=BModel#>s',
method: 'get'
})
},
add<#=BModel#>(<#=Model#>) {
return myaxios({
url: '/<#=BModel#>/add<#=BModel#>',
method: 'post',
data: <#=Model#>
})
},
update<#=BModel#>(<#=BModel#>) {
return myaxios({
url: '/<#=BModel#>/Update<#=BModel#>',
method: 'post',
data: <#=BModel#>
})
},
del<#=BModel#>List(Ids) {
return myaxios({
url: '/<#=BModel#>/Del<#=BModel#>List',
method: 'post',
data: Ids
})
},
}
*/

View File

@@ -0,0 +1,35 @@

/*
import myaxios from '@/utils/myaxios'
export default {
getStudents() {
return myaxios({
url: '/Student/getStudents',
method: 'get'
})
},
addStudent(student) {
return myaxios({
url: '/Student/addStudent',
method: 'post',
data: student
})
},
updateStudent(Student) {
return myaxios({
url: '/Student/UpdateStudent',
method: 'post',
data: Student
})
},
delStudentList(Ids) {
return myaxios({
url: '/Student/DelStudentList',
method: 'post',
data: Ids
})
},
}
*/

View File

@@ -0,0 +1,279 @@
<#@ 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=".vue" #>
<#
string solutionsPath = Host.ResolveAssemblyReference("$(SolutionDir)");//获取解决方案路径
List<string> ModelData=new List<string>();
StreamReader sr = new StreamReader(solutionsPath+@"\T4Model\T4Vue.txt");
string p;
while((p =sr.ReadLine())!=null)
{
ModelData.Add(p);
}
sr.Close();
string Model= ModelData[0];
string BModel=Model.Substring(0,1).ToUpper()+Model.Substring(1);
string[] Data=ModelData[1].Split(',');
string[] Name=ModelData[2].Split(',');
string[] Default=ModelData[3].Split(',');
#>
/*
<template>
<v-card>
<v-data-table
:headers="headers"
:items="desserts"
sort-by="calories"
class="elevation-1"
item-key="id"
show-select
v-model="selected"
:search="search"
>
<template v-slot:top>
<!-- 搜索框 -->
<v-toolbar flat>
<v-spacer></v-spacer>
<v-text-field
v-model="search"
append-icon="mdi-magnify"
label="搜索"
single-line
hide-details
class="mx-4"
></v-text-field>
<!-- 添加提示框 -->
<v-dialog v-model="dialog" max-width="500px">
<template v-slot:activator="{ on, attrs }">
<v-btn
color="primary"
dark
class="mb-2 mx-2"
v-bind="attrs"
v-on="on"
>
添加新项
</v-btn>
</template>
<v-card>
<v-card-title>
<span class="headline">{{ formTitle }}</span>
</v-card-title>
<v-card-text>
<v-container>
<!-- 【1】这里设置对应的编辑框名 -->
<v-row>
<#
for(int i=0;i<Data.Length;i++)
{
#>
<v-col cols="12" sm="6" md="4">
<v-text-field
v-model="editedItem.<#=Data[i]#>"
label="<#=Name[i]#>"
></v-text-field>
</v-col>
<#
}
#>
</v-row>
</v-container>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="blue darken-1" text @click="close"> 取消 </v-btn>
<v-btn color="blue darken-1" text @click="save"> 保存 </v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<v-btn color="red" dark class="mb-2" @click="deleteItem(null)">
删除所选
</v-btn>
<!-- 删除提示框 -->
<v-dialog v-model="dialogDelete" max-width="500px">
<v-card>
<v-card-title class="headline"
>你确定要删除此条记录吗?</v-card-title
>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="blue darken-1" text @click="closeDelete"
>取消</v-btn
>
<v-btn color="blue darken-1" text @click="deleteItemConfirm"
>确定</v-btn
>
<v-spacer></v-spacer>
</v-card-actions>
</v-card>
</v-dialog>
</v-toolbar>
</template>
<!-- 表格中的删除和修改 -->
<template v-slot:item.actions="{ item }">
<v-icon small class="mr-2" @click="editItem(item)"> mdi-pencil </v-icon>
<v-icon small @click="deleteItem(item)"> mdi-delete </v-icon>
</template>
<!-- 初始化 -->
<template v-slot:no-data>
<v-btn color="primary" @click="initialize"> 刷新 </v-btn>
</template>
</v-data-table>
</v-card>
</template>
<script>
//【2】这里设置对应的API
import <#=Model#>Api from "@/api/<#=Model#>Api";
export default {
data: () => ({
page: 1,
selected: [],
search: "",
dialog: false,
dialogDelete: false,
//【3】这里设置对应的模型字段
headers: [
{
text: "编号",
align: "start",
value: "id",
},
<#
for(int i=0;i<Data.Length;i++)
{
#>
{ text: "<#=Name[i]#>", value: "<#=Data[i]#>", sortable: false },
<#
}
#>
{ text: "操作", value: "actions", sortable: false },
],
desserts: [],
editedIndex: -1,
//【4】这里设置对应的模型默认字段
editedItem: {
<#
for(int i=0;i<Data.Length;i++)
{
#>
<#=Data[i]#>: <#=Default[i]#>,
<#
}
#>
},
defaultItem: {
<#
for(int i=0;i<Data.Length;i++)
{
#>
<#=Data[i]#>: <#=Default[i]#>,
<#
}
#>
},
}),
computed: {
formTitle() {
return this.editedIndex === -1 ? "添加数据" : "编辑数据";
},
},
watch: {
dialog(val) {
val || this.close();
},
dialogDelete(val) {
val || this.closeDelete();
},
},
created() {
this.initialize();
},
methods: {
initialize() {
//【5】这里获取全部字段的API
<#=Model#>Api.get<#=BModel#>s().then((resp) => {
const response = resp.data;
this.desserts = response;
});
},
editItem(item) {
this.editedIndex = this.desserts.indexOf(item);
this.editedItem = Object.assign({}, item);
this.dialog = true;
},
deleteItem(item) {
this.editedIndex = this.desserts.indexOf(item);
this.editedItem = Object.assign({}, item);
this.dialogDelete = true;
},
deleteItemConfirm() {
var Ids = [];
if (this.editedIndex > -1) {
Ids.push(this.editedItem.id);
} else {
this.selected.forEach(function (item) {
Ids.push(item.id);
});
}
//【6】这里多条删除的API
<#=Model#>Api.del<#=BModel#>List(Ids).then(() => this.initialize());
this.closeDelete();
},
close() {
this.dialog = false;
this.$nextTick(() => {
this.editedItem = Object.assign({}, this.defaultItem);
this.editedIndex = -1;
});
},
closeDelete() {
this.dialogDelete = false;
this.$nextTick(() => {
this.editedItem = Object.assign({}, this.defaultItem);
this.editedIndex = -1;
});
},
save() {
//【7】这里编辑和添加的API
if (this.editedIndex > -1) {
<#=Model#>Api.update<#=BModel#>(this.editedItem).then(() => this.initialize());
} else {
<#=Model#>Api.add<#=BModel#>(this.editedItem).then(() => this.initialize());
}
this.close();
},
},
};
</script>
*/

View File

@@ -0,0 +1,237 @@

/*
<template>
<v-card>
<v-data-table
:headers="headers"
:items="desserts"
sort-by="calories"
class="elevation-1"
item-key="id"
show-select
v-model="selected"
:search="search"
>
<template v-slot:top>
<!-- 搜索框 -->
<v-toolbar flat>
<v-spacer></v-spacer>
<v-text-field
v-model="search"
append-icon="mdi-magnify"
label="搜索"
single-line
hide-details
class="mx-4"
></v-text-field>
<!-- 添加提示框 -->
<v-dialog v-model="dialog" max-width="500px">
<template v-slot:activator="{ on, attrs }">
<v-btn
color="primary"
dark
class="mb-2 mx-2"
v-bind="attrs"
v-on="on"
>
添加新项
</v-btn>
</template>
<v-card>
<v-card-title>
<span class="headline">{{ formTitle }}</span>
</v-card-title>
<v-card-text>
<v-container>
<!-- 【1】这里设置对应的编辑框名 -->
<v-row>
<v-col cols="12" sm="6" md="4">
<v-text-field
v-model="editedItem.id"
label="id"
></v-text-field>
</v-col>
<v-col cols="12" sm="6" md="4">
<v-text-field
v-model="editedItem.name"
label="姓名"
></v-text-field>
</v-col>
</v-row>
</v-container>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="blue darken-1" text @click="close"> 取消 </v-btn>
<v-btn color="blue darken-1" text @click="save"> 保存 </v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<v-btn color="red" dark class="mb-2" @click="deleteItem(null)">
删除所选
</v-btn>
<!-- 删除提示框 -->
<v-dialog v-model="dialogDelete" max-width="500px">
<v-card>
<v-card-title class="headline"
>你确定要删除此条记录吗?</v-card-title
>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="blue darken-1" text @click="closeDelete"
>取消</v-btn
>
<v-btn color="blue darken-1" text @click="deleteItemConfirm"
>确定</v-btn
>
<v-spacer></v-spacer>
</v-card-actions>
</v-card>
</v-dialog>
</v-toolbar>
</template>
<!-- 表格中的删除和修改 -->
<template v-slot:item.actions="{ item }">
<v-icon small class="mr-2" @click="editItem(item)"> mdi-pencil </v-icon>
<v-icon small @click="deleteItem(item)"> mdi-delete </v-icon>
</template>
<!-- 初始化 -->
<template v-slot:no-data>
<v-btn color="primary" @click="initialize"> 刷新 </v-btn>
</template>
</v-data-table>
</v-card>
</template>
<script>
//【2】这里设置对应的API
import studentApi from "@/api/studentApi";
export default {
data: () => ({
page: 1,
selected: [],
search: "",
dialog: false,
dialogDelete: false,
//【3】这里设置对应的模型字段
headers: [
{
text: "编号",
align: "start",
value: "id",
},
{ text: "id", value: "id", sortable: false },
{ text: "姓名", value: "name", sortable: false },
{ text: "操作", value: "actions", sortable: false },
],
desserts: [],
editedIndex: -1,
//【4】这里设置对应的模型默认字段
editedItem: {
id: "0",
name: "张三",
},
defaultItem: {
id: "0",
name: "张三",
},
}),
computed: {
formTitle() {
return this.editedIndex === -1 ? "添加数据" : "编辑数据";
},
},
watch: {
dialog(val) {
val || this.close();
},
dialogDelete(val) {
val || this.closeDelete();
},
},
created() {
this.initialize();
},
methods: {
initialize() {
//【5】这里获取全部字段的API
studentApi.getStudents().then((resp) => {
const response = resp.data;
this.desserts = response;
});
},
editItem(item) {
this.editedIndex = this.desserts.indexOf(item);
this.editedItem = Object.assign({}, item);
this.dialog = true;
},
deleteItem(item) {
this.editedIndex = this.desserts.indexOf(item);
this.editedItem = Object.assign({}, item);
this.dialogDelete = true;
},
deleteItemConfirm() {
var Ids = [];
if (this.editedIndex > -1) {
Ids.push(this.editedItem.id);
} else {
this.selected.forEach(function (item) {
Ids.push(item.id);
});
}
//【6】这里多条删除的API
studentApi.delStudentList(Ids).then(() => this.initialize());
this.closeDelete();
},
close() {
this.dialog = false;
this.$nextTick(() => {
this.editedItem = Object.assign({}, this.defaultItem);
this.editedIndex = -1;
});
},
closeDelete() {
this.dialogDelete = false;
this.$nextTick(() => {
this.editedItem = Object.assign({}, this.defaultItem);
this.editedIndex = -1;
});
},
save() {
//【7】这里编辑和添加的API
if (this.editedIndex > -1) {
studentApi.updateStudent(this.editedItem).then(() => this.initialize());
} else {
studentApi.addStudent(this.editedItem).then(() => this.initialize());
}
this.close();
},
},
};
</script>
*/

View File

@@ -0,0 +1,59 @@
//using CC.Yi.Common;
//using CC.Yi.IBLL;
//using CC.Yi.Model;
//using Microsoft.AspNetCore.Authorization;
//using Microsoft.AspNetCore.Mvc;
//using Microsoft.EntityFrameworkCore;
//using Microsoft.Extensions.Logging;
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Threading.Tasks;
//namespace CC.Yi.API.Controllers
//{
// [Route("[controller]/[action]")]
// [ApiController]
// public class PlateController : Controller
// {
// private IplateBll _plateBll;
// private ILogger<PlateController> _logger;
// short delFlagNormal = (short)ViewModel.Enum.DelFlagEnum.Normal;
// public PlateController(IplateBll plateBll, ILogger<PlateController> logger)
// {
// _plateBll = plateBll;
// _logger = logger;
// }
// [HttpGet]
// public async Task<Result> GetPlates()
// {
// var data =await _plateBll.GetEntities(u=>u.is_delete==delFlagNormal).AsNoTracking().ToListAsync();
// return Result.Success().SetData(data);
// }
// [Authorize(Policy = "板块管理")]
// [HttpPost]
// public Result AddPlate(plate myPlate)
// {
// _plateBll.Add(myPlate);
// return Result.Success();
// }
// [Authorize(Policy = "板块管理")]
// [HttpPost]
// public Result UpdatePlate(plate myPlate)
// {
// _plateBll.Update(myPlate);
// return Result.Success();
// }
// [Authorize(Policy = "板块管理")]
// [HttpPost]
// public Result delPlateList(List<int> Ids)
// {
// _plateBll.DelListByUpdateList(Ids);
// return Result.Success();
// }
// }
//}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CC.Yi.Common.mongodb.model
{
public class student
{
public string sname { get; set; }
public string sex { get; set; }
}
}

View File

@@ -0,0 +1,29 @@
using CC.Yi.Common.mongodb.model;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Text;
namespace CC.Yi.Common.mongodb
{
public class mongodbContext
{
private readonly IMongoDatabase _database = null;
public mongodbContext()
{
//连接服务器名称 mongo的默认端口27017
var client = new MongoClient("mongodb://.......:27017");
if (client != null)
//连接数据库
_database = client.GetDatabase("数据库名");
}
public IMongoCollection<student> Province
{
get
{
return _database.GetCollection<student>("Province");
}
}
}
}

View File

@@ -0,0 +1,48 @@
using CC.Yi.Common.Cache;
using System;
using System.Collections.Generic;
using System.Text;
namespace CC.Yi.Common
{
public static class settingHelper
{
public static ICacheWriter CacheWriter { get; set; }
static settingHelper()
{
settingHelper.CacheWriter = new RedisCache();
}
public static int commentPage()
{
return CacheWriter.GetCache<int>("commentPage");
}
public static int discussPage()
{
return CacheWriter.GetCache<int>("discussPage");
}
public static int commentExperience()
{
return CacheWriter.GetCache<int>("commentExperience");
}
public static int discussExperience()
{
return CacheWriter.GetCache<int>("discussExperience");
}
public static string title()
{
return CacheWriter.GetCache<string>("title");
}
//配置设置
//public static void update(setting data)
//{
// CacheWriter.SetCache<int>("commentPage", data.commentPage);
// CacheWriter.SetCache<int>("discussPage", data.discussPage);
// CacheWriter.SetCache<int>("commentExperience", data.commentExperience);
// CacheWriter.SetCache<int>("discussExperience", data.discussExperience);
// CacheWriter.SetCache<string>("title", data.title);
//}
}
}

View File

@@ -6,6 +6,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
namespace CC.Yi.DAL
{
@@ -16,8 +17,15 @@ namespace CC.Yi.DAL
{
Db = _Db;
}
public async Task<T> GetEntityById(int id)
{
return await Db.Set<T>().FindAsync(id);
}
public IQueryable<T> GetEntities(Expression<Func<T, bool>> whereLambda)
{
return Db.Set<T>().Where(whereLambda).AsQueryable();
}

View File

@@ -14,11 +14,4 @@ namespace CC.Yi.DAL
Db = _Db;
}
}
public partial class propDal : BaseDal<prop>, IpropDal
{
public propDal(DataContext _Db):base(_Db)
{
Db = _Db;
}
}
}

View File

@@ -3,11 +3,17 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
namespace CC.Yi.IBLL
{
public interface IBaseBll<T> where T : class, new()
{
#region
//通过id得到实体
#endregion
Task<T> GetEntityById(int id);
#region
//得到全部实体
#endregion

View File

@@ -2,13 +2,12 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace CC.Yi.IBLL
{
public partial interface IstudentBll : IBaseBll<student>
{
}
public partial interface IpropBll : IBaseBll<prop>
{
Task<bool> DelListByUpdateList(List<int> Ids);
}
}

View File

@@ -17,6 +17,7 @@ using CC.Yi.Model;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace CC.Yi.IBLL
{
@@ -24,6 +25,7 @@ namespace CC.Yi.IBLL
#>
public partial interface I<#=k #>Bll : IBaseBll<<#=k #>>
{
Task<bool> DelListByUpdateList(List<int> Ids);
}
<# } #>
}

View File

@@ -2,11 +2,17 @@
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
namespace CC.Yi.IDAL
{
public interface IBaseDal<T> where T : class, new()
{
#region
//通过Id得到实体
#endregion
Task<T> GetEntityById(int id);
#region
//得到全部实体
#endregion

View File

@@ -8,7 +8,4 @@ namespace CC.Yi.IDAL
public partial interface IstudentDal:IBaseDal<student>
{
}
public partial interface IpropDal:IBaseDal<prop>
{
}
}

View File

@@ -7,10 +7,9 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.6" />
<PackageReference Include="Oracle.EntityFrameworkCore" Version="5.21.1" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="5.0.0" />
</ItemGroup>
<ItemGroup>

View File

@@ -5,17 +5,17 @@ using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace CC.Yi.API.Migrations
namespace CC.Yi.Model.Migrations
{
[DbContext(typeof(DataContext))]
[Migration("20210413063257_y1")]
partial class y1
[Migration("20210602114758_yi1")]
partial class yi1
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "5.0.5");
.HasAnnotation("ProductVersion", "5.0.6");
modelBuilder.Entity("CC.Yi.Model.student", b =>
{

View File

@@ -1,8 +1,8 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace CC.Yi.API.Migrations
namespace CC.Yi.Model.Migrations
{
public partial class y1 : Migration
public partial class yi1 : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{

View File

@@ -0,0 +1,39 @@
// <auto-generated />
using CC.Yi.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace CC.Yi.Model.Migrations
{
[DbContext(typeof(DataContext))]
[Migration("20210602115718_yi2")]
partial class yi2
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "5.0.6");
modelBuilder.Entity("CC.Yi.Model.student", b =>
{
b.Property<int>("id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("is_delete")
.HasColumnType("INTEGER");
b.Property<string>("name")
.HasColumnType("TEXT");
b.HasKey("id");
b.ToTable("student");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,24 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace CC.Yi.Model.Migrations
{
public partial class yi2 : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "is_delete",
table: "student",
type: "INTEGER",
nullable: false,
defaultValue: 0);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "is_delete",
table: "student");
}
}
}

View File

@@ -0,0 +1,37 @@
// <auto-generated />
using CC.Yi.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace CC.Yi.Model.Migrations
{
[DbContext(typeof(DataContext))]
partial class DataContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "5.0.6");
modelBuilder.Entity("CC.Yi.Model.student", b =>
{
b.Property<int>("id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("is_delete")
.HasColumnType("INTEGER");
b.Property<string>("name")
.HasColumnType("TEXT");
b.HasKey("id");
b.ToTable("student");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -7,6 +7,5 @@ namespace CC.Yi.Model
public partial class DataContext :DbContext
{
public DbSet<student> student { get; set; }
public DbSet<prop> prop { get; set; }
}
}

View File

@@ -6,12 +6,11 @@ using System.Text;
namespace CC.Yi.Model
{
public class prop
public class baseModel
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int id { get; set; }
public string name { get; set; }
public student student { get; set; }
public int is_delete { get; set; }
}
}

View File

@@ -6,12 +6,8 @@ using System.Text;
namespace CC.Yi.Model
{
public class student
public class student:baseModel
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int id { get; set; }
public string name { get; set; }
public List<prop> props { get; set; }
}
}

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CC.Yi.ViewModel.Enum
{
public enum DelFlagEnum
{
Normal=0,
Deleted=1
}
}

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CC.Yi.ViewModel
{
public class setByIds
{
public int id { get; set; }
public List<int> ids { get; set; }
}
}

View File

@@ -1 +1 @@
student,prop
student

4
CC.Yi/T4Model/T4Vue.txt Normal file
View File

@@ -0,0 +1,4 @@
student
id,name
id,姓名
"0","张三"