diff --git "a/\350\256\270\346\242\246\345\251\267/2021-6-22.md" "b/\350\256\270\346\242\246\345\251\267/2021-6-22.md" new file mode 100644 index 0000000000000000000000000000000000000000..aa35f09b6c15ecaf1c2775e6559dde4851e4cc9f --- /dev/null +++ "b/\350\256\270\346\242\246\345\251\267/2021-6-22.md" @@ -0,0 +1,9 @@ + +今日份课堂笔记 + +2021-6-22 星期二 +创建解决方案:dotnet new sln + +将项目添加到解决方案:dotnet sln add MyApi.Api + +运行:dotnet run diff --git "a/\350\256\270\346\242\246\345\251\267/2021-6-23.md" "b/\350\256\270\346\242\246\345\251\267/2021-6-23.md" new file mode 100644 index 0000000000000000000000000000000000000000..b44ace29e9357dd8b61386a3478a6ce756c26830 --- /dev/null +++ "b/\350\256\270\346\242\246\345\251\267/2021-6-23.md" @@ -0,0 +1,212 @@ +今日份课堂笔记 + +2021-6-23 星期三 + +1.创建解决方案:dotnet new sln + +2.创建webapi文件:dotnet new webapi -n Admin3000.Backend.Api --no-https + +3.不进入文件夹进行运行:dotnet run -p Admin3000.Backend.Api (如果进入文件夹可直接 dotnet run) + +4.将项目添加到解决方案中:dotnet sln add Admin3000.Backend.Api + +5.下载以下插件 + +![avater](./imgs/2021-6-23-001.PNG) +![avater](./imgs/2021-6-23-002.PNG) +![avater](./imgs/2021-6-23-003.PNG) + +``` +api.http中: + +### +GET http://localhost:5000/users HTTP/1.1 + +UsersController.cs中: + +using Microsoft.AspNetCore.Mvc; +namespace Admin300.Backend.Controllers +{ + [ApiController] + [Route("[controller]")] + public class UsersController : ControllerBase + { + [HttpGet] + public dynamic Get() + { + return"恭喜发财"; + } + } +} +``` +结果如图: + +![avater](./imgs/2021-6-23-004.PNG) + +``` +api.http中: + +### +GET http://localhost:5000/users HTTP/1.1 + +Entity文件夹中Users.cs: + +using System; +namespace Admin3000.Backend.Api.Entity +{ + public class Users + { + public Users(){ + CreatedTime=DateTime.Now; + UpdatedTime=DateTime.Now; + Remarks=""; + } + public int Id {get;set;} + public string Username {get;set;} + public string Password{get;set;} + public DateTime CreatedTime{get;set;} + public DateTime UpdatedTime{get;set;} + public string Remarks{get;set;} + } +} +``` +结果如图: + +![avater](./imgs/2021-6-23-005.PNG) + +

增删改查

+ + +UsersController.cs中: +``` +using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; +using Admin3000.Backend.Api.Entity; +using System.Linq; + + +namespace Admin300.Backend.Controllers +{ + [ApiController] + [Route("[controller]")] + public class UsersController : ControllerBase + { + [HttpGet] + public dynamic Get() + { + var users = GetUsers(); + return users; + } + [HttpGet("{id}")] + public dynamic Get(int id) + { + var users = GetUsers(); + var user = users.Where(x => x.Id == id).FirstOrDefault(); + return user; + } + [HttpPost] + public dynamic Post(dynamic model) + { + + return new + { + Code = 1000, + Data = model, + Msg = "创建用户成功" + }; + } + [HttpPut("{id}")] + public dynamic put(int id, dynamic model) + { + return new + { + Code = 1000, + Data = model, + Msg = string.Format("你修改的用户id为:{0},已经成功", id) + }; + } + [HttpDelete("{id}")] + public dynamic Delete(int id) + { + return new + { + Code = 1000, + Msg = string.Format("删除指定id为:{0}的用户已经成功", id) + }; + } + private IEnumerable GetUsers() + { + var users = new List{ + new Users{ + Id=1, + Username="小明", + Password="123" + }, new Users{ + Id=2, + Username="小王", + Password="123" + }, new Users{ + Id=3, + Username="小李", + Password="123" + }, + }; + return users; + } + } +} +``` +api.http中: + +``` +###获取用户列表 +GET http://localhost:5000/users HTTP/1.1 + +###获取指定ID的用户 +GET http://localhost:5000/users/3 HTTP/1.1 + +###创建用户 +POST http://localhost:5000/users HTTP/1.1 +Content-Type: application/json + +{ + "username":"小林", + "password":"222" +} + +###修改指定用户 + +PUT http://localhost:5000/users/1 HTTP/1.1 +Content-Type: application/json + +{ + "username":"小林", + "password":"222" +} + +###删除指定用户 +DELETE http://localhost:5000/users/1 HTTP/1.1 +``` + +users.cs中: + +``` +using System; +namespace Admin3000.Backend.Api.Entity +{ + public class Users + { + public Users(){ + CreatedTime=DateTime.Now; + UpdatedTime=DateTime.Now; + Remarks=""; + } + public int Id {get;set;} + public string Username {get;set;} + public string Password{get;set;} + public DateTime CreatedTime{get;set;} + public DateTime UpdatedTime{get;set;} + public string Remarks{get;set;} + } +} +``` \ No newline at end of file diff --git "a/\350\256\270\346\242\246\345\251\267/2021-6-26.md" "b/\350\256\270\346\242\246\345\251\267/2021-6-26.md" new file mode 100644 index 0000000000000000000000000000000000000000..5053ee77a3f801f6ad035c407c80a29683310558 --- /dev/null +++ "b/\350\256\270\346\242\246\345\251\267/2021-6-26.md" @@ -0,0 +1,23 @@ +今日份课堂笔记 + +2021-6-26 星期六 + +

