diff --git a/Bunny.Common/EFCore/EFCoreContext.cs b/Bunny.Common/EFCore/EFCoreContext.cs index 1a7c9b0..6072fda 100644 --- a/Bunny.Common/EFCore/EFCoreContext.cs +++ b/Bunny.Common/EFCore/EFCoreContext.cs @@ -7,7 +7,7 @@ public class EfCoreContext : DbContext { public EfCoreContext() { - DbPath = @"D:\Project\web\Bunny-Cli\template\CSharp\CSharp-Single-EFCore\Bunny.WebApi\Database\bunny.db"; + DbPath = @"D:\MyFolder\Bunny\Bunny-cli\Template\CSharp\CSharp-Single-EFCore\Bunny.WebApi\Database\bunny.db"; // var dataBaseConnection = AppSettings.GetAppConfig("DataBase:DataBaseConnection"); // DbPath = dataBaseConnection; } diff --git a/Bunny.Common/Migrations/20240809011221_InitialCreate.Designer.cs b/Bunny.Common/Migrations/20240809011221_InitialCreate.Designer.cs new file mode 100644 index 0000000..2b268e8 --- /dev/null +++ b/Bunny.Common/Migrations/20240809011221_InitialCreate.Designer.cs @@ -0,0 +1,173 @@ +// +using System; +using Bunny.Common.EFCore; +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 new file mode 100644 index 0000000..04f8424 --- /dev/null +++ b/Bunny.Common/Migrations/20240809011221_InitialCreate.cs @@ -0,0 +1,117 @@ +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/EfCoreContextModelSnapshot.cs b/Bunny.Common/Migrations/EfCoreContextModelSnapshot.cs new file mode 100644 index 0000000..20a9ea3 --- /dev/null +++ b/Bunny.Common/Migrations/EfCoreContextModelSnapshot.cs @@ -0,0 +1,170 @@ +// +using System; +using Bunny.Common.EFCore; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Bunny.Common.Migrations +{ + [DbContext(typeof(EfCoreContext))] + partial class EfCoreContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(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.Dao/Models/Base/BaseModel.cs b/Bunny.Dao/Models/Base/BaseModel.cs index e358d9b..cb95a69 100644 --- a/Bunny.Dao/Models/Base/BaseModel.cs +++ b/Bunny.Dao/Models/Base/BaseModel.cs @@ -12,8 +12,4 @@ public class BaseModel public long CreateUserId { get; set; } public long UpdateUserId { get; set; } - - public string? OperationMessage { get; set; } - - public bool IsDelete { get; set; } } \ No newline at end of file diff --git a/Bunny.Dao/Models/System/Blog.cs b/Bunny.Dao/Models/System/Blog.cs index 3fd5e18..e07164d 100644 --- a/Bunny.Dao/Models/System/Blog.cs +++ b/Bunny.Dao/Models/System/Blog.cs @@ -4,6 +4,5 @@ namespace Bunny.Dao.Models.System; public class Blog : BaseModel { - public int BlogId { get; set; } public string Url { get; set; } } \ No newline at end of file diff --git a/Bunny.Service/IService/IBlogService.cs b/Bunny.Service/IService/IBlogService.cs index 7f80cd3..6800f5e 100644 --- a/Bunny.Service/IService/IBlogService.cs +++ b/Bunny.Service/IService/IBlogService.cs @@ -9,4 +9,22 @@ public interface IBlogService /// /// void AddBlog(Blog dto); + + /// + /// 查询BLog + /// + /// + List QueryBlog(); + + /// + /// 更新Blog内容 + /// + /// + void UpdateBlog(Blog dto); + + /// + /// 删除BLog + /// + /// + void DeleteBlog(string id); } \ No newline at end of file diff --git a/Bunny.Service/IService/Service/BlogService.cs b/Bunny.Service/IService/Service/BlogService.cs index 00d2705..5ff4768 100644 --- a/Bunny.Service/IService/Service/BlogService.cs +++ b/Bunny.Service/IService/Service/BlogService.cs @@ -22,4 +22,34 @@ public class BlogService : IBlogService _dbContext.Add(dto); _dbContext.SaveChanges(); } + + /// + /// 查询BLog + /// + /// + public List QueryBlog() + { + return _dbContext.Blogs.ToList(); + } + + /// + /// 更新Blog内容 + /// + /// + public void UpdateBlog(Blog dto) + { + _dbContext.Blogs.Update(dto); + _dbContext.SaveChanges(); + } + + /// + /// 删除BLog + /// + /// + public void DeleteBlog(string id) + { + var blog = new Blog { Id = id }; + _dbContext.Blogs.Remove(blog); + _dbContext.SaveChanges(); + } } \ No newline at end of file diff --git a/Bunny.Test.Until/EfCoreTest/EfCoreTest.cs b/Bunny.Test.Until/EfCoreTest/EfCoreTest.cs index 98ff862..69e031f 100644 --- a/Bunny.Test.Until/EfCoreTest/EfCoreTest.cs +++ b/Bunny.Test.Until/EfCoreTest/EfCoreTest.cs @@ -20,7 +20,7 @@ public class EfCoreTest // Read Console.WriteLine("Querying for a blog"); var blog = db.Blogs - .OrderBy(b => b.BlogId) + .OrderBy(b => b.Id) .First(); Console.WriteLine(blog.Url); } diff --git a/Bunny.WebApi/Controllers/BlogController.cs b/Bunny.WebApi/Controllers/BlogController.cs index 6135afa..13ea09c 100644 --- a/Bunny.WebApi/Controllers/BlogController.cs +++ b/Bunny.WebApi/Controllers/BlogController.cs @@ -5,6 +5,9 @@ using Microsoft.AspNetCore.Mvc; namespace Bunny.WebApi.Controllers; +/// +/// BLog相关接口 +/// [Route("/api/[controller]")] public class BlogController : ControllerBase { @@ -26,4 +29,38 @@ public class BlogController : ControllerBase _blogService.AddBlog(dto); return Result.Success(); } + + /// + /// 查询BLog + /// + /// + [HttpGet("QueryBlog")] + public Result> QueryBlog() + { + var vo = _blogService.QueryBlog(); + return Result>.Success(vo); + } + + /// + /// 更新Blog内容 + /// + /// + /// + [HttpGet("UpdateBlog")] + public Result UpdateBlog(Blog dto) + { + _blogService.UpdateBlog(dto); + return Result.Success(); + } + + /// + /// 删除BLog + /// + /// + [HttpDelete("DeleteBlog")] + public Result DeleteBlog(string id) + { + _blogService.DeleteBlog(id); + return Result.Success(); + } } \ No newline at end of file diff --git a/Bunny.WebApi/Database/bunny.db b/Bunny.WebApi/Database/bunny.db new file mode 100644 index 0000000..83b1211 Binary files /dev/null and b/Bunny.WebApi/Database/bunny.db differ diff --git a/Bunny.WebApi/Database/bunny.db-shm b/Bunny.WebApi/Database/bunny.db-shm new file mode 100644 index 0000000..aea5578 Binary files /dev/null and b/Bunny.WebApi/Database/bunny.db-shm differ diff --git a/Bunny.WebApi/Database/bunny.db-wal b/Bunny.WebApi/Database/bunny.db-wal new file mode 100644 index 0000000..484dd66 Binary files /dev/null and b/Bunny.WebApi/Database/bunny.db-wal differ