diff --git a/.idea/.idea.Bunny.WebApi/.idea/GitCommitMessageStorage.xml b/.idea/.idea.Bunny.WebApi/.idea/GitCommitMessageStorage.xml
index e4fd56a..3b56900 100644
--- a/.idea/.idea.Bunny.WebApi/.idea/GitCommitMessageStorage.xml
+++ b/.idea/.idea.Bunny.WebApi/.idea/GitCommitMessageStorage.xml
@@ -2,7 +2,19 @@
\ No newline at end of file
diff --git a/.vs/Bunny.WebApi/DesignTimeBuild/.dtbcache.v2 b/.vs/Bunny.WebApi/DesignTimeBuild/.dtbcache.v2
new file mode 100644
index 0000000..ca5892c
Binary files /dev/null and b/.vs/Bunny.WebApi/DesignTimeBuild/.dtbcache.v2 differ
diff --git a/.vs/Bunny.WebApi/FileContentIndex/db59c62f-ee05-4d14-90fe-e338af5dcbdb.vsidx b/.vs/Bunny.WebApi/FileContentIndex/db59c62f-ee05-4d14-90fe-e338af5dcbdb.vsidx
new file mode 100644
index 0000000..cb9361d
Binary files /dev/null and b/.vs/Bunny.WebApi/FileContentIndex/db59c62f-ee05-4d14-90fe-e338af5dcbdb.vsidx differ
diff --git a/.vs/Bunny.WebApi/v17/.futdcache.v2 b/.vs/Bunny.WebApi/v17/.futdcache.v2
new file mode 100644
index 0000000..68ec319
Binary files /dev/null and b/.vs/Bunny.WebApi/v17/.futdcache.v2 differ
diff --git a/.vs/Bunny.WebApi/v17/.suo b/.vs/Bunny.WebApi/v17/.suo
new file mode 100644
index 0000000..52055a6
Binary files /dev/null and b/.vs/Bunny.WebApi/v17/.suo differ
diff --git a/.vs/Bunny.WebApi/v17/DocumentLayout.json b/.vs/Bunny.WebApi/v17/DocumentLayout.json
new file mode 100644
index 0000000..376dcbf
--- /dev/null
+++ b/.vs/Bunny.WebApi/v17/DocumentLayout.json
@@ -0,0 +1,92 @@
+{
+ "Version": 1,
+ "WorkspaceRootPath": "D:\\MyFolder\\Bunny\\Bunny-cli\\CSharp\\CSharp-Single-EFCore\\",
+ "Documents": [
+ {
+ "AbsoluteMoniker": "D:0:0:{28753039-0C3B-4FE5-95F8-7EDC92DCBA26}|Bunny.WebApi\\Bunny.WebApi.csproj|d:\\myfolder\\bunny\\bunny-cli\\csharp\\csharp-single-efcore\\bunny.webapi\\config\\baseconfig.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
+ "RelativeMoniker": "D:0:0:{28753039-0C3B-4FE5-95F8-7EDC92DCBA26}|Bunny.WebApi\\Bunny.WebApi.csproj|solutionrelative:bunny.webapi\\config\\baseconfig.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
+ },
+ {
+ "AbsoluteMoniker": "D:0:0:{28753039-0C3B-4FE5-95F8-7EDC92DCBA26}|Bunny.WebApi\\Bunny.WebApi.csproj|d:\\myfolder\\bunny\\bunny-cli\\csharp\\csharp-single-efcore\\bunny.webapi\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
+ "RelativeMoniker": "D:0:0:{28753039-0C3B-4FE5-95F8-7EDC92DCBA26}|Bunny.WebApi\\Bunny.WebApi.csproj|solutionrelative:bunny.webapi\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
+ },
+ {
+ "AbsoluteMoniker": "D:0:0:{28753039-0C3B-4FE5-95F8-7EDC92DCBA26}|Bunny.WebApi\\Bunny.WebApi.csproj|d:\\myfolder\\bunny\\bunny-cli\\csharp\\csharp-single-efcore\\bunny.webapi\\config\\serviceregistration.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
+ "RelativeMoniker": "D:0:0:{28753039-0C3B-4FE5-95F8-7EDC92DCBA26}|Bunny.WebApi\\Bunny.WebApi.csproj|solutionrelative:bunny.webapi\\config\\serviceregistration.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
+ },
+ {
+ "AbsoluteMoniker": "D:0:0:{28753039-0C3B-4FE5-95F8-7EDC92DCBA26}|Bunny.WebApi\\Bunny.WebApi.csproj|d:\\myfolder\\bunny\\bunny-cli\\csharp\\csharp-single-efcore\\bunny.webapi\\config\\knife4net.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
+ "RelativeMoniker": "D:0:0:{28753039-0C3B-4FE5-95F8-7EDC92DCBA26}|Bunny.WebApi\\Bunny.WebApi.csproj|solutionrelative:bunny.webapi\\config\\knife4net.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
+ }
+ ],
+ "DocumentGroupContainers": [
+ {
+ "Orientation": 0,
+ "VerticalTabListWidth": 256,
+ "DocumentGroups": [
+ {
+ "DockedWidth": 200,
+ "SelectedChildIndex": 4,
+ "Children": [
+ {
+ "$type": "Bookmark",
+ "Name": "ST:0:0:{1c4feeaa-4718-4aa9-859d-94ce25d182ba}"
+ },
+ {
+ "$type": "Document",
+ "DocumentIndex": 1,
+ "Title": "Program.cs",
+ "DocumentMoniker": "D:\\MyFolder\\Bunny\\Bunny-cli\\CSharp\\CSharp-Single-EFCore\\Bunny.WebApi\\Program.cs",
+ "RelativeDocumentMoniker": "Bunny.WebApi\\Program.cs",
+ "ToolTip": "D:\\MyFolder\\Bunny\\Bunny-cli\\CSharp\\CSharp-Single-EFCore\\Bunny.WebApi\\Program.cs",
+ "RelativeToolTip": "Bunny.WebApi\\Program.cs",
+ "ViewState": "AQIAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
+ "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
+ "WhenOpened": "2024-09-02T00:54:57.227Z",
+ "EditorCaption": ""
+ },
+ {
+ "$type": "Document",
+ "DocumentIndex": 2,
+ "Title": "ServiceRegistration.cs",
+ "DocumentMoniker": "D:\\MyFolder\\Bunny\\Bunny-cli\\CSharp\\CSharp-Single-EFCore\\Bunny.WebApi\\Config\\ServiceRegistration.cs",
+ "RelativeDocumentMoniker": "Bunny.WebApi\\Config\\ServiceRegistration.cs",
+ "ToolTip": "D:\\MyFolder\\Bunny\\Bunny-cli\\CSharp\\CSharp-Single-EFCore\\Bunny.WebApi\\Config\\ServiceRegistration.cs",
+ "RelativeToolTip": "Bunny.WebApi\\Config\\ServiceRegistration.cs",
+ "ViewState": "AQIAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
+ "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
+ "WhenOpened": "2024-09-02T00:54:44.07Z",
+ "EditorCaption": ""
+ },
+ {
+ "$type": "Document",
+ "DocumentIndex": 3,
+ "Title": "Knife4Net.cs",
+ "DocumentMoniker": "D:\\MyFolder\\Bunny\\Bunny-cli\\CSharp\\CSharp-Single-EFCore\\Bunny.WebApi\\Config\\Knife4Net.cs",
+ "RelativeDocumentMoniker": "Bunny.WebApi\\Config\\Knife4Net.cs",
+ "ToolTip": "D:\\MyFolder\\Bunny\\Bunny-cli\\CSharp\\CSharp-Single-EFCore\\Bunny.WebApi\\Config\\Knife4Net.cs",
+ "RelativeToolTip": "Bunny.WebApi\\Config\\Knife4Net.cs",
+ "ViewState": "AQIAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
+ "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
+ "WhenOpened": "2024-09-02T00:54:28.202Z",
+ "EditorCaption": ""
+ },
+ {
+ "$type": "Document",
+ "DocumentIndex": 0,
+ "Title": "BaseConfig.cs",
+ "DocumentMoniker": "D:\\MyFolder\\Bunny\\Bunny-cli\\CSharp\\CSharp-Single-EFCore\\Bunny.WebApi\\Config\\BaseConfig.cs",
+ "RelativeDocumentMoniker": "Bunny.WebApi\\Config\\BaseConfig.cs",
+ "ToolTip": "D:\\MyFolder\\Bunny\\Bunny-cli\\CSharp\\CSharp-Single-EFCore\\Bunny.WebApi\\Config\\BaseConfig.cs",
+ "RelativeToolTip": "Bunny.WebApi\\Config\\BaseConfig.cs",
+ "ViewState": "AQIAABAAAAAAAAAAAAAowBwAAAARAAAA",
+ "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
+ "WhenOpened": "2024-09-02T00:54:22.184Z",
+ "EditorCaption": ""
+ }
+ ]
+ }
+ ]
+ }
+ ]
+}
\ No newline at end of file
diff --git a/.vs/ProjectEvaluation/bunny.webapi.metadata.v8.bin b/.vs/ProjectEvaluation/bunny.webapi.metadata.v8.bin
new file mode 100644
index 0000000..529ed14
Binary files /dev/null and b/.vs/ProjectEvaluation/bunny.webapi.metadata.v8.bin differ
diff --git a/.vs/ProjectEvaluation/bunny.webapi.projects.v8.bin b/.vs/ProjectEvaluation/bunny.webapi.projects.v8.bin
new file mode 100644
index 0000000..a9ff1f6
Binary files /dev/null and b/.vs/ProjectEvaluation/bunny.webapi.projects.v8.bin differ
diff --git a/.vs/ProjectEvaluation/bunny.webapi.strings.v8.bin b/.vs/ProjectEvaluation/bunny.webapi.strings.v8.bin
new file mode 100644
index 0000000..f916064
Binary files /dev/null and b/.vs/ProjectEvaluation/bunny.webapi.strings.v8.bin differ
diff --git a/Bunny.Common/AppSettings.cs b/Bunny.Common/AppSettings.cs
index ccacc50..6511662 100644
--- a/Bunny.Common/AppSettings.cs
+++ b/Bunny.Common/AppSettings.cs
@@ -57,11 +57,10 @@ public class AppSettings
}
- public static T GetAppConfig(string key, T? defaultValue = default)
+ public static T? GetAppConfig(string key, T? defaultValue = default)
{
- var setting = (T)Convert.ChangeType(Configuration[key], typeof(T));
- var value = setting;
- return value;
+ return (T)Convert.ChangeType(Configuration[key], typeof(T))!;
+ ;
}
///
@@ -71,7 +70,7 @@ public class AppSettings
///
public static string GetConfig(string key)
{
- return Configuration[key];
+ return Configuration[key]!;
}
///
@@ -82,6 +81,6 @@ public class AppSettings
/// 节点类型实例
public static T Get(string key)
{
- return Configuration.GetSection(key).Get();
+ return Configuration.GetSection(key).Get()!;
}
}
\ No newline at end of file
diff --git a/Bunny.Common/Bunny.Common.csproj b/Bunny.Common/Bunny.Common.csproj
index 67a2885..40c23a0 100644
--- a/Bunny.Common/Bunny.Common.csproj
+++ b/Bunny.Common/Bunny.Common.csproj
@@ -10,14 +10,14 @@
-
- all
+
runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
-
-
- all
+
+
runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
diff --git a/Bunny.Common/Connect/EFCoreContext.cs b/Bunny.Common/Context/EFCoreContext.cs
similarity index 55%
rename from Bunny.Common/Connect/EFCoreContext.cs
rename to Bunny.Common/Context/EFCoreContext.cs
index 57652cb..406290b 100644
--- a/Bunny.Common/Connect/EFCoreContext.cs
+++ b/Bunny.Common/Context/EFCoreContext.cs
@@ -1,31 +1,45 @@
-using Bunny.Common.Context;
+using Bunny.Common.Interceptor;
using Bunny.Dao.Entity.Base;
using Bunny.Dao.Entity.System;
using Microsoft.EntityFrameworkCore;
-namespace Bunny.Common.Connect;
+namespace Bunny.Common.Context;
+///
+/// EfCore 连接内容
+/// dotnet tool install --global dotnet-ef
+/// dotnet add package Microsoft.EntityFrameworkCore.Design
+/// dotnet ef migrations add InitialCreate
+/// dotnet ef database update
+///
public class EfCoreContext : DbContext
{
public EfCoreContext()
{
- // DbPath = @"D:\MyFolder\Bunny\Bunny-cli\Template\CSharp\CSharp-Single-EFCore\Bunny.WebApi\Database\bunny.db";
var dataBaseConnection = AppSettings.GetAppConfig("DataBase:DataBaseConnection");
- DbPath = dataBaseConnection;
+ // const string dataBaseConnection =
+ // "192.168.3.98;Initial Catalog=BunnyDemo;TrustServerCertificate=True;Persist Security Info=True;User ID=sa;Password=abc1234.";
+ DbPath = $"Data Source={dataBaseConnection}";
}
- public string DbPath { get; }
-
+ // 连接路径
+ private string DbPath { get; }
public DbSet Blogs { get; set; }
public DbSet Posts { get; set; }
public DbSet Products { get; set; }
public DbSet Users { get; set; }
+ ///
+ /// 配置数据库上下文选项,指定数据库连接字符串
+ ///
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
- options.UseSqlite($"Data Source={DbPath}");
+ options.UseSqlServer(DbPath).AddInterceptors(new TransactionInterceptor());
}
+ ///
+ /// 在创建模型时,为所有继承自BaseEntity的实体类型添加软删除查询过滤器
+ ///
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
@@ -35,24 +49,36 @@ public class EfCoreContext : DbContext
base.OnModelCreating(modelBuilder);
}
+ ///
+ /// 重写SaveChanges方法,在保存更改之前设置系统字段
+ ///
public override int SaveChanges()
{
SetSystemField();
return base.SaveChanges();
}
+ ///
+ /// 重写SaveChanges方法,在保存更改之前设置系统字段
+ ///
public override int SaveChanges(bool acceptAllChangesOnSuccess)
{
SetSystemField();
return base.SaveChanges(acceptAllChangesOnSuccess);
}
+ ///
+ /// 异步保存更改,设置系统字段
+ ///
public override Task SaveChangesAsync(CancellationToken cancellationToken = new())
{
SetSystemField();
return base.SaveChangesAsync(cancellationToken);
}
+ ///
+ /// 异步保存更改,设置系统字段
+ ///
public override Task SaveChangesAsync(bool acceptAllChangesOnSuccess,
CancellationToken cancellationToken = new())
{
@@ -67,31 +93,31 @@ public class EfCoreContext : DbContext
{
foreach (var item in ChangeTracker.Entries())
if (item.Entity is BaseEntity entity)
+ {
+ var userId = BaseContext.GetUserId();
switch (item.State)
{
// 添加操作
case EntityState.Added:
{
- if (entity.Id == string.Empty) entity.Id = Guid.NewGuid().ToString();
+ if (entity.Id == Guid.Empty) entity.Id = Guid.NewGuid();
entity.CreateTime = DateTime.Now;
entity.UpdateTime = DateTime.Now;
- entity.CreateUserId = BaseContext.GetUserId()!.Value;
- entity.UpdateUserId = BaseContext.GetUserId()!.Value;
+ // 判断用户Id是否为空
+ if (userId != null)
+ {
+ entity.CreateUserId = userId!.Value;
+ entity.UpdateUserId = userId!.Value;
+ }
+
break;
}
// 修改操作
case EntityState.Modified:
entity.UpdateTime = DateTime.Now;
- if (BaseContext.GetUserId() != null) entity.UpdateUserId = BaseContext.GetUserId()!.Value;
- break;
- case EntityState.Detached:
- break;
- case EntityState.Unchanged:
- break;
- case EntityState.Deleted:
- entity.UpdateTime = DateTime.Now;
- entity.UpdateUserId = BaseContext.GetUserId()!.Value;
+ if (userId != null) entity.UpdateUserId = userId!.Value;
break;
}
+ }
}
}
\ No newline at end of file
diff --git a/Bunny.Common/Context/JsonDateTimeConverter.cs b/Bunny.Common/Context/JsonDateTimeConverter.cs
new file mode 100644
index 0000000..8a7db46
--- /dev/null
+++ b/Bunny.Common/Context/JsonDateTimeConverter.cs
@@ -0,0 +1,35 @@
+using System.Text.Json;
+using System.Text.Json.Serialization;
+using Bunny.Dao.Model.Constant;
+
+namespace Bunny.Common.Context;
+
+///
+/// 自定义Json转换器,用于将DateTime类型转换为JSON格式
+///
+public class JsonDateTimeConverter : JsonConverter
+{
+ ///
+ /// 重写读取方法,将JSON数据转换为DateTime类型
+ ///
+ /// JSON读取器
+ /// 要转换的目标类型
+ /// JSON序列化选项
+ /// 转换后的DateTime对象
+ public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
+ {
+ return DateTime.TryParse(reader.GetString(), out var date) ? date : default;
+ }
+
+ ///
+ /// 重写写入方法,将DateTime对象转换为JSON格式并写入JSON写入器
+ ///
+ /// JSON写入器
+ /// 要写入的DateTime对象
+ /// JSON序列化选项
+ public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
+ {
+ // 将DateTime对象转换为特定格式的字符串并写入JSON写入器
+ writer.WriteStringValue(value.ToString(LocalDateTimeConstant.DefaultDateTimeSecondFormat));
+ }
+}
\ No newline at end of file
diff --git a/Bunny.Common/Connect/MinioContext.cs b/Bunny.Common/Context/MinioContext.cs
similarity index 95%
rename from Bunny.Common/Connect/MinioContext.cs
rename to Bunny.Common/Context/MinioContext.cs
index 19044bb..ab6b13b 100644
--- a/Bunny.Common/Connect/MinioContext.cs
+++ b/Bunny.Common/Context/MinioContext.cs
@@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Builder;
using Minio;
-namespace Bunny.Common.Connect;
+namespace Bunny.Common.Context;
public static class MinioContext
{
diff --git a/Bunny.Common/Connect/RedisContext.cs b/Bunny.Common/Context/RedisContext.cs
similarity index 97%
rename from Bunny.Common/Connect/RedisContext.cs
rename to Bunny.Common/Context/RedisContext.cs
index 8949c64..bf6d9e5 100644
--- a/Bunny.Common/Connect/RedisContext.cs
+++ b/Bunny.Common/Context/RedisContext.cs
@@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Builder;
using StackExchange.Redis;
-namespace Bunny.Common.Connect;
+namespace Bunny.Common.Context;
public static class RedisContext
{
diff --git a/Bunny.Common/Connect/SoftDeleteQueryExtension.cs b/Bunny.Common/Context/SoftDeleteQueryExtension.cs
similarity index 97%
rename from Bunny.Common/Connect/SoftDeleteQueryExtension.cs
rename to Bunny.Common/Context/SoftDeleteQueryExtension.cs
index b583b5c..5a8863a 100644
--- a/Bunny.Common/Connect/SoftDeleteQueryExtension.cs
+++ b/Bunny.Common/Context/SoftDeleteQueryExtension.cs
@@ -3,7 +3,7 @@ using System.Reflection;
using Bunny.Dao.Entity.Base;
using Microsoft.EntityFrameworkCore.Metadata;
-namespace Bunny.Common.Connect;
+namespace Bunny.Common.Context;
///
/// 软删除过滤器
diff --git a/Bunny.Common/Filter/GlobalExceptionFilter.cs b/Bunny.Common/Filter/GlobalExceptionFilter.cs
index 775b30a..b5b12c8 100644
--- a/Bunny.Common/Filter/GlobalExceptionFilter.cs
+++ b/Bunny.Common/Filter/GlobalExceptionFilter.cs
@@ -1,6 +1,6 @@
using Bunny.Common.Exception;
-using Bunny.Dao.Entity.Constant;
-using Bunny.Dao.Entity.Result;
+using Bunny.Dao.Model.Constant;
+using Bunny.Dao.Model.Result;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Logging;
diff --git a/Bunny.Common/Filter/ValidateModelStateAttribute.cs b/Bunny.Common/Filter/ValidateModelStateAttribute.cs
index a0852b9..59e3bd6 100644
--- a/Bunny.Common/Filter/ValidateModelStateAttribute.cs
+++ b/Bunny.Common/Filter/ValidateModelStateAttribute.cs
@@ -1,5 +1,5 @@
using System.Net;
-using Bunny.Dao.Entity.Result;
+using Bunny.Dao.Model.Result;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
@@ -14,8 +14,11 @@ public class ValidateModelStateAttribute : ActionFilterAttribute
{
if (actionContext.ModelState.IsValid) return;
- // 异常返回结果包装 也可以自定自定义返回类型
- var errorMessage = actionContext.ModelState.Values.First().Errors.First().ErrorMessage;
+ // 表单验证失败
+ var errorMessage = string.Join(",", actionContext.ModelState.Values
+ .SelectMany(value => value.Errors)
+ .Select(value => value.ErrorMessage));
+
var result = Result.Error(HttpStatusCode.BadRequest, errorMessage);
// 重新复写返回结果
diff --git a/Bunny.Common/Interceptor/TransactionInterceptor.cs b/Bunny.Common/Interceptor/TransactionInterceptor.cs
new file mode 100644
index 0000000..8bfbdb6
--- /dev/null
+++ b/Bunny.Common/Interceptor/TransactionInterceptor.cs
@@ -0,0 +1,30 @@
+using Bunny.Common.Exception;
+using Bunny.Dao.Model.Constant;
+using Microsoft.EntityFrameworkCore.Diagnostics;
+
+namespace Bunny.Common.Interceptor;
+
+public class TransactionInterceptor : SaveChangesInterceptor
+{
+ public override InterceptionResult SavingChanges(DbContextEventData eventData, InterceptionResult result)
+ {
+ if (eventData.Context!.Database.CurrentTransaction != null) return result;
+ using var transaction = eventData.Context.Database.BeginTransaction();
+ try
+ {
+ // 调用基类方法继续保存更改
+ result = base.SavingChanges(eventData, result);
+
+ // 如果保存更改成功,则提交事务
+ transaction.Commit();
+ }
+ catch (System.Exception)
+ {
+ // 如果保存更改失败,则回滚事务
+ transaction.Rollback();
+ throw new BunnyException(ExceptionConstant.DataBaseError);
+ }
+
+ return result;
+ }
+}
\ No newline at end of file
diff --git a/Bunny.Common/Migrations/20240809011221_InitialCreate.Designer.cs b/Bunny.Common/Migrations/20240809011221_InitialCreate.Designer.cs
deleted file mode 100644
index 1eba6a2..0000000
--- a/Bunny.Common/Migrations/20240809011221_InitialCreate.Designer.cs
+++ /dev/null
@@ -1,173 +0,0 @@
-//
-using System;
-using Bunny.Common.Connect;
-using Microsoft.EntityFrameworkCore;
-using Microsoft.EntityFrameworkCore.Infrastructure;
-using Microsoft.EntityFrameworkCore.Migrations;
-using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
-
-#nullable disable
-
-namespace Bunny.Common.Migrations
-{
- [DbContext(typeof(EfCoreContext))]
- [Migration("20240809011221_InitialCreate")]
- partial class InitialCreate
- {
- ///
- protected override void BuildTargetModel(ModelBuilder modelBuilder)
- {
-#pragma warning disable 612, 618
- modelBuilder.HasAnnotation("ProductVersion", "8.0.7");
-
- modelBuilder.Entity("Bunny.Dao.Models.System.Blog", b =>
- {
- b.Property("Id")
- .HasColumnType("TEXT");
-
- b.Property("CreateTime")
- .HasColumnType("TEXT");
-
- b.Property("CreateUserId")
- .HasColumnType("INTEGER");
-
- b.Property("UpdateTime")
- .HasColumnType("TEXT");
-
- b.Property("UpdateUserId")
- .HasColumnType("INTEGER");
-
- b.Property("Url")
- .IsRequired()
- .HasColumnType("TEXT");
-
- b.HasKey("Id");
-
- b.ToTable("Blogs");
- });
-
- modelBuilder.Entity("Bunny.Dao.Models.System.Post", b =>
- {
- b.Property("Id")
- .HasColumnType("TEXT");
-
- b.Property("BlogId")
- .HasColumnType("INTEGER");
-
- b.Property("BlogId1")
- .HasColumnType("TEXT");
-
- b.Property("Content")
- .HasColumnType("TEXT");
-
- b.Property("CreateTime")
- .HasColumnType("TEXT");
-
- b.Property("CreateUserId")
- .HasColumnType("INTEGER");
-
- b.Property("PostId")
- .HasColumnType("INTEGER");
-
- b.Property("Title")
- .HasColumnType("TEXT");
-
- b.Property("UpdateTime")
- .HasColumnType("TEXT");
-
- b.Property("UpdateUserId")
- .HasColumnType("INTEGER");
-
- b.HasKey("Id");
-
- b.HasIndex("BlogId1");
-
- b.ToTable("Posts");
- });
-
- modelBuilder.Entity("Bunny.Dao.Models.System.Product", b =>
- {
- b.Property("Id")
- .HasColumnType("TEXT");
-
- b.Property("CreateTime")
- .HasColumnType("TEXT");
-
- b.Property("CreateUserId")
- .HasColumnType("INTEGER");
-
- b.Property("CustomerId")
- .HasColumnType("TEXT");
-
- b.Property("CustomerName")
- .HasColumnType("TEXT");
-
- b.Property("PackageType")
- .HasColumnType("TEXT");
-
- b.Property("UpdateTime")
- .HasColumnType("TEXT");
-
- b.Property("UpdateUserId")
- .HasColumnType("INTEGER");
-
- b.HasKey("Id");
-
- b.ToTable("Products");
- });
-
- modelBuilder.Entity("Bunny.Dao.Models.System.User", b =>
- {
- b.Property("Id")
- .HasColumnType("TEXT");
-
- b.Property("CompanyCode")
- .HasColumnType("TEXT");
-
- b.Property("CreateTime")
- .HasColumnType("TEXT");
-
- b.Property("CreateUserId")
- .HasColumnType("INTEGER");
-
- b.Property("DeptCode")
- .HasColumnType("TEXT");
-
- b.Property("Email")
- .HasColumnType("TEXT");
-
- b.Property("Password")
- .HasColumnType("TEXT");
-
- b.Property("Phone")
- .HasColumnType("TEXT");
-
- b.Property("QrCode")
- .HasColumnType("TEXT");
-
- b.Property("UpdateTime")
- .HasColumnType("TEXT");
-
- b.Property("UpdateUserId")
- .HasColumnType("INTEGER");
-
- b.Property("UserName")
- .HasColumnType("TEXT");
-
- b.HasKey("Id");
-
- b.ToTable("Users");
- });
-
- modelBuilder.Entity("Bunny.Dao.Models.System.Post", b =>
- {
- b.HasOne("Bunny.Dao.Models.System.Blog", "Blog")
- .WithMany()
- .HasForeignKey("BlogId1");
-
- b.Navigation("Blog");
- });
-#pragma warning restore 612, 618
- }
- }
-}
diff --git a/Bunny.Common/Migrations/20240809011221_InitialCreate.cs b/Bunny.Common/Migrations/20240809011221_InitialCreate.cs
deleted file mode 100644
index 04f8424..0000000
--- a/Bunny.Common/Migrations/20240809011221_InitialCreate.cs
+++ /dev/null
@@ -1,117 +0,0 @@
-using System;
-using Microsoft.EntityFrameworkCore.Migrations;
-
-#nullable disable
-
-namespace Bunny.Common.Migrations
-{
- ///
- public partial class InitialCreate : Migration
- {
- ///
- protected override void Up(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.CreateTable(
- name: "Blogs",
- columns: table => new
- {
- Id = table.Column(type: "TEXT", nullable: false),
- Url = table.Column(type: "TEXT", nullable: false),
- CreateTime = table.Column(type: "TEXT", nullable: false),
- UpdateTime = table.Column(type: "TEXT", nullable: false),
- CreateUserId = table.Column(type: "INTEGER", nullable: false),
- UpdateUserId = table.Column(type: "INTEGER", nullable: false)
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_Blogs", x => x.Id);
- });
-
- migrationBuilder.CreateTable(
- name: "Products",
- columns: table => new
- {
- Id = table.Column(type: "TEXT", nullable: false),
- CustomerId = table.Column(type: "TEXT", nullable: true),
- CustomerName = table.Column(type: "TEXT", nullable: true),
- PackageType = table.Column(type: "TEXT", nullable: true),
- CreateTime = table.Column(type: "TEXT", nullable: false),
- UpdateTime = table.Column(type: "TEXT", nullable: false),
- CreateUserId = table.Column(type: "INTEGER", nullable: false),
- UpdateUserId = table.Column(type: "INTEGER", nullable: false)
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_Products", x => x.Id);
- });
-
- migrationBuilder.CreateTable(
- name: "Users",
- columns: table => new
- {
- Id = table.Column(type: "TEXT", nullable: false),
- UserName = table.Column(type: "TEXT", nullable: true),
- Password = table.Column(type: "TEXT", nullable: true),
- Email = table.Column(type: "TEXT", nullable: true),
- Phone = table.Column(type: "TEXT", nullable: true),
- QrCode = table.Column(type: "TEXT", nullable: true),
- CompanyCode = table.Column(type: "TEXT", nullable: true),
- DeptCode = table.Column(type: "TEXT", nullable: true),
- CreateTime = table.Column(type: "TEXT", nullable: false),
- UpdateTime = table.Column(type: "TEXT", nullable: false),
- CreateUserId = table.Column(type: "INTEGER", nullable: false),
- UpdateUserId = table.Column(type: "INTEGER", nullable: false)
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_Users", x => x.Id);
- });
-
- migrationBuilder.CreateTable(
- name: "Posts",
- columns: table => new
- {
- Id = table.Column(type: "TEXT", nullable: false),
- PostId = table.Column(type: "INTEGER", nullable: false),
- Title = table.Column(type: "TEXT", nullable: true),
- Content = table.Column(type: "TEXT", nullable: true),
- BlogId = table.Column(type: "INTEGER", nullable: false),
- BlogId1 = table.Column(type: "TEXT", nullable: true),
- CreateTime = table.Column(type: "TEXT", nullable: false),
- UpdateTime = table.Column(type: "TEXT", nullable: false),
- CreateUserId = table.Column(type: "INTEGER", nullable: false),
- UpdateUserId = table.Column(type: "INTEGER", nullable: false)
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_Posts", x => x.Id);
- table.ForeignKey(
- name: "FK_Posts_Blogs_BlogId1",
- column: x => x.BlogId1,
- principalTable: "Blogs",
- principalColumn: "Id");
- });
-
- migrationBuilder.CreateIndex(
- name: "IX_Posts_BlogId1",
- table: "Posts",
- column: "BlogId1");
- }
-
- ///
- protected override void Down(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.DropTable(
- name: "Posts");
-
- migrationBuilder.DropTable(
- name: "Products");
-
- migrationBuilder.DropTable(
- name: "Users");
-
- migrationBuilder.DropTable(
- name: "Blogs");
- }
- }
-}
diff --git a/Bunny.Common/Migrations/20240902054644_InitialCreate.Designer.cs b/Bunny.Common/Migrations/20240902054644_InitialCreate.Designer.cs
new file mode 100644
index 0000000..9e2b4af
--- /dev/null
+++ b/Bunny.Common/Migrations/20240902054644_InitialCreate.Designer.cs
@@ -0,0 +1,186 @@
+//
+using System;
+using Bunny.Common.Context;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace Bunny.Common.Migrations
+{
+ [DbContext(typeof(EfCoreContext))]
+ [Migration("20240902054644_InitialCreate")]
+ partial class InitialCreate
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "8.0.8")
+ .HasAnnotation("Relational:MaxIdentifierLength", 128);
+
+ SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
+
+ modelBuilder.Entity("Bunny.Dao.Entity.System.Blog", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("nvarchar(450)");
+
+ b.Property("CreateTime")
+ .HasColumnType("datetime2");
+
+ b.Property("CreateUserId")
+ .HasColumnType("bigint");
+
+ b.Property("IsDeleted")
+ .HasColumnType("bit");
+
+ b.Property("UpdateTime")
+ .HasColumnType("datetime2");
+
+ b.Property("UpdateUserId")
+ .HasColumnType("bigint");
+
+ b.Property("Url")
+ .IsRequired()
+ .HasColumnType("varchar(600)")
+ .HasColumnName("BlogUrl");
+
+ b.HasKey("Id");
+
+ b.ToTable("Blog");
+ });
+
+ modelBuilder.Entity("Bunny.Dao.Entity.System.Post", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("nvarchar(450)");
+
+ b.Property("BlogId")
+ .HasColumnType("nvarchar(450)");
+
+ b.Property("Content")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("CreateTime")
+ .HasColumnType("datetime2");
+
+ b.Property("CreateUserId")
+ .HasColumnType("bigint");
+
+ b.Property("IsDeleted")
+ .HasColumnType("bit");
+
+ b.Property("Title")
+ .HasMaxLength(600)
+ .HasColumnType("nvarchar(600)");
+
+ b.Property("UpdateTime")
+ .HasColumnType("datetime2");
+
+ b.Property("UpdateUserId")
+ .HasColumnType("bigint");
+
+ b.HasKey("Id");
+
+ b.HasIndex("BlogId");
+
+ b.ToTable("Posts");
+ });
+
+ modelBuilder.Entity("Bunny.Dao.Entity.System.Product", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("nvarchar(450)");
+
+ b.Property("CreateTime")
+ .HasColumnType("datetime2");
+
+ b.Property("CreateUserId")
+ .HasColumnType("bigint");
+
+ b.Property("CustomerId")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("CustomerName")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("IsDeleted")
+ .HasColumnType("bit");
+
+ b.Property("PackageType")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("UpdateTime")
+ .HasColumnType("datetime2");
+
+ b.Property("UpdateUserId")
+ .HasColumnType("bigint");
+
+ b.HasKey("Id");
+
+ b.ToTable("Products");
+ });
+
+ modelBuilder.Entity("Bunny.Dao.Entity.System.User", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("nvarchar(450)");
+
+ b.Property("CompanyCode")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("CreateTime")
+ .HasColumnType("datetime2");
+
+ b.Property("CreateUserId")
+ .HasColumnType("bigint");
+
+ b.Property("DeptCode")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Email")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("IsDeleted")
+ .HasColumnType("bit");
+
+ b.Property("Password")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Phone")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("QrCode")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("UpdateTime")
+ .HasColumnType("datetime2");
+
+ b.Property("UpdateUserId")
+ .HasColumnType("bigint");
+
+ b.Property("UserName")
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("Id");
+
+ b.ToTable("Users");
+ });
+
+ modelBuilder.Entity("Bunny.Dao.Entity.System.Post", b =>
+ {
+ b.HasOne("Bunny.Dao.Entity.System.Blog", "Blog")
+ .WithMany()
+ .HasForeignKey("BlogId");
+
+ b.Navigation("Blog");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/Bunny.Common/Migrations/20240902054644_InitialCreate.cs b/Bunny.Common/Migrations/20240902054644_InitialCreate.cs
new file mode 100644
index 0000000..a93b535
--- /dev/null
+++ b/Bunny.Common/Migrations/20240902054644_InitialCreate.cs
@@ -0,0 +1,119 @@
+using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace Bunny.Common.Migrations
+{
+ ///
+ public partial class InitialCreate : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.CreateTable(
+ name: "Blog",
+ columns: table => new
+ {
+ Id = table.Column(type: "nvarchar(450)", nullable: false),
+ BlogUrl = table.Column(type: "varchar(600)", nullable: false),
+ CreateTime = table.Column(type: "datetime2", nullable: false),
+ UpdateTime = table.Column(type: "datetime2", nullable: false),
+ CreateUserId = table.Column(type: "bigint", nullable: false),
+ UpdateUserId = table.Column(type: "bigint", nullable: false),
+ IsDeleted = table.Column(type: "bit", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Blog", x => x.Id);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "Products",
+ columns: table => new
+ {
+ Id = table.Column(type: "nvarchar(450)", nullable: false),
+ CustomerId = table.Column(type: "nvarchar(max)", nullable: true),
+ CustomerName = table.Column(type: "nvarchar(max)", nullable: true),
+ PackageType = table.Column(type: "nvarchar(max)", nullable: true),
+ CreateTime = table.Column(type: "datetime2", nullable: false),
+ UpdateTime = table.Column(type: "datetime2", nullable: false),
+ CreateUserId = table.Column(type: "bigint", nullable: false),
+ UpdateUserId = table.Column(type: "bigint", nullable: false),
+ IsDeleted = table.Column(type: "bit", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Products", x => x.Id);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "Users",
+ columns: table => new
+ {
+ Id = table.Column(type: "nvarchar(450)", nullable: false),
+ UserName = table.Column(type: "nvarchar(max)", nullable: true),
+ Password = table.Column(type: "nvarchar(max)", nullable: true),
+ Email = table.Column(type: "nvarchar(max)", nullable: true),
+ Phone = table.Column(type: "nvarchar(max)", nullable: true),
+ QrCode = table.Column(type: "nvarchar(max)", nullable: true),
+ CompanyCode = table.Column(type: "nvarchar(max)", nullable: true),
+ DeptCode = table.Column(type: "nvarchar(max)", nullable: true),
+ CreateTime = table.Column(type: "datetime2", nullable: false),
+ UpdateTime = table.Column(type: "datetime2", nullable: false),
+ CreateUserId = table.Column(type: "bigint", nullable: false),
+ UpdateUserId = table.Column(type: "bigint", nullable: false),
+ IsDeleted = table.Column(type: "bit", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Users", x => x.Id);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "Posts",
+ columns: table => new
+ {
+ Id = table.Column(type: "nvarchar(450)", nullable: false),
+ Title = table.Column(type: "nvarchar(600)", maxLength: 600, nullable: true),
+ Content = table.Column(type: "nvarchar(max)", nullable: true),
+ BlogId = table.Column(type: "nvarchar(450)", nullable: true),
+ CreateTime = table.Column(type: "datetime2", nullable: false),
+ UpdateTime = table.Column(type: "datetime2", nullable: false),
+ CreateUserId = table.Column(type: "bigint", nullable: false),
+ UpdateUserId = table.Column(type: "bigint", nullable: false),
+ IsDeleted = table.Column(type: "bit", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Posts", x => x.Id);
+ table.ForeignKey(
+ name: "FK_Posts_Blog_BlogId",
+ column: x => x.BlogId,
+ principalTable: "Blog",
+ principalColumn: "Id");
+ });
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Posts_BlogId",
+ table: "Posts",
+ column: "BlogId");
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(
+ name: "Posts");
+
+ migrationBuilder.DropTable(
+ name: "Products");
+
+ migrationBuilder.DropTable(
+ name: "Users");
+
+ migrationBuilder.DropTable(
+ name: "Blog");
+ }
+ }
+}
diff --git a/Bunny.Common/Migrations/EfCoreContextModelSnapshot.cs b/Bunny.Common/Migrations/EfCoreContextModelSnapshot.cs
index 31a34f2..9663506 100644
--- a/Bunny.Common/Migrations/EfCoreContextModelSnapshot.cs
+++ b/Bunny.Common/Migrations/EfCoreContextModelSnapshot.cs
@@ -1,8 +1,9 @@
//
using System;
-using Bunny.Common.Connect;
+using Bunny.Common.Context;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
@@ -15,152 +16,164 @@ namespace Bunny.Common.Migrations
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
- modelBuilder.HasAnnotation("ProductVersion", "8.0.7");
+ modelBuilder
+ .HasAnnotation("ProductVersion", "8.0.8")
+ .HasAnnotation("Relational:MaxIdentifierLength", 128);
- modelBuilder.Entity("Bunny.Dao.Models.System.Blog", b =>
+ SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
+
+ modelBuilder.Entity("Bunny.Dao.Entity.System.Blog", b =>
{
b.Property("Id")
- .HasColumnType("TEXT");
+ .HasColumnType("nvarchar(450)");
b.Property("CreateTime")
- .HasColumnType("TEXT");
+ .HasColumnType("datetime2");
b.Property("CreateUserId")
- .HasColumnType("INTEGER");
+ .HasColumnType("bigint");
+
+ b.Property("IsDeleted")
+ .HasColumnType("bit");
b.Property("UpdateTime")
- .HasColumnType("TEXT");
+ .HasColumnType("datetime2");
b.Property("UpdateUserId")
- .HasColumnType("INTEGER");
+ .HasColumnType("bigint");
b.Property("Url")
.IsRequired()
- .HasColumnType("TEXT");
+ .HasColumnType("varchar(600)")
+ .HasColumnName("BlogUrl");
b.HasKey("Id");
- b.ToTable("Blogs");
+ b.ToTable("Blog");
});
- modelBuilder.Entity("Bunny.Dao.Models.System.Post", b =>
+ modelBuilder.Entity("Bunny.Dao.Entity.System.Post", b =>
{
b.Property("Id")
- .HasColumnType("TEXT");
+ .HasColumnType("nvarchar(450)");
- b.Property("BlogId")
- .HasColumnType("INTEGER");
-
- b.Property("BlogId1")
- .HasColumnType("TEXT");
+ b.Property("BlogId")
+ .HasColumnType("nvarchar(450)");
b.Property("Content")
- .HasColumnType("TEXT");
+ .HasColumnType("nvarchar(max)");
b.Property("CreateTime")
- .HasColumnType("TEXT");
+ .HasColumnType("datetime2");
b.Property("CreateUserId")
- .HasColumnType("INTEGER");
+ .HasColumnType("bigint");
- b.Property("PostId")
- .HasColumnType("INTEGER");
+ b.Property("IsDeleted")
+ .HasColumnType("bit");
b.Property("Title")
- .HasColumnType("TEXT");
+ .HasMaxLength(600)
+ .HasColumnType("nvarchar(600)");
b.Property("UpdateTime")
- .HasColumnType("TEXT");
+ .HasColumnType("datetime2");
b.Property("UpdateUserId")
- .HasColumnType("INTEGER");
+ .HasColumnType("bigint");
b.HasKey("Id");
- b.HasIndex("BlogId1");
+ b.HasIndex("BlogId");
b.ToTable("Posts");
});
- modelBuilder.Entity("Bunny.Dao.Models.System.Product", b =>
+ modelBuilder.Entity("Bunny.Dao.Entity.System.Product", b =>
{
b.Property("Id")
- .HasColumnType("TEXT");
+ .HasColumnType("nvarchar(450)");
b.Property("CreateTime")
- .HasColumnType("TEXT");
+ .HasColumnType("datetime2");
b.Property("CreateUserId")
- .HasColumnType("INTEGER");
+ .HasColumnType("bigint");
b.Property("CustomerId")
- .HasColumnType("TEXT");
+ .HasColumnType("nvarchar(max)");
b.Property("CustomerName")
- .HasColumnType("TEXT");
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("IsDeleted")
+ .HasColumnType("bit");
b.Property("PackageType")
- .HasColumnType("TEXT");
+ .HasColumnType("nvarchar(max)");
b.Property("UpdateTime")
- .HasColumnType("TEXT");
+ .HasColumnType("datetime2");
b.Property("UpdateUserId")
- .HasColumnType("INTEGER");
+ .HasColumnType("bigint");
b.HasKey("Id");
b.ToTable("Products");
});
- modelBuilder.Entity("Bunny.Dao.Models.System.User", b =>
+ modelBuilder.Entity("Bunny.Dao.Entity.System.User", b =>
{
b.Property("Id")
- .HasColumnType("TEXT");
+ .HasColumnType("nvarchar(450)");
b.Property("CompanyCode")
- .HasColumnType("TEXT");
+ .HasColumnType("nvarchar(max)");
b.Property("CreateTime")
- .HasColumnType("TEXT");
+ .HasColumnType("datetime2");
b.Property("CreateUserId")
- .HasColumnType("INTEGER");
+ .HasColumnType("bigint");
b.Property("DeptCode")
- .HasColumnType("TEXT");
+ .HasColumnType("nvarchar(max)");
b.Property("Email")
- .HasColumnType("TEXT");
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("IsDeleted")
+ .HasColumnType("bit");
b.Property("Password")
- .HasColumnType("TEXT");
+ .HasColumnType("nvarchar(max)");
b.Property("Phone")
- .HasColumnType("TEXT");
+ .HasColumnType("nvarchar(max)");
b.Property("QrCode")
- .HasColumnType("TEXT");
+ .HasColumnType("nvarchar(max)");
b.Property("UpdateTime")
- .HasColumnType("TEXT");
+ .HasColumnType("datetime2");
b.Property("UpdateUserId")
- .HasColumnType("INTEGER");
+ .HasColumnType("bigint");
b.Property("UserName")
- .HasColumnType("TEXT");
+ .HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Users");
});
- modelBuilder.Entity("Bunny.Dao.Models.System.Post", b =>
+ modelBuilder.Entity("Bunny.Dao.Entity.System.Post", b =>
{
- b.HasOne("Bunny.Dao.Models.System.Blog", "Blog")
+ b.HasOne("Bunny.Dao.Entity.System.Blog", "Blog")
.WithMany()
- .HasForeignKey("BlogId1");
+ .HasForeignKey("BlogId");
b.Navigation("Blog");
});
diff --git a/Bunny.Common/Utils/EmailUtil.cs b/Bunny.Common/Utils/EmailUtil.cs
index be9398b..e410e7b 100644
--- a/Bunny.Common/Utils/EmailUtil.cs
+++ b/Bunny.Common/Utils/EmailUtil.cs
@@ -31,9 +31,9 @@ public class EmailUtil
};
// 判断是否有抄送
- if (entity.CC != null)
+ if (entity.Cc != null)
{
- var ccArray = entity.CC.Split(',');
+ var ccArray = entity.Cc.Split(',');
// 是抄送
if (entity.IsBbc == false)
foreach (var ccAddress in ccArray)
diff --git a/Bunny.Common/Utils/Jwt/JwtParseUtil.cs b/Bunny.Common/Utils/Jwt/JwtParseUtil.cs
index bca2bbe..b6010e3 100644
--- a/Bunny.Common/Utils/Jwt/JwtParseUtil.cs
+++ b/Bunny.Common/Utils/Jwt/JwtParseUtil.cs
@@ -1,7 +1,7 @@
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using Bunny.Common.Exception;
-using Bunny.Dao.Entity.Constant;
+using Bunny.Dao.Model.Constant;
using Newtonsoft.Json;
namespace Bunny.Common.Utils.Jwt;
diff --git a/Bunny.Common/Utils/MinioUtil.cs b/Bunny.Common/Utils/MinioUtil.cs
index c5e2190..c274b1f 100644
--- a/Bunny.Common/Utils/MinioUtil.cs
+++ b/Bunny.Common/Utils/MinioUtil.cs
@@ -1,6 +1,6 @@
-using Bunny.Common.Connect;
+using Bunny.Common.Context;
using Bunny.Common.Exception;
-using Bunny.Dao.Entity.Constant;
+using Bunny.Dao.Model.Constant;
using Microsoft.AspNetCore.Http;
using Microsoft.IdentityModel.Tokens;
using Minio.DataModel;
diff --git a/Bunny.Common/Utils/Net/Response.cs b/Bunny.Common/Utils/Net/Response.cs
index 57d3ed5..08b5846 100644
--- a/Bunny.Common/Utils/Net/Response.cs
+++ b/Bunny.Common/Utils/Net/Response.cs
@@ -1,5 +1,5 @@
using System.Net;
-using Bunny.Dao.Entity.Result;
+using Bunny.Dao.Model.Result;
using Microsoft.AspNetCore.Mvc;
namespace Bunny.Common.Utils.Net;
diff --git a/Bunny.Dao/Bunny.Dao.csproj b/Bunny.Dao/Bunny.Dao.csproj
index 99800de..61a281b 100644
--- a/Bunny.Dao/Bunny.Dao.csproj
+++ b/Bunny.Dao/Bunny.Dao.csproj
@@ -10,4 +10,8 @@
+
+
+
+
diff --git a/Bunny.Dao/Dto/System/BlogUpdateDto.cs b/Bunny.Dao/Dto/System/BlogUpdateDto.cs
new file mode 100644
index 0000000..1520cbf
--- /dev/null
+++ b/Bunny.Dao/Dto/System/BlogUpdateDto.cs
@@ -0,0 +1,20 @@
+using System.ComponentModel.DataAnnotations;
+
+namespace Bunny.Dao.Dto.System;
+
+public class BlogUpdateDto
+{
+ [Required(ErrorMessage = "ID是必须的")] public Guid? Id { get; set; }
+ [Required(ErrorMessage = "Url是必填项")] public string? Url { get; init; }
+ public DateTime CreateTime { get; set; }
+
+ public DateTime UpdateTime { get; set; }
+
+ public long CreateUserId { get; set; }
+
+ public long UpdateUserId { get; set; }
+
+ public bool IsDeleted { get; set; }
+
+ public byte[]? Version { get; set; }
+}
\ No newline at end of file
diff --git a/Bunny.Dao/Entity/Base/BaseEntity.cs b/Bunny.Dao/Entity/Base/BaseEntity.cs
index d3ece92..4f32a97 100644
--- a/Bunny.Dao/Entity/Base/BaseEntity.cs
+++ b/Bunny.Dao/Entity/Base/BaseEntity.cs
@@ -1,8 +1,10 @@
-namespace Bunny.Dao.Entity.Base;
+using System.ComponentModel.DataAnnotations;
+
+namespace Bunny.Dao.Entity.Base;
public class BaseEntity
{
- public string? Id { get; set; }
+ [Key] public Guid? Id { get; set; }
public DateTime CreateTime { get; set; }
@@ -13,4 +15,6 @@ public class BaseEntity
public long UpdateUserId { get; set; }
public bool IsDeleted { get; set; }
+
+ [Timestamp] public byte[]? Version { get; set; }
}
\ No newline at end of file
diff --git a/Bunny.Dao/Entity/Email/EmailSendEntity.cs b/Bunny.Dao/Entity/Email/EmailSendEntity.cs
index eb9c39e..cac4446 100644
--- a/Bunny.Dao/Entity/Email/EmailSendEntity.cs
+++ b/Bunny.Dao/Entity/Email/EmailSendEntity.cs
@@ -8,7 +8,7 @@ public abstract class EmailSendEntity
///
/// SMTP 服务器
///
- public string SmtpService { get; set; }
+ public string? SmtpService { get; set; }
///
/// SMTP 服务器端口号
@@ -18,32 +18,32 @@ public abstract class EmailSendEntity
///
/// 发送者邮件
///
- public string SendEmail { get; set; }
+ public string? SendEmail { get; set; }
///
/// 发送者密码
///
- public string SendEmailPassword { get; set; }
+ public string? SendEmailPassword { get; set; }
///
/// 接受这邮件
///
- public string ReceiverEmail { get; set; }
+ public string? ReceiverEmail { get; set; }
///
/// 发送邮件的主题
///
- public string Subject { get; set; }
+ public string? Subject { get; set; }
///
/// 发送邮件的内容
///
- public string Body { get; set; }
+ public string? Body { get; set; }
///
/// 设置抄送
///
- public string? CC { get; set; }
+ public string? Cc { get; set; }
///
/// 是否密送
diff --git a/Bunny.Dao/Entity/Enum/Enum.cs b/Bunny.Dao/Entity/Enum/Enum.cs
deleted file mode 100644
index cd8c2d5..0000000
--- a/Bunny.Dao/Entity/Enum/Enum.cs
+++ /dev/null
@@ -1,5 +0,0 @@
-namespace Bunny.Dao.Entity.Enum;
-
-public enum Enum
-{
-}
\ No newline at end of file
diff --git a/Bunny.Dao/Entity/System/Blog.cs b/Bunny.Dao/Entity/System/Blog.cs
index 986ec52..b373b42 100644
--- a/Bunny.Dao/Entity/System/Blog.cs
+++ b/Bunny.Dao/Entity/System/Blog.cs
@@ -1,9 +1,13 @@
using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
using Bunny.Dao.Entity.Base;
namespace Bunny.Dao.Entity.System;
+[Table("Blog")]
public class Blog : BaseEntity
{
- [Required(ErrorMessage = "Url是必填项")] public string Url { get; set; }
+ [Required]
+ [Column("BlogUrl", TypeName = "varchar(600)")]
+ public string? Url { get; init; }
}
\ No newline at end of file
diff --git a/Bunny.Dao/Entity/System/Post.cs b/Bunny.Dao/Entity/System/Post.cs
index 7d556a6..e0d22ca 100644
--- a/Bunny.Dao/Entity/System/Post.cs
+++ b/Bunny.Dao/Entity/System/Post.cs
@@ -1,13 +1,11 @@
-using Bunny.Dao.Entity.Base;
+using System.ComponentModel.DataAnnotations;
+using Bunny.Dao.Entity.Base;
namespace Bunny.Dao.Entity.System;
public class Post : BaseEntity
{
- public int PostId { get; set; }
- public string? Title { get; set; }
- public string? Content { get; set; }
-
- public int BlogId { get; set; }
- public Blog? Blog { get; set; }
+ [MaxLength(600)] public string? Title { get; init; }
+ public string? Content { get; init; }
+ public Blog? Blog { get; init; }
}
\ No newline at end of file
diff --git a/Bunny.Dao/Entity/Constant/ExceptionConstant.cs b/Bunny.Dao/Model/Constant/ExceptionConstant.cs
similarity index 97%
rename from Bunny.Dao/Entity/Constant/ExceptionConstant.cs
rename to Bunny.Dao/Model/Constant/ExceptionConstant.cs
index 35d49aa..41e844f 100644
--- a/Bunny.Dao/Entity/Constant/ExceptionConstant.cs
+++ b/Bunny.Dao/Model/Constant/ExceptionConstant.cs
@@ -1,4 +1,4 @@
-namespace Bunny.Dao.Entity.Constant;
+namespace Bunny.Dao.Model.Constant;
///
/// 错误常量
@@ -14,6 +14,7 @@ public class ExceptionConstant
public const string AddDataIsEmptyException = "添加数据为空";
public const string DeleteIdIsNotEmptyException = "删除id不能为空";
public const string ServerError = "服务器错误";
+ public const string DataBaseError = "数据库错误";
// 文章操作相关
public const string DoLikeCommentNotExist = "点赞内容不存在";
diff --git a/Bunny.Dao/Entity/Constant/FileMessageConstant.cs b/Bunny.Dao/Model/Constant/FileMessageConstant.cs
similarity index 96%
rename from Bunny.Dao/Entity/Constant/FileMessageConstant.cs
rename to Bunny.Dao/Model/Constant/FileMessageConstant.cs
index d3e01f3..2bf20e2 100644
--- a/Bunny.Dao/Entity/Constant/FileMessageConstant.cs
+++ b/Bunny.Dao/Model/Constant/FileMessageConstant.cs
@@ -1,4 +1,4 @@
-namespace Bunny.Dao.Entity.Constant;
+namespace Bunny.Dao.Model.Constant;
///
/// 文件消息相关常量
diff --git a/Bunny.Dao/Entity/Constant/LocalDateTimeConstant.cs b/Bunny.Dao/Model/Constant/LocalDateTimeConstant.cs
similarity index 90%
rename from Bunny.Dao/Entity/Constant/LocalDateTimeConstant.cs
rename to Bunny.Dao/Model/Constant/LocalDateTimeConstant.cs
index f62e584..b779f72 100644
--- a/Bunny.Dao/Entity/Constant/LocalDateTimeConstant.cs
+++ b/Bunny.Dao/Model/Constant/LocalDateTimeConstant.cs
@@ -1,4 +1,4 @@
-namespace Bunny.Dao.Entity.Constant;
+namespace Bunny.Dao.Model.Constant;
///
/// 事件相关常量
diff --git a/Bunny.Dao/Entity/Constant/MailMessageConstant.cs b/Bunny.Dao/Model/Constant/MailMessageConstant.cs
similarity index 92%
rename from Bunny.Dao/Entity/Constant/MailMessageConstant.cs
rename to Bunny.Dao/Model/Constant/MailMessageConstant.cs
index 12227cc..cd151b9 100644
--- a/Bunny.Dao/Entity/Constant/MailMessageConstant.cs
+++ b/Bunny.Dao/Model/Constant/MailMessageConstant.cs
@@ -1,4 +1,4 @@
-namespace Bunny.Dao.Entity.Constant;
+namespace Bunny.Dao.Model.Constant;
///
/// 邮箱消息先关常量
diff --git a/Bunny.Dao/Entity/Constant/RedisConstant.cs b/Bunny.Dao/Model/Constant/RedisConstant.cs
similarity index 96%
rename from Bunny.Dao/Entity/Constant/RedisConstant.cs
rename to Bunny.Dao/Model/Constant/RedisConstant.cs
index 644d178..1c0b5a8 100644
--- a/Bunny.Dao/Entity/Constant/RedisConstant.cs
+++ b/Bunny.Dao/Model/Constant/RedisConstant.cs
@@ -1,4 +1,4 @@
-namespace Bunny.Dao.Entity.Constant;
+namespace Bunny.Dao.Model.Constant;
///
/// Redis相关常量
diff --git a/Bunny.Dao/Entity/Result/Constant/ErrorConstant.cs b/Bunny.Dao/Model/Constant/Result/ErrorConstant.cs
similarity index 84%
rename from Bunny.Dao/Entity/Result/Constant/ErrorConstant.cs
rename to Bunny.Dao/Model/Constant/Result/ErrorConstant.cs
index b398666..d125ee9 100644
--- a/Bunny.Dao/Entity/Result/Constant/ErrorConstant.cs
+++ b/Bunny.Dao/Model/Constant/Result/ErrorConstant.cs
@@ -1,4 +1,4 @@
-namespace Bunny.Dao.Entity.Result.Constant;
+namespace Bunny.Dao.Model.Constant.Result;
///
/// 发生时的错误敞亮
diff --git a/Bunny.Dao/Entity/Result/Constant/SuccessConstant.cs b/Bunny.Dao/Model/Constant/Result/SuccessConstant.cs
similarity index 65%
rename from Bunny.Dao/Entity/Result/Constant/SuccessConstant.cs
rename to Bunny.Dao/Model/Constant/Result/SuccessConstant.cs
index 91be540..6c58310 100644
--- a/Bunny.Dao/Entity/Result/Constant/SuccessConstant.cs
+++ b/Bunny.Dao/Model/Constant/Result/SuccessConstant.cs
@@ -1,4 +1,4 @@
-namespace Bunny.Dao.Entity.Result.Constant;
+namespace Bunny.Dao.Model.Constant.Result;
public class SuccessConstant
{
diff --git a/Bunny.Dao/Entity/Constant/SecurityConstant.cs b/Bunny.Dao/Model/Constant/SecurityConstant.cs
similarity index 75%
rename from Bunny.Dao/Entity/Constant/SecurityConstant.cs
rename to Bunny.Dao/Model/Constant/SecurityConstant.cs
index 5e6802e..e7621a0 100644
--- a/Bunny.Dao/Entity/Constant/SecurityConstant.cs
+++ b/Bunny.Dao/Model/Constant/SecurityConstant.cs
@@ -1,4 +1,4 @@
-namespace Bunny.Dao.Entity.Constant;
+namespace Bunny.Dao.Model.Constant;
///
/// 鉴权相关常量
diff --git a/Bunny.Dao/Entity/Constant/SqlConstant.cs b/Bunny.Dao/Model/Constant/SqlConstant.cs
similarity index 89%
rename from Bunny.Dao/Entity/Constant/SqlConstant.cs
rename to Bunny.Dao/Model/Constant/SqlConstant.cs
index 4f964c7..61d967e 100644
--- a/Bunny.Dao/Entity/Constant/SqlConstant.cs
+++ b/Bunny.Dao/Model/Constant/SqlConstant.cs
@@ -1,4 +1,4 @@
-namespace Bunny.Dao.Entity.Constant;
+namespace Bunny.Dao.Model.Constant;
///
/// 数据库相关常量
diff --git a/Bunny.Dao/Entity/Constant/StatusConstant.cs b/Bunny.Dao/Model/Constant/StatusConstant.cs
similarity index 78%
rename from Bunny.Dao/Entity/Constant/StatusConstant.cs
rename to Bunny.Dao/Model/Constant/StatusConstant.cs
index 8936e5a..7b9d3b3 100644
--- a/Bunny.Dao/Entity/Constant/StatusConstant.cs
+++ b/Bunny.Dao/Model/Constant/StatusConstant.cs
@@ -1,4 +1,4 @@
-namespace Bunny.Dao.Entity.Constant;
+namespace Bunny.Dao.Model.Constant;
///
/// 状态相关常量
diff --git a/Bunny.Dao/Entity/Constant/UserConstant.cs b/Bunny.Dao/Model/Constant/UserConstant.cs
similarity index 86%
rename from Bunny.Dao/Entity/Constant/UserConstant.cs
rename to Bunny.Dao/Model/Constant/UserConstant.cs
index 606c083..02baa01 100644
--- a/Bunny.Dao/Entity/Constant/UserConstant.cs
+++ b/Bunny.Dao/Model/Constant/UserConstant.cs
@@ -1,4 +1,4 @@
-namespace Bunny.Dao.Entity.Constant;
+namespace Bunny.Dao.Model.Constant;
///
/// 用户相关常量
diff --git a/Bunny.Dao/Model/Enum/Enum.cs b/Bunny.Dao/Model/Enum/Enum.cs
new file mode 100644
index 0000000..152baec
--- /dev/null
+++ b/Bunny.Dao/Model/Enum/Enum.cs
@@ -0,0 +1,5 @@
+namespace Bunny.Dao.Model.Enum;
+
+public enum Enum
+{
+}
\ No newline at end of file
diff --git a/Bunny.Dao/Entity/Result/Pagination.cs b/Bunny.Dao/Model/Result/Pagination.cs
similarity index 92%
rename from Bunny.Dao/Entity/Result/Pagination.cs
rename to Bunny.Dao/Model/Result/Pagination.cs
index 48120c4..84fa2bb 100644
--- a/Bunny.Dao/Entity/Result/Pagination.cs
+++ b/Bunny.Dao/Model/Result/Pagination.cs
@@ -1,4 +1,4 @@
-namespace Bunny.Dao.Entity.Result;
+namespace Bunny.Dao.Model.Result;
public class PageResult
{
diff --git a/Bunny.Dao/Entity/Result/Result.cs b/Bunny.Dao/Model/Result/Result.cs
similarity index 97%
rename from Bunny.Dao/Entity/Result/Result.cs
rename to Bunny.Dao/Model/Result/Result.cs
index 3596420..63c5082 100644
--- a/Bunny.Dao/Entity/Result/Result.cs
+++ b/Bunny.Dao/Model/Result/Result.cs
@@ -1,8 +1,8 @@
using System.Net;
-using Bunny.Dao.Entity.Result.Constant;
+using Bunny.Dao.Model.Constant.Result;
using Microsoft.AspNetCore.Mvc;
-namespace Bunny.Dao.Entity.Result;
+namespace Bunny.Dao.Model.Result;
[Serializable]
public class Result(HttpStatusCode code, T? data, string? message)
@@ -168,7 +168,7 @@ public class Result(HttpStatusCode code, T? data, string? message)
/// 消息内容
/// 数据内容分
/// 返回的数据内容
- public static Result Error(string message, T data)
+ public static Result Error(T data, string message)
{
return new Result(HttpStatusCode.InternalServerError, data, message);
}
diff --git a/Bunny.Service/Filter/AuthorizationFilter.cs b/Bunny.Service/Filter/AuthorizationFilter.cs
index cee6176..18ddfb0 100644
--- a/Bunny.Service/Filter/AuthorizationFilter.cs
+++ b/Bunny.Service/Filter/AuthorizationFilter.cs
@@ -1,7 +1,7 @@
using System.Net;
using Bunny.Common.Utils.Jwt;
using Bunny.Common.Utils.Net;
-using Bunny.Dao.Entity.Constant;
+using Bunny.Dao.Model.Constant;
using Bunny.Dao.Vo.User;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Filters;
diff --git a/Bunny.Service/IService/IBlogService.cs b/Bunny.Service/IService/IBlogService.cs
index 61e93c8..2f46545 100644
--- a/Bunny.Service/IService/IBlogService.cs
+++ b/Bunny.Service/IService/IBlogService.cs
@@ -1,5 +1,6 @@
-using Bunny.Dao.Entity.Result;
+using Bunny.Dao.Dto.System;
using Bunny.Dao.Entity.System;
+using Bunny.Dao.Model.Result;
namespace Bunny.Service.IService;
@@ -21,7 +22,7 @@ public interface IBlogService
/// 更新Blog内容
///
///
- void UpdateBlog(Blog dto);
+ void UpdateBlog(BlogUpdateDto dto);
///
/// 删除BLog
diff --git a/Bunny.Service/IService/Service/BlogService.cs b/Bunny.Service/IService/Service/BlogService.cs
index bd53af2..9ee6589 100644
--- a/Bunny.Service/IService/Service/BlogService.cs
+++ b/Bunny.Service/IService/Service/BlogService.cs
@@ -1,17 +1,15 @@
-using Bunny.Common.Connect;
-using Bunny.Dao.Entity.Result;
+using Bunny.Common.Context;
+using Bunny.Common.Utils.Net;
+using Bunny.Dao.Dto.System;
using Bunny.Dao.Entity.System;
+using Bunny.Dao.Model.Result;
+using Microsoft.AspNetCore.Components;
namespace Bunny.Service.IService.Service;
public class BlogService : IBlogService
{
- private readonly EfCoreContext _dbContext;
-
- public BlogService(EfCoreContext dbContext)
- {
- _dbContext = dbContext;
- }
+ [Inject] public required EfCoreContext DbContext { get; set; }
///
/// 添加Blog
@@ -20,8 +18,8 @@ public class BlogService : IBlogService
///
public void AddBlog(Blog dto)
{
- _dbContext.Add(dto);
- _dbContext.SaveChanges();
+ DbContext.Add(dto);
+ DbContext.SaveChanges();
}
///
@@ -30,17 +28,20 @@ public class BlogService : IBlogService
///
public List QueryBlog()
{
- return _dbContext.Blogs.ToList();
+ return DbContext.Blogs.ToList();
}
///
/// 更新Blog内容
///
///
- public void UpdateBlog(Blog dto)
+ public void UpdateBlog(BlogUpdateDto dto)
{
- _dbContext.Blogs.Update(dto);
- _dbContext.SaveChanges();
+ var blog = new Blog();
+ NetUtil.CopyProperties(dto, blog);
+
+ DbContext.Blogs.Update(blog);
+ DbContext.SaveChanges();
}
///
@@ -49,9 +50,9 @@ public class BlogService : IBlogService
///
public void DeleteBlog(string id)
{
- var blog = new Blog { Id = id };
- _dbContext.Blogs.Remove(blog);
- _dbContext.SaveChanges();
+ var blog = new Blog { Id = Guid.NewGuid() };
+ DbContext.Blogs.Remove(blog);
+ DbContext.SaveChanges();
}
///
@@ -64,7 +65,6 @@ public class BlogService : IBlogService
for (var i = 0; i <= 100000; i++)
list.Add(new Blog
{
- Id = $"{i}",
Url = url,
CreateTime = DateTime.Now,
UpdateTime = DateTime.Now,
@@ -72,8 +72,8 @@ public class BlogService : IBlogService
CreateUserId = Random.Shared.NextInt64()
});
- _dbContext.Blogs.AddRange(list);
- _dbContext.SaveChanges();
+ DbContext.Blogs.AddRange(list);
+ DbContext.SaveChanges();
}
@@ -85,12 +85,12 @@ public class BlogService : IBlogService
var list = new List();
for (var i = 0; i < 10; i++)
{
- var blog = new Blog { Id = $"{i}" };
+ var blog = new Blog();
list.Add(blog);
}
- _dbContext.Blogs.RemoveRange(list);
- _dbContext.SaveChanges();
+ DbContext.Blogs.RemoveRange(list);
+ DbContext.SaveChanges();
}
///
@@ -99,19 +99,19 @@ public class BlogService : IBlogService
public void UseTransaction()
{
// 还可以使用异步的
- var transaction = _dbContext.Database.BeginTransaction();
+ var transaction = DbContext.Database.BeginTransaction();
// 执行批量更新操作
var list = new List();
for (var i = 0; i < 10; i++)
{
- var blog = new Blog { Id = $"{i}", Url = "https://learn.microsoft.com/zh-cn/ef/core/saving/transactions" };
+ var blog = new Blog { Url = "https://learn.microsoft.com/zh-cn/ef/core/saving/transactions" };
list.Add(blog);
}
// 更新内容
- _dbContext.Blogs.UpdateRange(list);
- _dbContext.SaveChanges();
+ DbContext.Blogs.UpdateRange(list);
+ DbContext.SaveChanges();
// 还可以使用异步方式
transaction.Commit();
@@ -124,7 +124,7 @@ public class BlogService : IBlogService
///
public PageResult QueryPage(int page, int limit)
{
- var items = _dbContext.Blogs.ToList();
+ var items = DbContext.Blogs.Take(limit).Skip(page).ToList();
var total = items.Count;
var pages = (int)Math.Ceiling(total / (double)limit);
diff --git a/Bunny.Service/IService/Service/LoginService.cs b/Bunny.Service/IService/Service/LoginService.cs
index 695112a..01d4c7a 100644
--- a/Bunny.Service/IService/Service/LoginService.cs
+++ b/Bunny.Service/IService/Service/LoginService.cs
@@ -1,11 +1,4 @@
-using Bunny.Common.Exception;
-using Bunny.Common.Utils.Jwt;
-using Bunny.Common.Utils.Net;
-using Bunny.Dao.Dto.User;
-using Bunny.Dao.Entity.Constant;
-using Bunny.Dao.Vo.User;
-
-namespace Bunny.Service.IService.Service;
+namespace Bunny.Service.IService.Service;
public class LoginService : ILoginService
{
diff --git a/Bunny.Service/IService/Service/MinioService.cs b/Bunny.Service/IService/Service/MinioService.cs
index a4f0c23..d41e168 100644
--- a/Bunny.Service/IService/Service/MinioService.cs
+++ b/Bunny.Service/IService/Service/MinioService.cs
@@ -1,5 +1,5 @@
using Bunny.Common;
-using Bunny.Common.Connect;
+using Bunny.Common.Context;
using Microsoft.AspNetCore.Http;
using Minio;
using Minio.DataModel;
diff --git a/Bunny.Service/IService/Service/RedisOptionService.cs b/Bunny.Service/IService/Service/RedisOptionService.cs
index 53b003e..31f7926 100644
--- a/Bunny.Service/IService/Service/RedisOptionService.cs
+++ b/Bunny.Service/IService/Service/RedisOptionService.cs
@@ -1,4 +1,4 @@
-using Bunny.Common.Connect;
+using Bunny.Common.Context;
using Bunny.Dao.Entity.System;
using Newtonsoft.Json;
using StackExchange.Redis;
@@ -7,7 +7,7 @@ namespace Bunny.Service.IService.Service;
public class RedisOptionService : IRedisOptionService
{
- private readonly IDatabase _redisDatabase = RedisContext.RedisDatabase;
+ private readonly IDatabase _redisDatabase = RedisContext.RedisDatabase!;
///
@@ -60,7 +60,7 @@ public class RedisOptionService : IRedisOptionService
{
var post = new Post
{
- PostId = 1,
+ Id = Guid.NewGuid(),
Title = "存入JSON内容",
Content = "正在存入JSON内容"
};
diff --git a/Bunny.Service/WebSocket/WebSocketTest.cs b/Bunny.Service/WebSocket/WebSocketTest.cs
index 4c3fd6f..10f6879 100644
--- a/Bunny.Service/WebSocket/WebSocketTest.cs
+++ b/Bunny.Service/WebSocket/WebSocketTest.cs
@@ -6,7 +6,7 @@ public static class WebSocketTest
{
public static void Start()
{
- var webSocketServer = new WebSocketServer("ws://0.0.0.0:8000");
+ var webSocketServer = new WebSocketServer("ws://0.0.0.0:8800");
webSocketServer.RestartAfterListenError = true;
webSocketServer.Start(socket =>
diff --git a/Bunny.Test.Until/EfCoreTest/EfCoreTest.cs b/Bunny.Test.Until/EfCoreTest/EfCoreTest.cs
deleted file mode 100644
index 19f8e94..0000000
--- a/Bunny.Test.Until/EfCoreTest/EfCoreTest.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-using Bunny.Common.Connect;
-using Bunny.Dao.Entity.System;
-using NUnit.Framework;
-
-namespace Bunny.Test.Until.EfCoreTest;
-
-public class EfCoreTest
-{
- [Test]
- public void TestDbConnection()
- {
- using var db = new EfCoreContext();
- Console.WriteLine($"Database path: {db.DbPath}.");
-
- // Create
- Console.WriteLine("Inserting a new blog");
- db.Add(new Blog { Url = "http://blogs.msdn.com/adonet" });
- db.SaveChanges();
-
- // Read
- Console.WriteLine("Querying for a blog");
- var blog = db.Blogs
- .OrderBy(b => b.Id)
- .First();
- Console.WriteLine(blog.Url);
- }
-}
\ No newline at end of file
diff --git a/Bunny.Test.Until/TestResultCodeEnum.cs b/Bunny.Test.Until/TestResultCodeEnum.cs
index 4851c49..6f0e78c 100644
--- a/Bunny.Test.Until/TestResultCodeEnum.cs
+++ b/Bunny.Test.Until/TestResultCodeEnum.cs
@@ -1,6 +1,6 @@
using System.Net;
-using Bunny.Dao.Entity.Constant;
-using Bunny.Dao.Entity.Result;
+using Bunny.Dao.Model.Constant;
+using Bunny.Dao.Model.Result;
using Newtonsoft.Json;
using NUnit.Framework;
diff --git a/Bunny.WebApi/Bunny.WebApi.csproj b/Bunny.WebApi/Bunny.WebApi.csproj
index fffaba7..70cb8d7 100644
--- a/Bunny.WebApi/Bunny.WebApi.csproj
+++ b/Bunny.WebApi/Bunny.WebApi.csproj
@@ -27,6 +27,8 @@
+
+
diff --git a/Bunny.WebApi/Config/JsonDateTimeConverter.cs b/Bunny.WebApi/Config/JsonDateTimeConverter.cs
deleted file mode 100644
index 2ce19b4..0000000
--- a/Bunny.WebApi/Config/JsonDateTimeConverter.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-using System.Text.Json;
-using System.Text.Json.Serialization;
-
-namespace Bunny.WebApi.Config;
-
-public class JsonDateTimeConverter : JsonConverter
-{
- public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
- {
- return DateTime.TryParse(reader.GetString(), out var date) ? date : default;
- }
-
- public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
- {
- writer.WriteStringValue(value.ToString("yyyy-MM-dd HH:mm:ss"));
- }
-}
\ No newline at end of file
diff --git a/Bunny.WebApi/Configuration/AddAutofacConfig.cs b/Bunny.WebApi/Configuration/AddAutofacConfig.cs
new file mode 100644
index 0000000..4bc4d61
--- /dev/null
+++ b/Bunny.WebApi/Configuration/AddAutofacConfig.cs
@@ -0,0 +1,32 @@
+using Autofac;
+using Bunny.Common.Context;
+using Bunny.Service.IService;
+using Bunny.Service.IService.Service;
+using Microsoft.AspNetCore.Mvc;
+
+namespace Bunny.WebApi.Configuration;
+
+public static class AddAutofacConfig
+{
+ public static void BuildContainer(ContainerBuilder builder)
+ {
+ // 异步方式创建数据库
+ new EfCoreContext().Database.EnsureCreatedAsync();
+
+ // 如果不在在 Controller 层写构造函数可以打开这个,自动完成注入
+ var controllerBaseType = typeof(ControllerBase);
+ builder.RegisterAssemblyTypes(typeof(Program).Assembly)
+ .Where(t => controllerBaseType.IsAssignableFrom(t) && t != controllerBaseType)
+ .PropertiesAutowired(); //支持属性注入
+
+ // 注入EfCore上下文对象
+ builder.RegisterType();
+
+ // 注入Service服务
+ builder.RegisterType().As();
+ builder.RegisterType().As();
+ builder.RegisterType().As();
+ builder.RegisterType().As();
+ builder.RegisterType().As();
+ }
+}
\ No newline at end of file
diff --git a/Bunny.WebApi/Config/BaseConfig.cs b/Bunny.WebApi/Configuration/BaseConfig.cs
similarity index 65%
rename from Bunny.WebApi/Config/BaseConfig.cs
rename to Bunny.WebApi/Configuration/BaseConfig.cs
index c05ccbb..7b3bb6d 100644
--- a/Bunny.WebApi/Config/BaseConfig.cs
+++ b/Bunny.WebApi/Configuration/BaseConfig.cs
@@ -1,8 +1,12 @@
-using Bunny.Common;
-using Bunny.Common.Connect;
+using Autofac;
+using Autofac.Extensions.DependencyInjection;
+using Bunny.Common;
+using Bunny.Common.Context;
using Bunny.Service.WebSocket;
+using Microsoft.AspNetCore.Mvc.Controllers;
+using Microsoft.Extensions.DependencyInjection.Extensions;
-namespace Bunny.WebApi.Config;
+namespace Bunny.WebApi.Configuration;
public class BaseConfig(WebApplicationBuilder builder)
{
@@ -14,25 +18,24 @@ public class BaseConfig(WebApplicationBuilder builder)
// 配置跨域
UseCors();
// 配置日志相关
- // builder.Logging.AddLog4Net("Config/log4net.config");
+ // builder.Logging.AddLog4Net("Configuration/log4net.config");
+ // 自定义时间格式
+ builder.Services.AddControllers().AddJsonOptions(options =>
+ options.JsonSerializerOptions.Converters.Add(new JsonDateTimeConverter()));
// 添加使用自定义配置文件
builder.Services.AddSingleton(new AppSettings(builder.Configuration));
- // 添加 SignalR
- builder.Services.AddSignalR();
- builder.WebHost.ConfigureKestrel((context, options) =>
+ builder.WebHost.ConfigureKestrel((_, options) =>
{
// 设置文件最大上传大小
options.Limits.MaxRequestBodySize = 1024 * 1024 * 100;
});
- // 注入后台服务
- builder.AddApplicationServices();
- // 设置控制器返回时间,统一格式
- builder.Services.AddControllers().AddJsonOptions(options =>
- options.JsonSerializerOptions.Converters.Add(new JsonDateTimeConverter()));
- // 添加后台服务
+ // 使用 AddAutofac 注册服务
+ builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
+ builder.Host.ConfigureContainer(AddAutofacConfig.BuildContainer);
+ // 让控制器实例由容器创建
+ builder.Services.Replace(ServiceDescriptor.Transient());
+ // 添加定时任务
builder.AddApplicationBackendServices();
- // 添加验证码
- builder.AddCaptcha();
// 设置过滤器
builder.AddFilterConfigInitialize();
// 初始化Redis
@@ -43,6 +46,8 @@ public class BaseConfig(WebApplicationBuilder builder)
builder.AddKnife4Net();
// 启动 webSocket
builder.AddWebSocketInitial();
+ // 添加验证码
+ builder.AddCaptcha();
}
///
diff --git a/Bunny.WebApi/Config/Knife4Net.cs b/Bunny.WebApi/Configuration/Knife4Net.cs
similarity index 96%
rename from Bunny.WebApi/Config/Knife4Net.cs
rename to Bunny.WebApi/Configuration/Knife4Net.cs
index 4272698..9187af2 100644
--- a/Bunny.WebApi/Config/Knife4Net.cs
+++ b/Bunny.WebApi/Configuration/Knife4Net.cs
@@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.OpenApi.Models;
-namespace Bunny.WebApi.Config;
+namespace Bunny.WebApi.Configuration;
public static class Knife4Net
{
diff --git a/Bunny.WebApi/Config/ServiceRegistration.cs b/Bunny.WebApi/Configuration/ServiceRegistration.cs
similarity index 78%
rename from Bunny.WebApi/Config/ServiceRegistration.cs
rename to Bunny.WebApi/Configuration/ServiceRegistration.cs
index 770f699..0ea49ad 100644
--- a/Bunny.WebApi/Config/ServiceRegistration.cs
+++ b/Bunny.WebApi/Configuration/ServiceRegistration.cs
@@ -1,30 +1,14 @@
-using Bunny.Common.Connect;
-using Bunny.Common.Filter;
+using Bunny.Common.Filter;
using Bunny.Service.Filter;
-using Bunny.Service.IService;
-using Bunny.Service.IService.Service;
using Bunny.Service.Job.JobService;
using Lazy.Captcha.Core;
using Lazy.Captcha.Core.Generator;
using SkiaSharp;
-namespace Bunny.WebApi.Config;
+namespace Bunny.WebApi.Configuration;
public static class ServiceRegistration
{
- public static void AddApplicationServices(this WebApplicationBuilder builder)
- {
- // 注入EfCore上下文对象
- builder.Services.AddScoped();
-
- // 注入Service服务
- builder.Services.AddScoped();
- builder.Services.AddScoped();
- builder.Services.AddScoped();
- builder.Services.AddScoped();
- builder.Services.AddScoped();
- }
-
///