EF Core

+ +``` +//配置时具有路径 + protected override void OnConfiguring(DbContextOptionsBuilder options) + => options.UseSqlite(@"Data Source=C:\blogging.db"); +``` +

安装 Entity Framework Core

+ +dotnet add package Microsoft.EntityFrameworkCore.Sqlserver + +

创建数据库

+ +dotnet tool install --global dotnet-ef +dotnet add package Microsoft.EntityFrameworkCore.Design + +

添加实体

+ +dotnet ef migrations add 添加一个用户实体 \ No newline at end of file diff --git "a/\350\256\270\346\242\246\345\251\267/2021-6-29.md" "b/\350\256\270\346\242\246\345\251\267/2021-6-29.md" new file mode 100644 index 0000000000000000000000000000000000000000..6d5f8a48b0aab2d63178703a74b3d9978c8e114b --- /dev/null +++ "b/\350\256\270\346\242\246\345\251\267/2021-6-29.md" @@ -0,0 +1,71 @@ +今日份课堂笔记 + +2021-6-29 星期二 + +``` +dotnet ef database update更新 +``` +

重新抽象了实体的共有属性

+ +BaseEntity.cs中: +``` +using System; +namespace Admin3000.Backend.Api.Entity +{ + //abstract只能被继承,不能被初始化 + public abstract class BaseEntity + { + public int Id {get;set;} + public bool IsActived { get; set;} + public bool IsDeleted { get; set;} + public DateTime CreateTime{ get; set;} + public int DisplayOrder{ get; set;} + public String Remarks{ get; set;} + public DateTime UpdatedTime{ get; set;} + } +} +``` +Roles.cs中: +``` +using System; +namespace Admin3000.Backend.Api.Entity +{ + public class Roles:BaseEntity{ + public string RoleName{ get; set;} + } +} +``` +UserRoles.cs中: +``` +using System; +namespace Admin3000.Backend.Api.Entity +{ + public class UserRoles:BaseEntity{ + public string UserId{ get; set;} + public string RoleId{ get; set;} + } +} +``` +Users.cs中: +``` +using System; +namespace Admin3000.Backend.Api.Entity +{ + public class Users:BaseEntity{ + public string Username{ get ; set;} + public string Password { get; set;} + } +} +``` +

尝试让其建立主外键关系

