From ea78be46be34617cfa53d491e337778bf13d880f Mon Sep 17 00:00:00 2001 From: yb <1728066681@qq.com> Date: Wed, 23 Jun 2021 17:47:13 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E7=AC=AC=E4=BA=8C=E6=AC=A1webapi=E6=8F=90?= =?UTF-8?q?=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...t \345\221\275\344\273\244\357\274\211.md" | 0 .../Web.Api/.vscode/launch.json" | 17 +++++++ .../Web.Api/Web.Api.sln" | 34 +++++++++++++ .../Web.Api/Controllers/UsersController.cs" | 51 +++++++++++++++++++ .../Controllers/WeatherForecastController.cs" | 39 ++++++++++++++ .../Web.Api/Web.Api/Entity/Users.cs" | 17 +++++++ .../Web.Api/Web.Api/Program.cs" | 26 ++++++++++ .../Web.Api/Properties/launchSettings.json" | 30 +++++++++++ .../Web.Api/Web.Api/Startup.cs" | 48 +++++++++++++++++ .../Web.Api/Web.Api/WeatherForecast.cs" | 15 ++++++ .../Web.Api/Web.Api/Web.Api.csproj" | 8 +++ .../Web.Api/appsettings.Development.json" | 9 ++++ .../Web.Api/Web.Api/appsettings.json" | 10 ++++ .../Web.Api/api.http" | 16 ++++++ 14 files changed, 320 insertions(+) rename "\346\242\201\350\211\272\347\274\244/Vue - 2021.06.19\357\274\210V dotnet \345\221\275\344\273\244\357\274\211.md" => "\346\242\201\350\211\272\347\274\244/Vue - 2021.06.22\357\274\210V dotnet \345\221\275\344\273\244\357\274\211.md" (100%) create mode 100644 "\346\242\201\350\211\272\347\274\244/Web.Api/.vscode/launch.json" create mode 100644 "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api.sln" create mode 100644 "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Controllers/UsersController.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Controllers/WeatherForecastController.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Entity/Users.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Program.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Properties/launchSettings.json" create mode 100644 "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Startup.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/WeatherForecast.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Web.Api.csproj" create mode 100644 "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/appsettings.Development.json" create mode 100644 "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/appsettings.json" create mode 100644 "\346\242\201\350\211\272\347\274\244/Web.Api/api.http" diff --git "a/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.19\357\274\210V dotnet \345\221\275\344\273\244\357\274\211.md" "b/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.22\357\274\210V dotnet \345\221\275\344\273\244\357\274\211.md" similarity index 100% rename from "\346\242\201\350\211\272\347\274\244/Vue - 2021.06.19\357\274\210V dotnet \345\221\275\344\273\244\357\274\211.md" rename to "\346\242\201\350\211\272\347\274\244/Vue - 2021.06.22\357\274\210V dotnet \345\221\275\344\273\244\357\274\211.md" diff --git "a/\346\242\201\350\211\272\347\274\244/Web.Api/.vscode/launch.json" "b/\346\242\201\350\211\272\347\274\244/Web.Api/.vscode/launch.json" new file mode 100644 index 0000000..2ef4b09 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/Web.Api/.vscode/launch.json" @@ -0,0 +1,17 @@ +{ + // 使用 IntelliSense 了解相关属性。 + // 悬停以查看现有属性的描述。 + // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "pwa-node", + "request": "launch", + "name": "Launch Program", + "skipFiles": [ + "/**" + ], + "program": "${file}" + } + ] +} \ No newline at end of file diff --git "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api.sln" "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api.sln" new file mode 100644 index 0000000..2525f92 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api.sln" @@ -0,0 +1,34 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26124.0 +MinimumVisualStudioVersion = 15.0.26124.0 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Web.Api", "Web.Api\Web.Api.csproj", "{2FEFD2BA-1065-4863-ABBD-9DF4DDBEBE72}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2FEFD2BA-1065-4863-ABBD-9DF4DDBEBE72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2FEFD2BA-1065-4863-ABBD-9DF4DDBEBE72}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2FEFD2BA-1065-4863-ABBD-9DF4DDBEBE72}.Debug|x64.ActiveCfg = Debug|Any CPU + {2FEFD2BA-1065-4863-ABBD-9DF4DDBEBE72}.Debug|x64.Build.0 = Debug|Any CPU + {2FEFD2BA-1065-4863-ABBD-9DF4DDBEBE72}.Debug|x86.ActiveCfg = Debug|Any CPU + {2FEFD2BA-1065-4863-ABBD-9DF4DDBEBE72}.Debug|x86.Build.0 = Debug|Any CPU + {2FEFD2BA-1065-4863-ABBD-9DF4DDBEBE72}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2FEFD2BA-1065-4863-ABBD-9DF4DDBEBE72}.Release|Any CPU.Build.0 = Release|Any CPU + {2FEFD2BA-1065-4863-ABBD-9DF4DDBEBE72}.Release|x64.ActiveCfg = Release|Any CPU + {2FEFD2BA-1065-4863-ABBD-9DF4DDBEBE72}.Release|x64.Build.0 = Release|Any CPU + {2FEFD2BA-1065-4863-ABBD-9DF4DDBEBE72}.Release|x86.ActiveCfg = Release|Any CPU + {2FEFD2BA-1065-4863-ABBD-9DF4DDBEBE72}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Controllers/UsersController.cs" "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Controllers/UsersController.cs" new file mode 100644 index 0000000..c938a0e --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Controllers/UsersController.cs" @@ -0,0 +1,51 @@ +using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; +using Web.Api.Entity; +using System.Linq; + +namespace Web.Api.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("{id}")] + public dynamic Post(dynamic model){ + return new { + Code = 2000, + Date = model, + Msg = "土笨笨", + }; + } + public IEnumerable GetUsers(){ + var users = new List{ + new Users{ + Id=1, + Username="good", + Password="lisa" + }, + new Users{ + Id=2, + Username="good", + Password="nice" + }, + new Users{ + Id=3, + Username="good", + Password="wdnbd" + }, + }; + return users; + } + } +} \ No newline at end of file diff --git "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Controllers/WeatherForecastController.cs" "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Controllers/WeatherForecastController.cs" new file mode 100644 index 0000000..3b56fb4 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Controllers/WeatherForecastController.cs" @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; + +namespace Web.Api.Controllers +{ + [ApiController] + [Route("[controller]")] + public class WeatherForecastController : ControllerBase + { + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet] + public IEnumerable Get() + { + var rng = new Random(); + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateTime.Now.AddDays(index), + TemperatureC = rng.Next(-20, 55), + Summary = Summaries[rng.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} diff --git "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Entity/Users.cs" "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Entity/Users.cs" new file mode 100644 index 0000000..9a7404e --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Entity/Users.cs" @@ -0,0 +1,17 @@ +using System; +namespace Web.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/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Program.cs" "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Program.cs" new file mode 100644 index 0000000..11cd3c8 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Program.cs" @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace Web.Api +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Properties/launchSettings.json" "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Properties/launchSettings.json" new file mode 100644 index 0000000..e36e127 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Properties/launchSettings.json" @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:42799", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Web.Api": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "applicationUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Startup.cs" "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Startup.cs" new file mode 100644 index 0000000..df11904 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Startup.cs" @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace Web.Api +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + services.AddControllers(); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/WeatherForecast.cs" "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/WeatherForecast.cs" new file mode 100644 index 0000000..699931c --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/WeatherForecast.cs" @@ -0,0 +1,15 @@ +using System; + +namespace Web.Api +{ + public class WeatherForecast + { + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string Summary { get; set; } + } +} diff --git "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Web.Api.csproj" "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Web.Api.csproj" new file mode 100644 index 0000000..d12c450 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Web.Api.csproj" @@ -0,0 +1,8 @@ + + + + netcoreapp3.1 + + + + diff --git "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/appsettings.Development.json" "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/appsettings.Development.json" new file mode 100644 index 0000000..8983e0f --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/appsettings.Development.json" @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/appsettings.json" "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/appsettings.json" new file mode 100644 index 0000000..d9d9a9b --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/appsettings.json" @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} diff --git "a/\346\242\201\350\211\272\347\274\244/Web.Api/api.http" "b/\346\242\201\350\211\272\347\274\244/Web.Api/api.http" new file mode 100644 index 0000000..9988738 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/Web.Api/api.http" @@ -0,0 +1,16 @@ +###获取用户列表 +GET http://localhost:5000/users HTTP/1.1 + + +###获取指定ID用户 +GET http://localhost:5000/users3 HTTP/1.1 + + +###创建用户 +POST http://localhost:5000/users HTTP/1.1 +Content-Type: application/json + +{ + "username":"good", + "password":"土笨笨" +} \ No newline at end of file -- Gitee From bd3ddebe0f4bd0b68e1768a24fb179e16517357e Mon Sep 17 00:00:00 2001 From: yb <1728066681@qq.com> Date: Sat, 26 Jun 2021 17:46:57 +0800 Subject: [PATCH 2/9] Ef Core --- ...t \345\221\275\344\273\244\357\274\211.md" | 0 ...1.06.26\357\274\210EF Core\357\274\211.md" | 63 +++++++++++++++++++ .../Web.Api/.vscode/launch.json" | 17 ----- .../Web.Api/Controllers/UsersController.cs" | 17 ++++- .../Web.Api/Web.Api/Date/Admin3000Db.cs" | 0 .../Web.Api/Web.Api/Startup.cs" | 2 +- .../Web.Api/Web.Api/Web.Api.csproj" | 5 ++ .../Web.Api/api.http" | 4 +- 8 files changed, 87 insertions(+), 21 deletions(-) create mode 100644 "\346\242\201\350\211\272\347\274\244/Vue - 2021.06.23\357\274\210V dotnet \345\221\275\344\273\244\357\274\211.md" create mode 100644 "\346\242\201\350\211\272\347\274\244/Vue - 2021.06.26\357\274\210EF Core\357\274\211.md" delete mode 100644 "\346\242\201\350\211\272\347\274\244/Web.Api/.vscode/launch.json" create mode 100644 "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Date/Admin3000Db.cs" diff --git "a/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.23\357\274\210V dotnet \345\221\275\344\273\244\357\274\211.md" "b/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.23\357\274\210V dotnet \345\221\275\344\273\244\357\274\211.md" new file mode 100644 index 0000000..e69de29 diff --git "a/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.26\357\274\210EF Core\357\274\211.md" "b/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.26\357\274\210EF Core\357\274\211.md" new file mode 100644 index 0000000..3a16490 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.26\357\274\210EF Core\357\274\211.md" @@ -0,0 +1,63 @@ +# 安装 EF Core + +### 获取 Entity Framework Core 运行时 + +把EF Core添加到项目中,要使用的数据库提供程序的 NuGet 包 + +命名 +~~~html +dotnet add package Microsoft.EntityFrameworkCore.Sql数据库类型 +~~~ + +创建模型 + +``` +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; + +namespace EFGetStarted +{ + public class BloggingContext : DbContext + { + public DbSet Blogs { get; set; } + public DbSet Posts { get; set; } + + // The following configures EF to create a Sqlite database file as `C:\blogging.db`. + // For Mac or Linux, change this to `/tmp/blogging.db` or any other absolute path. + protected override void OnConfiguring(DbContextOptionsBuilder options) + => options.UseSqlite(@"Data Source=C:\blogging.db"); + } + + public class Blog + { + public int BlogId { get; set; } + public string Url { get; set; } + + public List Posts { get; } = new List(); + } + + public class Post + { + 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; } + } +} +``` +创建数据库 + ++ 以下步骤使用迁移创建数据库 + +命令 +``` +dotnet tool install --global dotnet-ef + +dotnet add package Microsoft.EntityFrameworkCore.Design + +dotnet ef migrations add InitialCreate + +dotnet ef database update +``` \ No newline at end of file diff --git "a/\346\242\201\350\211\272\347\274\244/Web.Api/.vscode/launch.json" "b/\346\242\201\350\211\272\347\274\244/Web.Api/.vscode/launch.json" deleted file mode 100644 index 2ef4b09..0000000 --- "a/\346\242\201\350\211\272\347\274\244/Web.Api/.vscode/launch.json" +++ /dev/null @@ -1,17 +0,0 @@ -{ - // 使用 IntelliSense 了解相关属性。 - // 悬停以查看现有属性的描述。 - // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "type": "pwa-node", - "request": "launch", - "name": "Launch Program", - "skipFiles": [ - "/**" - ], - "program": "${file}" - } - ] -} \ No newline at end of file diff --git "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Controllers/UsersController.cs" "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Controllers/UsersController.cs" index c938a0e..10625f7 100644 --- "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Controllers/UsersController.cs" +++ "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Controllers/UsersController.cs" @@ -24,9 +24,24 @@ namespace Web.Api.Controllers return new { Code = 2000, Date = model, - Msg = "土笨笨", + Msg = "成功", }; } + [HttpPut("{id}")] + public dynamic Put(int id, dynamic model){ + return new{ + Date = model, + Msg=string.Format("要修改的ID为{0},",id) + }; + } + [HttpDelete("{id}")] + public dynamic Delete(int id,dynamic model){ + return new{ + Date = model, + Msg=string.Format("要修改的ID为{0},",id) + }; + } + public IEnumerable GetUsers(){ var users = new List{ new Users{ diff --git "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Date/Admin3000Db.cs" "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Date/Admin3000Db.cs" new file mode 100644 index 0000000..e69de29 diff --git "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Startup.cs" "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Startup.cs" index df11904..009492d 100644 --- "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Startup.cs" +++ "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Startup.cs" @@ -23,7 +23,7 @@ namespace Web.Api // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) - { + { services.AddControllers(); } diff --git "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Web.Api.csproj" "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Web.Api.csproj" index d12c450..2efd60a 100644 --- "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Web.Api.csproj" +++ "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Web.Api.csproj" @@ -4,5 +4,10 @@ netcoreapp3.1 + + + + + diff --git "a/\346\242\201\350\211\272\347\274\244/Web.Api/api.http" "b/\346\242\201\350\211\272\347\274\244/Web.Api/api.http" index 9988738..a84c8d1 100644 --- "a/\346\242\201\350\211\272\347\274\244/Web.Api/api.http" +++ "b/\346\242\201\350\211\272\347\274\244/Web.Api/api.http" @@ -5,7 +5,6 @@ GET http://localhost:5000/users HTTP/1.1 ###获取指定ID用户 GET http://localhost:5000/users3 HTTP/1.1 - ###创建用户 POST http://localhost:5000/users HTTP/1.1 Content-Type: application/json @@ -13,4 +12,5 @@ Content-Type: application/json { "username":"good", "password":"土笨笨" -} \ No newline at end of file +} + -- Gitee From 3ea9e0620ba32c22d843e9293aaa62a873b987ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E8=89=BA=E7=BC=A4?= <1728066681@qq.com> Date: Mon, 28 Jun 2021 14:29:53 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E7=AC=94=E8=AE=B0=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...t \345\221\275\344\273\244\357\274\211.md" | 17 ++++++++++++ ...1.06.26\357\274\210EF Core\357\274\211.md" | 27 ++++++++++++++++--- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git "a/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.23\357\274\210V dotnet \345\221\275\344\273\244\357\274\211.md" "b/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.23\357\274\210V dotnet \345\221\275\344\273\244\357\274\211.md" index e69de29..8707d9c 100644 --- "a/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.23\357\274\210V dotnet \345\221\275\344\273\244\357\274\211.md" +++ "b/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.23\357\274\210V dotnet \345\221\275\344\273\244\357\274\211.md" @@ -0,0 +1,17 @@ +# 安装REST CLient 插件 + +## 控制器中用法 + +``` +// GET +[HttpGet("{id}")] + +// POST +[HttpPost] + +// PUT +[HttpPut("{id}")] + +// Delete +[HttpDelete("{id}")] +``` \ No newline at end of file diff --git "a/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.26\357\274\210EF Core\357\274\211.md" "b/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.26\357\274\210EF Core\357\274\211.md" index 3a16490..7a0a351 100644 --- "a/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.26\357\274\210EF Core\357\274\211.md" +++ "b/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.26\357\274\210EF Core\357\274\211.md" @@ -1,3 +1,5 @@ +# WebApi 连接数据库 + # 安装 EF Core ### 获取 Entity Framework Core 运行时 @@ -5,11 +7,28 @@ 把EF Core添加到项目中,要使用的数据库提供程序的 NuGet 包 命名 -~~~html -dotnet add package Microsoft.EntityFrameworkCore.Sql数据库类型 -~~~ +``` +// sqlserver/sqlite + +dotnet add package Microsoft.EntityFrameworkCore.Sql数据库类型(sqlserver/sqlite) +``` + +## 数据库迁移 +``` +// 安装dotnet-ef +dotnet tool install --global dotnet-ef + +// 安装EFCore.Design +dotnet add package Microsoft.EntityFrameworkCore.Design + +// 创建迁移,指示 EF Core 创建名为 InitialCreate 的迁移 +dotnet ef migrations add InitialCreate + +// 创建数据库和架构 +dotnet ef database update +``` -创建模型 +创建模型 Data 部分配置演示 ``` using System.Collections.Generic; -- Gitee From ba23020d56463b080952a41b28fffe81dbb0a21f Mon Sep 17 00:00:00 2001 From: yb <1728066681@qq.com> Date: Tue, 29 Jun 2021 10:26:50 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MyWebApi.Api/.vscode/launch.json" | 17 +++++ .../MyWebApi.Api/MyWebApi.Api.sln" | 16 ----- .../Controllers/UsersController.cs" | 68 +++++++++++-------- .../Controllers/WeatherForecastController.cs" | 2 +- .../MyWebApi.Api/Entity/Users.cs" | 10 +++ .../MyWebApi.Api/MyWebApi.Api.csproj" | 5 -- .../MyWebApi.Api/MyWebApi.Api/Program.cs" | 2 +- .../Properties/launchSettings.json" | 4 +- .../MyWebApi.Api/MyWebApi.Api/Startup.cs" | 4 +- .../MyWebApi.Api/WeatherForecast.cs" | 2 +- .../appsettings.Development.json" | 0 .../MyWebApi.Api/appsettings.json" | 0 .../MyWebApi.Api/api.http" | 35 ++++++++++ .../Web.Api/Web.Api/Date/Admin3000Db.cs" | 0 .../Web.Api/Web.Api/Entity/Users.cs" | 17 ----- .../Web.Api/api.http" | 16 ----- 16 files changed, 109 insertions(+), 89 deletions(-) create mode 100644 "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/.vscode/launch.json" rename "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api.sln" => "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api.sln" (30%) rename "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Controllers/UsersController.cs" => "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Controllers/UsersController.cs" (41%) rename "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Controllers/WeatherForecastController.cs" => "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Controllers/WeatherForecastController.cs" (96%) create mode 100644 "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Entity/Users.cs" rename "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Web.Api.csproj" => "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/MyWebApi.Api.csproj" (40%) rename "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Program.cs" => "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Program.cs" (96%) rename "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Properties/launchSettings.json" => "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Properties/launchSettings.json" (90%) rename "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Startup.cs" => "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Startup.cs" (97%) rename "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/WeatherForecast.cs" => "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/WeatherForecast.cs" (92%) rename "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/appsettings.Development.json" => "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/appsettings.Development.json" (100%) rename "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/appsettings.json" => "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/appsettings.json" (100%) create mode 100644 "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/api.http" delete mode 100644 "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Date/Admin3000Db.cs" delete mode 100644 "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Entity/Users.cs" delete mode 100644 "\346\242\201\350\211\272\347\274\244/Web.Api/api.http" diff --git "a/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/.vscode/launch.json" "b/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/.vscode/launch.json" new file mode 100644 index 0000000..9686532 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/.vscode/launch.json" @@ -0,0 +1,17 @@ +{ + // 使用 IntelliSense 了解相关属性。 + // 悬停以查看现有属性的描述。 + // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "启动程序", + "skipFiles": [ + "/**" + ], + "program": "${file}" + } + ] +} \ No newline at end of file diff --git "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api.sln" "b/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api.sln" similarity index 30% rename from "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api.sln" rename to "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api.sln" index 2525f92..2f92ebd 100644 --- "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api.sln" +++ "b/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api.sln" @@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.26124.0 MinimumVisualStudioVersion = 15.0.26124.0 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Web.Api", "Web.Api\Web.Api.csproj", "{2FEFD2BA-1065-4863-ABBD-9DF4DDBEBE72}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -17,18 +15,4 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {2FEFD2BA-1065-4863-ABBD-9DF4DDBEBE72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2FEFD2BA-1065-4863-ABBD-9DF4DDBEBE72}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2FEFD2BA-1065-4863-ABBD-9DF4DDBEBE72}.Debug|x64.ActiveCfg = Debug|Any CPU - {2FEFD2BA-1065-4863-ABBD-9DF4DDBEBE72}.Debug|x64.Build.0 = Debug|Any CPU - {2FEFD2BA-1065-4863-ABBD-9DF4DDBEBE72}.Debug|x86.ActiveCfg = Debug|Any CPU - {2FEFD2BA-1065-4863-ABBD-9DF4DDBEBE72}.Debug|x86.Build.0 = Debug|Any CPU - {2FEFD2BA-1065-4863-ABBD-9DF4DDBEBE72}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2FEFD2BA-1065-4863-ABBD-9DF4DDBEBE72}.Release|Any CPU.Build.0 = Release|Any CPU - {2FEFD2BA-1065-4863-ABBD-9DF4DDBEBE72}.Release|x64.ActiveCfg = Release|Any CPU - {2FEFD2BA-1065-4863-ABBD-9DF4DDBEBE72}.Release|x64.Build.0 = Release|Any CPU - {2FEFD2BA-1065-4863-ABBD-9DF4DDBEBE72}.Release|x86.ActiveCfg = Release|Any CPU - {2FEFD2BA-1065-4863-ABBD-9DF4DDBEBE72}.Release|x86.Build.0 = Release|Any CPU - EndGlobalSection EndGlobal diff --git "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Controllers/UsersController.cs" "b/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Controllers/UsersController.cs" similarity index 41% rename from "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Controllers/UsersController.cs" rename to "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Controllers/UsersController.cs" index 10625f7..3cc13b1 100644 --- "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Controllers/UsersController.cs" +++ "b/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Controllers/UsersController.cs" @@ -1,66 +1,78 @@ using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; -using Web.Api.Entity; +using MyApi.Api.Entity; using System.Linq; -namespace Web.Api.Controllers +namespace MyApi.Api.Controllers { [ApiController] [Route("[controller]")] - public class UsersController : ControllerBase{ + public class UsersController : ControllerBase { [HttpGet] - public dynamic Get(){ - var users = GetUsers(); - return users; + // public dynamic Get(){ + // return "唯独你没懂"; + // } + + [HttpGet] + public IEnumerable 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; + var users = GetUsers(); + var user = users.Where(x=>x.Id==id).FirstOrDefault(); + return user; } - [HttpPost("{id}")] + + + [HttpPost] public dynamic Post(dynamic model){ - return new { - Code = 2000, - Date = model, - Msg = "成功", + + return new{ + Data=model, + Msg="成功了" }; } + [HttpPut("{id}")] - public dynamic Put(int id, dynamic model){ + public dynamic Put(int id,dynamic model){ + return new{ - Date = model, - Msg=string.Format("要修改的ID为{0},",id) + Data=model, + Msg=string.Format("要修改的Id为{0},",id) }; } + [HttpDelete("{id}")] public dynamic Delete(int id,dynamic model){ + return new{ - Date = model, - Msg=string.Format("要修改的ID为{0},",id) + Data=model, + Msg=string.Format("要删除的Id为{0},",id) }; } - public IEnumerable GetUsers(){ - var users = new List{ + + private IEnumerable GetUsers(){ + var users = new List{ new Users{ Id=1, - Username="good", - Password="lisa" + UserName="你好", + PassWord="确实好啊" }, new Users{ Id=2, - Username="good", - Password="nice" + UserName="真的吗", + PassWord="不啊" }, new Users{ Id=3, - Username="good", - Password="wdnbd" + UserName="可以吗", + PassWord="我觉得不行" }, }; return users; } } -} \ No newline at end of file +} diff --git "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Controllers/WeatherForecastController.cs" "b/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Controllers/WeatherForecastController.cs" similarity index 96% rename from "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Controllers/WeatherForecastController.cs" rename to "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Controllers/WeatherForecastController.cs" index 3b56fb4..4e01cb2 100644 --- "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Controllers/WeatherForecastController.cs" +++ "b/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Controllers/WeatherForecastController.cs" @@ -5,7 +5,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; -namespace Web.Api.Controllers +namespace MyWebApi.Api.Controllers { [ApiController] [Route("[controller]")] diff --git "a/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Entity/Users.cs" "b/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Entity/Users.cs" new file mode 100644 index 0000000..995f8dd --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Entity/Users.cs" @@ -0,0 +1,10 @@ +using System; + +namespace MyApi.Api.Entity +{ + public class Users{ + public int Id{get;set;} + public String UserName{get;set;} + public string PassWord{get;set;} + } +} \ No newline at end of file diff --git "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Web.Api.csproj" "b/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/MyWebApi.Api.csproj" similarity index 40% rename from "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Web.Api.csproj" rename to "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/MyWebApi.Api.csproj" index 2efd60a..d12c450 100644 --- "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Web.Api.csproj" +++ "b/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/MyWebApi.Api.csproj" @@ -4,10 +4,5 @@ netcoreapp3.1 - - - - - diff --git "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Program.cs" "b/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Program.cs" similarity index 96% rename from "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Program.cs" rename to "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Program.cs" index 11cd3c8..49aa87c 100644 --- "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Program.cs" +++ "b/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Program.cs" @@ -7,7 +7,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -namespace Web.Api +namespace MyWebApi.Api { public class Program { diff --git "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Properties/launchSettings.json" "b/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Properties/launchSettings.json" similarity index 90% rename from "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Properties/launchSettings.json" rename to "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Properties/launchSettings.json" index e36e127..549dce5 100644 --- "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Properties/launchSettings.json" +++ "b/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Properties/launchSettings.json" @@ -4,7 +4,7 @@ "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { - "applicationUrl": "http://localhost:42799", + "applicationUrl": "http://localhost:62960", "sslPort": 0 } }, @@ -17,7 +17,7 @@ "ASPNETCORE_ENVIRONMENT": "Development" } }, - "Web.Api": { + "MyWebApi.Api": { "commandName": "Project", "launchBrowser": true, "launchUrl": "weatherforecast", diff --git "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Startup.cs" "b/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Startup.cs" similarity index 97% rename from "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Startup.cs" rename to "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Startup.cs" index 009492d..32ca4a2 100644 --- "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Startup.cs" +++ "b/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Startup.cs" @@ -10,7 +10,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -namespace Web.Api +namespace MyWebApi.Api { public class Startup { @@ -23,7 +23,7 @@ namespace Web.Api // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) - { + { services.AddControllers(); } diff --git "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/WeatherForecast.cs" "b/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/WeatherForecast.cs" similarity index 92% rename from "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/WeatherForecast.cs" rename to "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/WeatherForecast.cs" index 699931c..fe20bc7 100644 --- "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/WeatherForecast.cs" +++ "b/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/WeatherForecast.cs" @@ -1,6 +1,6 @@ using System; -namespace Web.Api +namespace MyWebApi.Api { public class WeatherForecast { diff --git "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/appsettings.Development.json" "b/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/appsettings.Development.json" similarity index 100% rename from "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/appsettings.Development.json" rename to "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/appsettings.Development.json" diff --git "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/appsettings.json" "b/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/appsettings.json" similarity index 100% rename from "\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/appsettings.json" rename to "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/appsettings.json" diff --git "a/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/api.http" "b/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/api.http" new file mode 100644 index 0000000..9fbde2b --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/api.http" @@ -0,0 +1,35 @@ +###Get + +GET http://localhost:5000/users HTTP/1.1 + +### +GET http://localhost:5000/users/2 HTTP/1.1 + + +### Post + +POST http://localhost:5000/users HTTP/1.1 +Content-Type: application/json + +{ + "UserName":"里", + "PassWord":"123" +} +### Put + +PUT http://localhost:5000/users/1 HTTP/1.1 +Content-Type: application/json + +{ + "UserName":"这里", + "PassWord":"123" +} +### Delete + +DELETE http://localhost:5000/users/2 HTTP/1.1 +Content-Type: application/json + +{ + "UserName":"哪里", + "PassWord":"123" +} \ No newline at end of file diff --git "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Date/Admin3000Db.cs" "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Date/Admin3000Db.cs" deleted file mode 100644 index e69de29..0000000 diff --git "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Entity/Users.cs" "b/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Entity/Users.cs" deleted file mode 100644 index 9a7404e..0000000 --- "a/\346\242\201\350\211\272\347\274\244/Web.Api/Web.Api/Entity/Users.cs" +++ /dev/null @@ -1,17 +0,0 @@ -using System; -namespace Web.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/\346\242\201\350\211\272\347\274\244/Web.Api/api.http" "b/\346\242\201\350\211\272\347\274\244/Web.Api/api.http" deleted file mode 100644 index a84c8d1..0000000 --- "a/\346\242\201\350\211\272\347\274\244/Web.Api/api.http" +++ /dev/null @@ -1,16 +0,0 @@ -###获取用户列表 -GET http://localhost:5000/users HTTP/1.1 - - -###获取指定ID用户 -GET http://localhost:5000/users3 HTTP/1.1 - -###创建用户 -POST http://localhost:5000/users HTTP/1.1 -Content-Type: application/json - -{ - "username":"good", - "password":"土笨笨" -} - -- Gitee From ca006282782f3dcc5a116c9f00cf20fb9895ac40 Mon Sep 17 00:00:00 2001 From: yb <1728066681@qq.com> Date: Tue, 29 Jun 2021 11:40:01 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E8=AF=BE=E5=A0=82=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MyApi/MyWebApi.Api/.vscode/launch.json" | 0 .../MyApi/MyWebApi.Api/MyWebApi.Api.sln" | 0 .../Controllers/UsersController.cs" | 78 +++++++++++++++++++ .../Controllers/WeatherForecastController.cs" | 0 .../MyWebApi.Api/MyWebApi.Api/Data/ShowDb.cs" | 13 ++++ .../MyWebApi.Api/Entity/BaseEntity.cs" | 15 ++++ .../MyWebApi.Api/Entity/Roles.cs" | 11 +++ .../MyWebApi.Api/Entity/UserRoles.cs" | 13 ++++ .../MyWebApi.Api/Entity/Users.cs" | 10 +++ .../20210629024032_InitialCreate.Designer.cs" | 43 ++++++++++ .../20210629024032_InitialCreate.cs" | 30 +++++++ .../Migrations/ShowDbModelSnapshot.cs" | 41 ++++++++++ .../MyWebApi.Api/MyWebApi.Api.csproj" | 17 ++++ .../MyWebApi.Api/ParamModel/NewUser.cs" | 7 ++ .../MyWebApi.Api/MyWebApi.Api/Program.cs" | 0 .../Properties/launchSettings.json" | 0 .../MyWebApi.Api/MyWebApi.Api/Startup.cs" | 0 .../MyWebApi.Api/WeatherForecast.cs" | 0 .../appsettings.Development.json" | 0 .../MyWebApi.Api/appsettings.json" | 0 .../MyApi/MyWebApi.Api/api.http" | 35 +++++++++ .../MyApi/MyWebApi.Api0/.vscode/launch.json" | 17 ++++ .../MyApi/MyWebApi.Api0/MyWebApi.Api.sln" | 18 +++++ .../Controllers/UsersController.cs" | 0 .../Controllers/WeatherForecastController.cs" | 39 ++++++++++ .../MyWebApi.Api/Entity/Users.cs" | 0 .../MyWebApi.Api/MyWebApi.Api.csproj" | 0 .../MyWebApi.Api0/MyWebApi.Api/Program.cs" | 26 +++++++ .../Properties/launchSettings.json" | 30 +++++++ .../MyWebApi.Api0/MyWebApi.Api/Startup.cs" | 48 ++++++++++++ .../MyWebApi.Api/WeatherForecast.cs" | 15 ++++ .../appsettings.Development.json" | 9 +++ .../MyWebApi.Api/appsettings.json" | 10 +++ .../MyApi/MyWebApi.Api0/api.http" | 0 ...1.06.29\357\274\210EF Core\357\274\211.md" | 42 ++++++++++ 35 files changed, 567 insertions(+) rename "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/.vscode/launch.json" => "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/.vscode/launch.json" (100%) rename "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api.sln" => "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api.sln" (100%) create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Controllers/UsersController.cs" rename "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Controllers/WeatherForecastController.cs" => "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Controllers/WeatherForecastController.cs" (100%) create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Data/ShowDb.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Entity/BaseEntity.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Entity/Roles.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Entity/UserRoles.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Entity/Users.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Migrations/20210629024032_InitialCreate.Designer.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Migrations/20210629024032_InitialCreate.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Migrations/ShowDbModelSnapshot.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/MyWebApi.Api.csproj" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/ParamModel/NewUser.cs" rename "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Program.cs" => "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Program.cs" (100%) rename "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Properties/launchSettings.json" => "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Properties/launchSettings.json" (100%) rename "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Startup.cs" => "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Startup.cs" (100%) rename "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/WeatherForecast.cs" => "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/WeatherForecast.cs" (100%) rename "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/appsettings.Development.json" => "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/appsettings.Development.json" (100%) rename "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/appsettings.json" => "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/appsettings.json" (100%) create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/api.http" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/.vscode/launch.json" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api.sln" rename "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Controllers/UsersController.cs" => "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/Controllers/UsersController.cs" (100%) create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/Controllers/WeatherForecastController.cs" rename "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Entity/Users.cs" => "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/Entity/Users.cs" (100%) rename "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/MyWebApi.Api.csproj" => "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/MyWebApi.Api.csproj" (100%) create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/Program.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/Properties/launchSettings.json" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/Startup.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/WeatherForecast.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/appsettings.Development.json" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/appsettings.json" rename "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/api.http" => "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/api.http" (100%) create mode 100644 "\346\242\201\350\211\272\347\274\244/Vue - 2021.06.29\357\274\210EF Core\357\274\211.md" diff --git "a/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/.vscode/launch.json" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/.vscode/launch.json" similarity index 100% rename from "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/.vscode/launch.json" rename to "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/.vscode/launch.json" diff --git "a/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api.sln" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api.sln" similarity index 100% rename from "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api.sln" rename to "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api.sln" diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Controllers/UsersController.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Controllers/UsersController.cs" new file mode 100644 index 0000000..da20131 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Controllers/UsersController.cs" @@ -0,0 +1,78 @@ +using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; +using MyWebApi.Api.Entity; +using System.Linq; + +namespace MyWebApi.Api.Controllers +{ + [ApiController] + [Route("[controller]")] + public class UsersController : ControllerBase { + [HttpGet] + // public dynamic Get(){ + // return "唯独你没懂"; + // } + + [HttpGet] + public IEnumerable 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{ + Data=model, + Msg="成功了" + }; + } + + [HttpPut("{id}")] + public dynamic Put(int id,dynamic model){ + + return new{ + Data=model, + Msg=string.Format("要修改的Id为{0},",id) + }; + } + + [HttpDelete("{id}")] + public dynamic Delete(int id,dynamic model){ + + return new{ + Data=model, + Msg=string.Format("要删除的Id为{0},",id) + }; + } + + + private IEnumerable GetUsers(){ + var users = new List{ + new Users{ + Id=1, + UserName="你好", + PassWord="确实好啊" + }, + new Users{ + Id=2, + UserName="真的吗", + PassWord="不啊" + }, + new Users{ + Id=3, + UserName="可以吗", + PassWord="我觉得不行" + }, + }; + return users; + } + } +} diff --git "a/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Controllers/WeatherForecastController.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Controllers/WeatherForecastController.cs" similarity index 100% rename from "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Controllers/WeatherForecastController.cs" rename to "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Controllers/WeatherForecastController.cs" diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Data/ShowDb.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Data/ShowDb.cs" new file mode 100644 index 0000000..d8fcc9b --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Data/ShowDb.cs" @@ -0,0 +1,13 @@ +using Microsoft.EntityFrameworkCore; +using MyWebApi.Api.Entity; + +namespace MyWebApi.Api.Db +{ + public class ShowDb : DbContext + { + public DbSet Users { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder options) + => options.UseSqlServer(@"server=.;database=ShowDb;uid=sa;pwd=123456;"); + } +} diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Entity/BaseEntity.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Entity/BaseEntity.cs" new file mode 100644 index 0000000..b8c3337 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Entity/BaseEntity.cs" @@ -0,0 +1,15 @@ +using System; + +namespace MyWebApi.Api.Entity +{ + public abstract class BaseEntity + { + public int Id{get;set;} + public bool IsActived { get; set; } + public bool IsDeleted { get; set; } + public DateTime CreatedTime { get; set; } + public DateTime UpdatedTime { get; set; } + public int DisplayOrder { get; set; } + public string Remarks { get; set; } + } +} \ No newline at end of file diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Entity/Roles.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Entity/Roles.cs" new file mode 100644 index 0000000..0e8a360 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Entity/Roles.cs" @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace MyWebApi.Api.Entity +{ + public class Roles : BaseEntity + { + public string RoleName{get;set;} + public virtual IEnumerable UserRoles { get; set; } + } +} \ No newline at end of file diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Entity/UserRoles.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Entity/UserRoles.cs" new file mode 100644 index 0000000..3769546 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Entity/UserRoles.cs" @@ -0,0 +1,13 @@ +using System; + +namespace MyWebApi.Api.Entity +{ + public class UserRoles : BaseEntity + { + public int UserId { get; set; } + public int RoleId { get; set; } + + public virtual Users User { get; set; } + public virtual Roles Role { get; set; } + } +} \ No newline at end of file diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Entity/Users.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Entity/Users.cs" new file mode 100644 index 0000000..b97cb40 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Entity/Users.cs" @@ -0,0 +1,10 @@ +using System; + +namespace MyWebApi.Api.Entity +{ + public class Users{ + public int Id{get;set;} + public String UserName{get;set;} + public string PassWord{get;set;} + } +} \ No newline at end of file diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Migrations/20210629024032_InitialCreate.Designer.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Migrations/20210629024032_InitialCreate.Designer.cs" new file mode 100644 index 0000000..bc23c65 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Migrations/20210629024032_InitialCreate.Designer.cs" @@ -0,0 +1,43 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using MyWebApi.Api.Db; + +namespace MyWebApi.Api.Migrations +{ + [DbContext(typeof(ShowDb))] + [Migration("20210629024032_InitialCreate")] + partial class InitialCreate + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("ProductVersion", "5.0.7") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("MyWebApi.Api.Entity.Users", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("PassWord") + .HasColumnType("nvarchar(max)"); + + b.Property("UserName") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Migrations/20210629024032_InitialCreate.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Migrations/20210629024032_InitialCreate.cs" new file mode 100644 index 0000000..d5ff20b --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Migrations/20210629024032_InitialCreate.cs" @@ -0,0 +1,30 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace MyWebApi.Api.Migrations +{ + public partial class InitialCreate : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + UserName = table.Column(type: "nvarchar(max)", nullable: true), + PassWord = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.Id); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Users"); + } + } +} diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Migrations/ShowDbModelSnapshot.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Migrations/ShowDbModelSnapshot.cs" new file mode 100644 index 0000000..83a875e --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Migrations/ShowDbModelSnapshot.cs" @@ -0,0 +1,41 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using MyWebApi.Api.Db; + +namespace MyWebApi.Api.Migrations +{ + [DbContext(typeof(ShowDb))] + partial class ShowDbModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("ProductVersion", "5.0.7") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("MyWebApi.Api.Entity.Users", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("PassWord") + .HasColumnType("nvarchar(max)"); + + b.Property("UserName") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/MyWebApi.Api.csproj" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/MyWebApi.Api.csproj" new file mode 100644 index 0000000..a1ec8be --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/MyWebApi.Api.csproj" @@ -0,0 +1,17 @@ + + + + netcoreapp3.1 + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/ParamModel/NewUser.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/ParamModel/NewUser.cs" new file mode 100644 index 0000000..5a9820b --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/ParamModel/NewUser.cs" @@ -0,0 +1,7 @@ +namespace MyWebApi.Api.ParamModel +{ + public class NewUser{ + public string UserName{get;set;} + public string PassWord{get;set;} + } +} \ No newline at end of file diff --git "a/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Program.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Program.cs" similarity index 100% rename from "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Program.cs" rename to "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Program.cs" diff --git "a/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Properties/launchSettings.json" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Properties/launchSettings.json" similarity index 100% rename from "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Properties/launchSettings.json" rename to "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Properties/launchSettings.json" diff --git "a/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Startup.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Startup.cs" similarity index 100% rename from "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Startup.cs" rename to "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/Startup.cs" diff --git "a/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/WeatherForecast.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/WeatherForecast.cs" similarity index 100% rename from "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/WeatherForecast.cs" rename to "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/WeatherForecast.cs" diff --git "a/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/appsettings.Development.json" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/appsettings.Development.json" similarity index 100% rename from "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/appsettings.Development.json" rename to "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/appsettings.Development.json" diff --git "a/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/appsettings.json" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/appsettings.json" similarity index 100% rename from "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/appsettings.json" rename to "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/MyWebApi.Api/appsettings.json" diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/api.http" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/api.http" new file mode 100644 index 0000000..95d5757 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/api.http" @@ -0,0 +1,35 @@ +###Get 获取 + +GET http://localhost:5000/users HTTP/1.1 + +### +GET http://localhost:5000/users/2 HTTP/1.1 + + +### Post 添加 + +POST http://localhost:5000/users HTTP/1.1 +Content-Type: application/json + +{ + "UserName":"里", + "PassWord":"123" +} +### Put 修改 + +PUT http://localhost:5000/users/1 HTTP/1.1 +Content-Type: application/json + +{ + "UserName":"这里", + "PassWord":"123" +} +### Delete 删除 + +DELETE http://localhost:5000/users/2 HTTP/1.1 +Content-Type: application/json + +{ + "UserName":"哪里", + "PassWord":"123" +} \ No newline at end of file diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/.vscode/launch.json" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/.vscode/launch.json" new file mode 100644 index 0000000..9686532 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/.vscode/launch.json" @@ -0,0 +1,17 @@ +{ + // 使用 IntelliSense 了解相关属性。 + // 悬停以查看现有属性的描述。 + // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "启动程序", + "skipFiles": [ + "/**" + ], + "program": "${file}" + } + ] +} \ No newline at end of file diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api.sln" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api.sln" new file mode 100644 index 0000000..2f92ebd --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api.sln" @@ -0,0 +1,18 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26124.0 +MinimumVisualStudioVersion = 15.0.26124.0 +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git "a/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Controllers/UsersController.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/Controllers/UsersController.cs" similarity index 100% rename from "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Controllers/UsersController.cs" rename to "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/Controllers/UsersController.cs" diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/Controllers/WeatherForecastController.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/Controllers/WeatherForecastController.cs" new file mode 100644 index 0000000..4e01cb2 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/Controllers/WeatherForecastController.cs" @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; + +namespace MyWebApi.Api.Controllers +{ + [ApiController] + [Route("[controller]")] + public class WeatherForecastController : ControllerBase + { + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet] + public IEnumerable Get() + { + var rng = new Random(); + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateTime.Now.AddDays(index), + TemperatureC = rng.Next(-20, 55), + Summary = Summaries[rng.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} diff --git "a/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Entity/Users.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/Entity/Users.cs" similarity index 100% rename from "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/Entity/Users.cs" rename to "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/Entity/Users.cs" diff --git "a/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/MyWebApi.Api.csproj" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/MyWebApi.Api.csproj" similarity index 100% rename from "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/MyWebApi.Api/MyWebApi.Api.csproj" rename to "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/MyWebApi.Api.csproj" diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/Program.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/Program.cs" new file mode 100644 index 0000000..49aa87c --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/Program.cs" @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace MyWebApi.Api +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/Properties/launchSettings.json" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/Properties/launchSettings.json" new file mode 100644 index 0000000..549dce5 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/Properties/launchSettings.json" @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:62960", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "MyWebApi.Api": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "applicationUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/Startup.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/Startup.cs" new file mode 100644 index 0000000..32ca4a2 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/Startup.cs" @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace MyWebApi.Api +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + services.AddControllers(); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/WeatherForecast.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/WeatherForecast.cs" new file mode 100644 index 0000000..fe20bc7 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/WeatherForecast.cs" @@ -0,0 +1,15 @@ +using System; + +namespace MyWebApi.Api +{ + public class WeatherForecast + { + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string Summary { get; set; } + } +} diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/appsettings.Development.json" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/appsettings.Development.json" new file mode 100644 index 0000000..8983e0f --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/appsettings.Development.json" @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/appsettings.json" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/appsettings.json" new file mode 100644 index 0000000..d9d9a9b --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/MyWebApi.Api/appsettings.json" @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} diff --git "a/\346\242\201\350\211\272\347\274\244/MyWebApi.Api/api.http" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/api.http" similarity index 100% rename from "\346\242\201\350\211\272\347\274\244/MyWebApi.Api/api.http" rename to "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api0/api.http" diff --git "a/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.29\357\274\210EF Core\357\274\211.md" "b/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.29\357\274\210EF Core\357\274\211.md" new file mode 100644 index 0000000..9dda711 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.29\357\274\210EF Core\357\274\211.md" @@ -0,0 +1,42 @@ +# 表关系 + +## BaseEntity继承表 +``` +using System; + +namespace MyWebApi.Api.Entity +{ + public abstract class BaseEntity + { + public int Id{get;set;} + public bool IsActived { get; set; } + public bool IsDeleted { get; set; } + public DateTime CreatedTime { get; set; } + public DateTime UpdatedTime { get; set; } + public int DisplayOrder { get; set; } + public string Remarks { get; set; } + } +} +``` +## Roles表 +``` +namespace MyWebApi.Api.Entity +{ + public class Roles : BaseEntity + { + public string RoleName{get;set;} + public virtual IEnumerable UserRoles { get; set; } + } +} +``` +## UserRoles +``` +public class UserRoles : BaseEntity + { + public int UserId { get; set; } + public int RoleId { get; set; } + + public virtual Users User { get; set; } + public virtual Roles Role { get; set; } + } +``` \ No newline at end of file -- Gitee From 0b3dd98ab4b29186a147ac6197edefbf796f8202 Mon Sep 17 00:00:00 2001 From: yb <172866681@qq.com> Date: Wed, 30 Jun 2021 17:44:35 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MyApi/MyWebApi.Api/.vscode/launch.json" | 17 --- .../MyApi/MyWebApi.Api23/MyWebApi.Api.sln" | 18 +++ .../Controllers/UsersController.cs" | 143 ++++++++++++++++++ .../Controllers/WeatherForecastController.cs" | 39 +++++ .../MyWebApi.Api/Data/ShowDb.cs" | 13 ++ .../MyWebApi.Api/Entity/BaseEntity.cs" | 15 ++ .../MyWebApi.Api/Entity/Roles.cs" | 11 ++ .../MyWebApi.Api/Entity/UserRoles.cs" | 13 ++ .../MyWebApi.Api/Entity/Users.cs" | 10 ++ .../20210629024032_InitialCreate.Designer.cs" | 43 ++++++ .../20210629024032_InitialCreate.cs" | 30 ++++ .../Migrations/ShowDbModelSnapshot.cs" | 41 +++++ .../MyWebApi.Api/MyWebApi.Api.csproj" | 17 +++ .../MyWebApi.Api/ParamModel/NewUser.cs" | 7 + .../MyWebApi.Api23/MyWebApi.Api/Program.cs" | 26 ++++ .../Properties/launchSettings.json" | 30 ++++ .../MyWebApi.Api23/MyWebApi.Api/Startup.cs" | 48 ++++++ .../MyWebApi.Api/WeatherForecast.cs" | 15 ++ .../appsettings.Development.json" | 9 ++ .../MyWebApi.Api/appsettings.json" | 10 ++ .../MyApi/MyWebApi.Api23/api.http" | 35 +++++ 21 files changed, 573 insertions(+), 17 deletions(-) delete mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/.vscode/launch.json" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api.sln" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Controllers/UsersController.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Controllers/WeatherForecastController.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Data/ShowDb.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Entity/BaseEntity.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Entity/Roles.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Entity/UserRoles.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Entity/Users.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Migrations/20210629024032_InitialCreate.Designer.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Migrations/20210629024032_InitialCreate.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Migrations/ShowDbModelSnapshot.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/MyWebApi.Api.csproj" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/ParamModel/NewUser.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Program.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Properties/launchSettings.json" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Startup.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/WeatherForecast.cs" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/appsettings.Development.json" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/appsettings.json" create mode 100644 "\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/api.http" diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/.vscode/launch.json" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/.vscode/launch.json" deleted file mode 100644 index 9686532..0000000 --- "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api/.vscode/launch.json" +++ /dev/null @@ -1,17 +0,0 @@ -{ - // 使用 IntelliSense 了解相关属性。 - // 悬停以查看现有属性的描述。 - // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "type": "node", - "request": "launch", - "name": "启动程序", - "skipFiles": [ - "/**" - ], - "program": "${file}" - } - ] -} \ No newline at end of file diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api.sln" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api.sln" new file mode 100644 index 0000000..2f92ebd --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api.sln" @@ -0,0 +1,18 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26124.0 +MinimumVisualStudioVersion = 15.0.26124.0 +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Controllers/UsersController.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Controllers/UsersController.cs" new file mode 100644 index 0000000..166fecd --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Controllers/UsersController.cs" @@ -0,0 +1,143 @@ +using System; +using System.Collections.Generic; +using Admin3000.Backend.Api.Entity; +using Microsoft.AspNetCore.Mvc; +using System.Linq; +using MyWebApi.Api.ParamModel; +using Newtonsoft.Json; +using MyWebApi.Api.Repository; + + +namespace MyWebApi.Api.Controllers +{ + [ApiController] + [Route("[controller]")] + public class UsersController : ControllerBase + { + private Api.Db.MyWebApiDb db=new Api.Db.MyWebApiDb(); + private IRepository _usersRespository=new EfRepository(); + + [HttpGet] + public dynamic Get() + { + + var users = _usersRespository.Table.ToList(); + return new { + Code =1000, + Data =users, + Msg ="获取用户列表成功^_^" + }; + } + + [HttpGet("{id}")] + public dynamic Get(int id) + { + var user = db.Users.Where(x => x.Id == id).FirstOrDefault(); + return user; + } + + [HttpPost] + public string Post(NewUser model) + { + JsonSerializerSettings settings = new JsonSerializerSettings(); + // settings.MissingMemberHandling = MissingMemberHandling.Ignore; + settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; + var user = new Users + { + Username = model.Username, + Password = model.Password + }; + + db.Users.Add(user); + db.SaveChanges(); + + var res = new + { + Code = 1000, + Data = user, + Msg = "创建用户成功" + }; + return JsonConvert.SerializeObject(res, settings); + } + + [HttpPut("{id}")] + public dynamic Put(int id, NewUser model) + { + var user = db.Users.Where(x => x.Id == id).FirstOrDefault(); + + if (user != null) + { + user.Username = model.Username; + user.Password = model.Password; + user.UpdatedTime=DateTime.Now; + db.Update(user); + db.SaveChanges(); + return new + { + Code = 1000, + Data = user, + Msg = string.Format("你修改的用户的id为:{0},已经修改成功,请注意查收", id) + }; + } + else + { + return new + { + Code = 104, + Data = "", + Msg = "指定Id的用户不存在,请确认后重试" + }; + } + } + + [HttpDelete("{id}")] + public dynamic Delete(int id) + { + var user = db.Users.Where(x => x.Id == id).FirstOrDefault(); + if (user != null) + { + db.Users.Remove(user); + db.SaveChanges(); + return new + { + Code = 1000, + Msg = string.Format("删除指定id为{0}的用户成功", id) + }; + } + else + { + return new + { + Code = 104, + Data = "", + Msg = "指定Id的用户不存在,请确认后重试" + }; + } + + } + + private IEnumerable GetUsers() + { + var users = + new List { + new Users { + Id = 1, + Username = "admin", + Password = "芝麻开门" + }, + new Users { + Id = 2, + Username = "超级管理员", + Password = "芝麻开门" + }, + new Users { + Id = 3, + Username = "普通用户", + Password = "芝麻开门" + } + }; + + return users; + } + } +} diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Controllers/WeatherForecastController.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Controllers/WeatherForecastController.cs" new file mode 100644 index 0000000..4e01cb2 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Controllers/WeatherForecastController.cs" @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; + +namespace MyWebApi.Api.Controllers +{ + [ApiController] + [Route("[controller]")] + public class WeatherForecastController : ControllerBase + { + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet] + public IEnumerable Get() + { + var rng = new Random(); + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateTime.Now.AddDays(index), + TemperatureC = rng.Next(-20, 55), + Summary = Summaries[rng.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Data/ShowDb.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Data/ShowDb.cs" new file mode 100644 index 0000000..d8fcc9b --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Data/ShowDb.cs" @@ -0,0 +1,13 @@ +using Microsoft.EntityFrameworkCore; +using MyWebApi.Api.Entity; + +namespace MyWebApi.Api.Db +{ + public class ShowDb : DbContext + { + public DbSet Users { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder options) + => options.UseSqlServer(@"server=.;database=ShowDb;uid=sa;pwd=123456;"); + } +} diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Entity/BaseEntity.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Entity/BaseEntity.cs" new file mode 100644 index 0000000..b8c3337 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Entity/BaseEntity.cs" @@ -0,0 +1,15 @@ +using System; + +namespace MyWebApi.Api.Entity +{ + public abstract class BaseEntity + { + public int Id{get;set;} + public bool IsActived { get; set; } + public bool IsDeleted { get; set; } + public DateTime CreatedTime { get; set; } + public DateTime UpdatedTime { get; set; } + public int DisplayOrder { get; set; } + public string Remarks { get; set; } + } +} \ No newline at end of file diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Entity/Roles.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Entity/Roles.cs" new file mode 100644 index 0000000..0e8a360 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Entity/Roles.cs" @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace MyWebApi.Api.Entity +{ + public class Roles : BaseEntity + { + public string RoleName{get;set;} + public virtual IEnumerable UserRoles { get; set; } + } +} \ No newline at end of file diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Entity/UserRoles.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Entity/UserRoles.cs" new file mode 100644 index 0000000..3769546 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Entity/UserRoles.cs" @@ -0,0 +1,13 @@ +using System; + +namespace MyWebApi.Api.Entity +{ + public class UserRoles : BaseEntity + { + public int UserId { get; set; } + public int RoleId { get; set; } + + public virtual Users User { get; set; } + public virtual Roles Role { get; set; } + } +} \ No newline at end of file diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Entity/Users.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Entity/Users.cs" new file mode 100644 index 0000000..b97cb40 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Entity/Users.cs" @@ -0,0 +1,10 @@ +using System; + +namespace MyWebApi.Api.Entity +{ + public class Users{ + public int Id{get;set;} + public String UserName{get;set;} + public string PassWord{get;set;} + } +} \ No newline at end of file diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Migrations/20210629024032_InitialCreate.Designer.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Migrations/20210629024032_InitialCreate.Designer.cs" new file mode 100644 index 0000000..bc23c65 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Migrations/20210629024032_InitialCreate.Designer.cs" @@ -0,0 +1,43 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using MyWebApi.Api.Db; + +namespace MyWebApi.Api.Migrations +{ + [DbContext(typeof(ShowDb))] + [Migration("20210629024032_InitialCreate")] + partial class InitialCreate + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("ProductVersion", "5.0.7") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("MyWebApi.Api.Entity.Users", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("PassWord") + .HasColumnType("nvarchar(max)"); + + b.Property("UserName") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Migrations/20210629024032_InitialCreate.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Migrations/20210629024032_InitialCreate.cs" new file mode 100644 index 0000000..d5ff20b --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Migrations/20210629024032_InitialCreate.cs" @@ -0,0 +1,30 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace MyWebApi.Api.Migrations +{ + public partial class InitialCreate : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + UserName = table.Column(type: "nvarchar(max)", nullable: true), + PassWord = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.Id); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Users"); + } + } +} diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Migrations/ShowDbModelSnapshot.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Migrations/ShowDbModelSnapshot.cs" new file mode 100644 index 0000000..83a875e --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Migrations/ShowDbModelSnapshot.cs" @@ -0,0 +1,41 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using MyWebApi.Api.Db; + +namespace MyWebApi.Api.Migrations +{ + [DbContext(typeof(ShowDb))] + partial class ShowDbModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("ProductVersion", "5.0.7") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("MyWebApi.Api.Entity.Users", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("PassWord") + .HasColumnType("nvarchar(max)"); + + b.Property("UserName") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/MyWebApi.Api.csproj" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/MyWebApi.Api.csproj" new file mode 100644 index 0000000..a1ec8be --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/MyWebApi.Api.csproj" @@ -0,0 +1,17 @@ + + + + netcoreapp3.1 + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/ParamModel/NewUser.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/ParamModel/NewUser.cs" new file mode 100644 index 0000000..5a9820b --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/ParamModel/NewUser.cs" @@ -0,0 +1,7 @@ +namespace MyWebApi.Api.ParamModel +{ + public class NewUser{ + public string UserName{get;set;} + public string PassWord{get;set;} + } +} \ No newline at end of file diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Program.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Program.cs" new file mode 100644 index 0000000..49aa87c --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Program.cs" @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace MyWebApi.Api +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Properties/launchSettings.json" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Properties/launchSettings.json" new file mode 100644 index 0000000..549dce5 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Properties/launchSettings.json" @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:62960", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "MyWebApi.Api": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "applicationUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Startup.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Startup.cs" new file mode 100644 index 0000000..32ca4a2 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/Startup.cs" @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace MyWebApi.Api +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + services.AddControllers(); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/WeatherForecast.cs" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/WeatherForecast.cs" new file mode 100644 index 0000000..fe20bc7 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/WeatherForecast.cs" @@ -0,0 +1,15 @@ +using System; + +namespace MyWebApi.Api +{ + public class WeatherForecast + { + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string Summary { get; set; } + } +} diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/appsettings.Development.json" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/appsettings.Development.json" new file mode 100644 index 0000000..8983e0f --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/appsettings.Development.json" @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/appsettings.json" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/appsettings.json" new file mode 100644 index 0000000..d9d9a9b --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/MyWebApi.Api/appsettings.json" @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} diff --git "a/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/api.http" "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/api.http" new file mode 100644 index 0000000..95d5757 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/MyApi/MyWebApi.Api23/api.http" @@ -0,0 +1,35 @@ +###Get 获取 + +GET http://localhost:5000/users HTTP/1.1 + +### +GET http://localhost:5000/users/2 HTTP/1.1 + + +### Post 添加 + +POST http://localhost:5000/users HTTP/1.1 +Content-Type: application/json + +{ + "UserName":"里", + "PassWord":"123" +} +### Put 修改 + +PUT http://localhost:5000/users/1 HTTP/1.1 +Content-Type: application/json + +{ + "UserName":"这里", + "PassWord":"123" +} +### Delete 删除 + +DELETE http://localhost:5000/users/2 HTTP/1.1 +Content-Type: application/json + +{ + "UserName":"哪里", + "PassWord":"123" +} \ No newline at end of file -- Gitee From 922543c23236af1c177f429eb22dadb40d79226c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E8=89=BA=E7=BC=A4?= <1728066681@qq.com> Date: Wed, 30 Jun 2021 22:53:33 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E8=AF=BE=E5=A0=82=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...40\346\224\271\346\237\245\357\274\211.md" | 218 ++++++++++++++++++ 1 file changed, 218 insertions(+) create mode 100644 "\346\242\201\350\211\272\347\274\244/Vue - 2021.06.30\357\274\210Api\345\260\201\350\243\205\346\216\245\345\217\243\345\242\236\345\210\240\346\224\271\346\237\245\357\274\211.md" diff --git "a/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.30\357\274\210Api\345\260\201\350\243\205\346\216\245\345\217\243\345\242\236\345\210\240\346\224\271\346\237\245\357\274\211.md" "b/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.30\357\274\210Api\345\260\201\350\243\205\346\216\245\345\217\243\345\242\236\345\210\240\346\224\271\346\237\245\357\274\211.md" new file mode 100644 index 0000000..9255451 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.30\357\274\210Api\345\260\201\350\243\205\346\216\245\345\217\243\345\242\236\345\210\240\346\224\271\346\237\245\357\274\211.md" @@ -0,0 +1,218 @@ +# Api 封装接口增删改查 + +### IRepository 配置 +``` +公共接口 IRepository 其中 T :类 + + 公共接口 IRepository 其中 T :类 + { + T 获取(对象 ID); + 无效附加(T实体); + IQueryable GetAll(); + 无效插入(T实体); + 无效删除(T实体); + void SubmitChanges(); + } + + 特点:IRepository 绑定到单个类型、IRepository 可能绑定到多个类型(一般情况使用 IRepository ) +``` + ++ MyWebApi +``` +namespace MyWebApi.Repository +{ + public interface IRepository + { + IQueryable Table { get; } + + /// + /// 根据Id获取指定实体 + /// + /// + /// + T GetById(int id); + + + /// + /// 使用实体对象,插入数据 + /// + /// 需要插入的对象 + void Insert(T entity); + + + /// + /// 使用实体对象,插入数据(异步) + /// + /// 需要插入的对象 + Task InsertAsync(T entity); + + + /// + /// 根据对象更新数据 + /// + /// 要更新的对象 + void Update(T entity); + + + /// + /// 根据对象更新数据(异步) + /// + /// 要更新的对象 + /// + Task UpdateAsync(T entity); + + + /// + /// 根据Id删除对应的记录 + /// + /// 主键id + void Delete(int id); + + } +} +``` + +### EFRepository配置 + +1. 用来封装存储,读取和查找行为的机制,它模拟了一个对象集合 + +2. 访问领域对象的一个类似集合的接口,在领域与数据映射层之间进行协调 + ++ 提取为IRepository接口,比如常见的也就是增删改查等方法 + +``` + public interface IRepository where T : class + { + //改变模型中没有更新,里面的Save就取代更新功能 + IEnumerable FindAll(Func exp); + void Add(T entity); + void Delete(T entity); + void Save(); + } +``` + ++ MyWebApi + +``` +namespace MyApi.Api.Repository +{ + public class EFRepository : IRepository where T : BaseEntity + { + /// + /// 数据库上下文的变量,此处是使用常规手段,直接初始化一个数据库上下文的实例对象 + /// + /// + private ShowDb db = new ShowDb(); + + + /// + /// 一个字段成员,用于内部Entity属性 + /// + private DbSet _entity; + + + /// + /// 一个访问受限的属性,只有访问器,总是返回一个代表T类型的表对象 + /// + /// + protected DbSet Entity + { + get + { + if (_entity == null) + { + _entity = db.Set(); + } + return _entity; + } + } + + + /// + /// 代表一个可以用于查询T类型的表 + /// + /// + public IQueryable Table + { + get + { + return Entity.AsQueryable(); + } + } + + + /// + /// 删除(指定T类型,在数据库当中代表指定的表)指定Id的记录 + /// + /// + public void Delete(int id) + { + var t = Entity.Where(x => x.Id == id).FirstOrDefault(); + Entity.Remove(t); + db.SaveChanges(); + } + + public T GetById(int id) + { + var t = Entity.Where(x => x.Id == id).FirstOrDefault(); + return t; + } + + public void Insert(T entity) + { + if (entity == null) + { + throw new NotImplementedException(); + } + + entity.IsActived = true; + entity.IsDeleted = false; + entity.DisplayOrder = 0; + entity.CreatedTime = DateTime.Now; + entity.UpdatedTime = DateTime.Now; + + Entity.Add(entity); + db.SaveChanges(); + } + + public async Task InsertAsync(T entity) + { + if (entity == null) + { + throw new NotImplementedException(); + } + + entity.IsActived = true; + entity.IsDeleted = false; + entity.DisplayOrder = 0; + entity.CreatedTime = DateTime.Now; + entity.UpdatedTime = DateTime.Now; + + await Entity.AddAsync(entity); + await db.SaveChangesAsync(); + } + + public void Update(T entity) + { + if (entity == null) + { + throw new NotImplementedException(); + } + + entity.UpdatedTime = DateTime.Now; + db.SaveChanges(); + } + + public async Task UpdateAsync(T entity) + { + if (entity == null) + { + throw new NotImplementedException(); + } + + entity.UpdatedTime = DateTime.Now; + await db.SaveChangesAsync(); + } + } +} +``` \ No newline at end of file -- Gitee From 25ed8a80591fc21698867298a25cd234be88276b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E8=89=BA=E7=BC=A4?= <1728066681@qq.com> Date: Wed, 30 Jun 2021 23:01:18 +0800 Subject: [PATCH 8/9] =?UTF-8?q?29=E5=8F=B7=E8=AF=BE=E5=A0=82=E7=AC=94?= =?UTF-8?q?=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...64\345\205\263\347\263\273\357\274\211.md" | 81 +++++++++++++++++++ ...1.06.29\357\274\210EF Core\357\274\211.md" | 42 ---------- 2 files changed, 81 insertions(+), 42 deletions(-) create mode 100644 "\346\242\201\350\211\272\347\274\244/Vue - 2021.06.29\357\274\210Api\345\260\201\350\243\205\350\241\250 \345\273\272\347\253\213\350\241\250\344\271\213\351\227\264\345\205\263\347\263\273\357\274\211.md" delete mode 100644 "\346\242\201\350\211\272\347\274\244/Vue - 2021.06.29\357\274\210EF Core\357\274\211.md" diff --git "a/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.29\357\274\210Api\345\260\201\350\243\205\350\241\250 \345\273\272\347\253\213\350\241\250\344\271\213\351\227\264\345\205\263\347\263\273\357\274\211.md" "b/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.29\357\274\210Api\345\260\201\350\243\205\350\241\250 \345\273\272\347\253\213\350\241\250\344\271\213\351\227\264\345\205\263\347\263\273\357\274\211.md" new file mode 100644 index 0000000..2b21bd7 --- /dev/null +++ "b/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.29\357\274\210Api\345\260\201\350\243\205\350\241\250 \345\273\272\347\253\213\350\241\250\344\271\213\351\227\264\345\205\263\347\263\273\357\274\211.md" @@ -0,0 +1,81 @@ +# Api封装表 建立表之间关系 + +## BaseEntity继承表 + +### 封装表 +``` +namespace MyApi.Api.Entity +{ + // abstract只能被继承 + public abstract class BaseEntity + { + // 一些主要表字段 + + // Id + public int Id { get; set; } + // 是否有效 + public bool IsActived { get; set; } + // 是否删除 + public bool IsDeleted { get; set; } + // 创建时间 + public DateTime CreatedTime { get; set; } + // 删除时间 + public DateTime UpdatedTime { get; set; } + // 显示顺序 + public int DisplayOrder { get; set; } + // 备注 + public string Remarks { get; set; } + } +} +``` + +## 表关系 + +### User表 +``` +namespace MyApi.Api.Entity +{ + // 继承BaseEntity + public class Users:BaseEntity + { + // 用户名 + public String UserName { get; set; } + // 用户密码 + public string PassWord { get; set; } + } +} +``` + +### UserRoles表 +``` +namespace MyApi.Api.Entity +{ + // 继承BaseEntity + public class UserRoles:BaseEntity + { + // 用户Id + public int UserId { get; set; } + // 角色Id + public int RoleId { get; set; } + + public virtual Users User { get; set; } + + public virtual Roles Role { get; set; } + } +} +``` + +### Roles表 +``` +namespace MyApi.Api.Entity +{ + // 继承BaseEntity + public class Roles:BaseEntity + { + // 角色名称 + public string RoleName { get; set; } + + public virtual IEnumerable UserRoles { get; set; } + } +} +``` \ No newline at end of file diff --git "a/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.29\357\274\210EF Core\357\274\211.md" "b/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.29\357\274\210EF Core\357\274\211.md" deleted file mode 100644 index 9dda711..0000000 --- "a/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.29\357\274\210EF Core\357\274\211.md" +++ /dev/null @@ -1,42 +0,0 @@ -# 表关系 - -## BaseEntity继承表 -``` -using System; - -namespace MyWebApi.Api.Entity -{ - public abstract class BaseEntity - { - public int Id{get;set;} - public bool IsActived { get; set; } - public bool IsDeleted { get; set; } - public DateTime CreatedTime { get; set; } - public DateTime UpdatedTime { get; set; } - public int DisplayOrder { get; set; } - public string Remarks { get; set; } - } -} -``` -## Roles表 -``` -namespace MyWebApi.Api.Entity -{ - public class Roles : BaseEntity - { - public string RoleName{get;set;} - public virtual IEnumerable UserRoles { get; set; } - } -} -``` -## UserRoles -``` -public class UserRoles : BaseEntity - { - public int UserId { get; set; } - public int RoleId { get; set; } - - public virtual Users User { get; set; } - public virtual Roles Role { get; set; } - } -``` \ No newline at end of file -- Gitee From cc9ca0fc0885127071e713e9530186aaefabe46f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E8=89=BA=E7=BC=A4?= <1728066681@qq.com> Date: Wed, 30 Jun 2021 23:06:17 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E8=BF=99=E4=B8=AA=E6=9C=88=E6=9C=80?= =?UTF-8?q?=E5=90=8E=E4=B8=80=E6=AC=A1=E8=AF=BE=E5=A0=82=E7=AC=94=E8=AE=B0?= =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...7\274\210Api dotnet \345\221\275\344\273\244\357\274\211.md" | 0 ...\274\210Api RESTful \346\217\222\344\273\266\357\274\211.md" | 0 ...\216\245\346\225\260\346\215\256\345\272\223\357\274\211.md" | 2 +- ...\271\213\351\227\264\345\205\263\347\263\273\357\274\211.md" | 0 ...\242\236\345\210\240\346\224\271\346\237\245\357\274\211.md" | 0 5 files changed, 1 insertion(+), 1 deletion(-) rename "\346\242\201\350\211\272\347\274\244/Vue - 2021.06.22\357\274\210V dotnet \345\221\275\344\273\244\357\274\211.md" => "\346\242\201\350\211\272\347\274\244/Vue - 2021.06.22\357\274\210Api dotnet \345\221\275\344\273\244\357\274\211.md" (100%) rename "\346\242\201\350\211\272\347\274\244/Vue - 2021.06.23\357\274\210V dotnet \345\221\275\344\273\244\357\274\211.md" => "\346\242\201\350\211\272\347\274\244/Vue - 2021.06.23\357\274\210Api RESTful \346\217\222\344\273\266\357\274\211.md" (100%) rename "\346\242\201\350\211\272\347\274\244/Vue - 2021.06.26\357\274\210EF Core\357\274\211.md" => "\346\242\201\350\211\272\347\274\244/Vue - 2021.06.26\357\274\210Api \350\277\236\346\216\245\346\225\260\346\215\256\345\272\223\357\274\211.md" (98%) rename "\346\242\201\350\211\272\347\274\244/Vue - 2021.06.29\357\274\210Api\345\260\201\350\243\205\350\241\250 \345\273\272\347\253\213\350\241\250\344\271\213\351\227\264\345\205\263\347\263\273\357\274\211.md" => "\346\242\201\350\211\272\347\274\244/Vue - 2021.06.29\357\274\210Api \345\260\201\350\243\205\350\241\250 \345\273\272\347\253\213\350\241\250\344\271\213\351\227\264\345\205\263\347\263\273\357\274\211.md" (100%) rename "\346\242\201\350\211\272\347\274\244/Vue - 2021.06.30\357\274\210Api\345\260\201\350\243\205\346\216\245\345\217\243\345\242\236\345\210\240\346\224\271\346\237\245\357\274\211.md" => "\346\242\201\350\211\272\347\274\244/Vue - 2021.06.30\357\274\210Api \345\260\201\350\243\205\346\216\245\345\217\243\345\242\236\345\210\240\346\224\271\346\237\245\357\274\211.md" (100%) diff --git "a/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.22\357\274\210V dotnet \345\221\275\344\273\244\357\274\211.md" "b/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.22\357\274\210Api dotnet \345\221\275\344\273\244\357\274\211.md" similarity index 100% rename from "\346\242\201\350\211\272\347\274\244/Vue - 2021.06.22\357\274\210V dotnet \345\221\275\344\273\244\357\274\211.md" rename to "\346\242\201\350\211\272\347\274\244/Vue - 2021.06.22\357\274\210Api dotnet \345\221\275\344\273\244\357\274\211.md" diff --git "a/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.23\357\274\210V dotnet \345\221\275\344\273\244\357\274\211.md" "b/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.23\357\274\210Api RESTful \346\217\222\344\273\266\357\274\211.md" similarity index 100% rename from "\346\242\201\350\211\272\347\274\244/Vue - 2021.06.23\357\274\210V dotnet \345\221\275\344\273\244\357\274\211.md" rename to "\346\242\201\350\211\272\347\274\244/Vue - 2021.06.23\357\274\210Api RESTful \346\217\222\344\273\266\357\274\211.md" diff --git "a/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.26\357\274\210EF Core\357\274\211.md" "b/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.26\357\274\210Api \350\277\236\346\216\245\346\225\260\346\215\256\345\272\223\357\274\211.md" similarity index 98% rename from "\346\242\201\350\211\272\347\274\244/Vue - 2021.06.26\357\274\210EF Core\357\274\211.md" rename to "\346\242\201\350\211\272\347\274\244/Vue - 2021.06.26\357\274\210Api \350\277\236\346\216\245\346\225\260\346\215\256\345\272\223\357\274\211.md" index 7a0a351..20e8641 100644 --- "a/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.26\357\274\210EF Core\357\274\211.md" +++ "b/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.26\357\274\210Api \350\277\236\346\216\245\346\225\260\346\215\256\345\272\223\357\274\211.md" @@ -1,4 +1,4 @@ -# WebApi 连接数据库 +# Api 连接数据库 # 安装 EF Core diff --git "a/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.29\357\274\210Api\345\260\201\350\243\205\350\241\250 \345\273\272\347\253\213\350\241\250\344\271\213\351\227\264\345\205\263\347\263\273\357\274\211.md" "b/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.29\357\274\210Api \345\260\201\350\243\205\350\241\250 \345\273\272\347\253\213\350\241\250\344\271\213\351\227\264\345\205\263\347\263\273\357\274\211.md" similarity index 100% rename from "\346\242\201\350\211\272\347\274\244/Vue - 2021.06.29\357\274\210Api\345\260\201\350\243\205\350\241\250 \345\273\272\347\253\213\350\241\250\344\271\213\351\227\264\345\205\263\347\263\273\357\274\211.md" rename to "\346\242\201\350\211\272\347\274\244/Vue - 2021.06.29\357\274\210Api \345\260\201\350\243\205\350\241\250 \345\273\272\347\253\213\350\241\250\344\271\213\351\227\264\345\205\263\347\263\273\357\274\211.md" diff --git "a/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.30\357\274\210Api\345\260\201\350\243\205\346\216\245\345\217\243\345\242\236\345\210\240\346\224\271\346\237\245\357\274\211.md" "b/\346\242\201\350\211\272\347\274\244/Vue - 2021.06.30\357\274\210Api \345\260\201\350\243\205\346\216\245\345\217\243\345\242\236\345\210\240\346\224\271\346\237\245\357\274\211.md" similarity index 100% rename from "\346\242\201\350\211\272\347\274\244/Vue - 2021.06.30\357\274\210Api\345\260\201\350\243\205\346\216\245\345\217\243\345\242\236\345\210\240\346\224\271\346\237\245\357\274\211.md" rename to "\346\242\201\350\211\272\347\274\244/Vue - 2021.06.30\357\274\210Api \345\260\201\350\243\205\346\216\245\345\217\243\345\242\236\345\210\240\346\224\271\346\237\245\357\274\211.md" -- Gitee