+ +``` +Users.cs和Roles.cs中添加: +public virtual IEnumerable UserRoles { get; set; } + +UserRoles中添加: +public virtual Users User{get;set;} +public virtual Roles Role{get;set;} +``` + +![avater](./imgs/2021-6-29-001.PNG) \ No newline at end of file diff --git "a/\350\256\270\346\242\246\345\251\267/2021-7-02.md" "b/\350\256\270\346\242\246\345\251\267/2021-7-02.md" new file mode 100644 index 0000000000000000000000000000000000000000..c0e446e18e9c7e031563eeac484accbfcdf53be4 --- /dev/null +++ "b/\350\256\270\346\242\246\345\251\267/2021-7-02.md" @@ -0,0 +1,3 @@ +今日份课堂笔记 + +2021-7-2 星期五 \ No newline at end of file diff --git "a/\350\256\270\346\242\246\345\251\267/2021-7-03.md" "b/\350\256\270\346\242\246\345\251\267/2021-7-03.md" new file mode 100644 index 0000000000000000000000000000000000000000..d5a45cb1d3b221d9908013d4687fb44c05368e98 --- /dev/null +++ "b/\350\256\270\346\242\246\345\251\267/2021-7-03.md" @@ -0,0 +1,6 @@ +今日份课堂笔记 + +2021-7-3 星期六 +![avater](./imgs/2021-7-3-001.PNG) +![avater](./imgs/2021-7-3-002.PNG) +![avater](./imgs/2021-7-3-003.PNG) \ No newline at end of file diff --git "a/\350\256\270\346\242\246\345\251\267/imgs/2021-6-23-001.PNG" "b/\350\256\270\346\242\246\345\251\267/imgs/2021-6-23-001.PNG" new file mode 100644 index 0000000000000000000000000000000000000000..68e66ff490def07e08fd044b553fc78eb44e0b80 Binary files /dev/null and "b/\350\256\270\346\242\246\345\251\267/imgs/2021-6-23-001.PNG" differ diff --git "a/\350\256\270\346\242\246\345\251\267/imgs/2021-6-23-002.PNG" "b/\350\256\270\346\242\246\345\251\267/imgs/2021-6-23-002.PNG" new file mode 100644 index 0000000000000000000000000000000000000000..ea3b746a7be323c04edfba8abb6ac27265656bdb Binary files /dev/null and "b/\350\256\270\346\242\246\345\251\267/imgs/2021-6-23-002.PNG" differ diff --git "a/\350\256\270\346\242\246\345\251\267/imgs/2021-6-23-003.PNG" "b/\350\256\270\346\242\246\345\251\267/imgs/2021-6-23-003.PNG" new file mode 100644 index 0000000000000000000000000000000000000000..2d8b6382b673bbda53b6405eee9fd11bccb999f5 Binary files /dev/null and "b/\350\256\270\346\242\246\345\251\267/imgs/2021-6-23-003.PNG" differ diff --git "a/\350\256\270\346\242\246\345\251\267/imgs/2021-6-23-004.PNG" "b/\350\256\270\346\242\246\345\251\267/imgs/2021-6-23-004.PNG" new file mode 100644 index 0000000000000000000000000000000000000000..89f34d7ad1e6423cfb9ff443139001352ed47693 Binary files /dev/null and "b/\350\256\270\346\242\246\345\251\267/imgs/2021-6-23-004.PNG" differ diff --git "a/\350\256\270\346\242\246\345\251\267/imgs/2021-6-23-005.PNG" "b/\350\256\270\346\242\246\345\251\267/imgs/2021-6-23-005.PNG" new file mode 100644 index 0000000000000000000000000000000000000000..894a8943816232169a7c957cca52ab3af4be9a88 Binary files /dev/null and "b/\350\256\270\346\242\246\345\251\267/imgs/2021-6-23-005.PNG" differ diff --git "a/\350\256\270\346\242\246\345\251\267/imgs/2021-6-29-001.PNG" "b/\350\256\270\346\242\246\345\251\267/imgs/2021-6-29-001.PNG" new file mode 100644 index 0000000000000000000000000000000000000000..2dca24239a8d9952e007bc446de922d1b831e053 Binary files /dev/null and "b/\350\256\270\346\242\246\345\251\267/imgs/2021-6-29-001.PNG" differ diff --git "a/\350\256\270\346\242\246\345\251\267/imgs/2021-7-3-001.PNG" "b/\350\256\270\346\242\246\345\251\267/imgs/2021-7-3-001.PNG" new file mode 100644 index 0000000000000000000000000000000000000000..a149218ccd0e5b046788d7fd739053957a2f1be4 Binary files /dev/null and "b/\350\256\270\346\242\246\345\251\267/imgs/2021-7-3-001.PNG" differ diff --git "a/\350\256\270\346\242\246\345\251\267/imgs/2021-7-3-002.PNG" "b/\350\256\270\346\242\246\345\251\267/imgs/2021-7-3-002.PNG" new file mode 100644 index 0000000000000000000000000000000000000000..f8d73a9337a9b8b2c029b715103985995bdffcac Binary files /dev/null and "b/\350\256\270\346\242\246\345\251\267/imgs/2021-7-3-002.PNG" differ diff --git "a/\350\256\270\346\242\246\345\251\267/imgs/2021-7-3-003.PNG" "b/\350\256\270\346\242\246\345\251\267/imgs/2021-7-3-003.PNG" new file mode 100644 index 0000000000000000000000000000000000000000..22e3c1775da3feba3d70b1919d930032e15026a2 Binary files /dev/null and "b/\350\256\270\346\242\246\345\251\267/imgs/2021-7-3-003.PNG" differ