From 0670d7b6fb37e6928487591167c1349310fa4ee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=93=9D=E6=99=93=E6=A2=85?= <2622290440@qq.com> Date: Sun, 14 Jun 2020 15:42:03 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E8=93=9D=E6=99=93=E6=A2=85=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WebApi07.Server/Class1.cs" | 8 ++ .../WebApi07.Server/WebApi07.Server.csproj" | 7 ++ .../WebApi07.Test/UnitTest1.cs" | 18 +++++ .../WebApi07.Test/WepApi07.Test.csproj" | 15 ++++ .../WebApi07.Util/DbInitializazer.cs" | 55 +++++++++++++ .../Filters/GlobalExceptionFilter.cs" | 33 ++++++++ .../WebApi07.Util/WepApi07.Util.csproj" | 18 +++++ .../WebApi07.sln" | 73 +++++++++++++++++ .../Controllers/WeatherForecastController.cs" | 81 +++++++++++++++++++ .../WebApi07/Program.cs" | 26 ++++++ .../WebApi07/Properties/launchSettings.json" | 30 +++++++ .../WebApi07/Startup.cs" | 62 ++++++++++++++ .../WebApi07/WeatherForecast.cs" | 15 ++++ .../WebApi07/WebApi07.csproj" | 13 +++ .../WebApi07/appsettings.Development.json" | 9 +++ .../WebApi07/appsettings.json" | 10 +++ .../WepApi07.Api/WepApi07.Api.csproj" | 7 ++ .../WepApi07.Date/Admin07Dbcontext.cs" | 22 +++++ .../WepApi07.Date/BaseEntity.cs" | 23 ++++++ .../WepApi07.Date/Entity/Logs.cs" | 16 ++++ .../WepApi07.Date/Entity/Roles.cs" | 12 +++ .../WepApi07.Date/Entity/Users.cs" | 14 ++++ .../WepApi07.Date/WepApi07.Data.csproj" | 12 +++ .../WepApi07.Domain/EfResponsitory.cs" | 80 ++++++++++++++++++ .../WepApi07.Domain/Enum/LogLevel.cs" | 15 ++++ .../WepApi07.Domain/IResponsitory.cs" | 26 ++++++ .../WepApi07.Domain/WepApi07.Domain.csproj" | 11 +++ .../WepApi07.Implement.csproj" | 11 +++ .../WepApi07.Intenface.csproj" | 12 +++ .../WepApi07.Server/WepApi07.Server.csproj" | 7 ++ 30 files changed, 741 insertions(+) create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.Server/Class1.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.Server/WebApi07.Server.csproj" create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.Test/UnitTest1.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.Test/WepApi07.Test.csproj" create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.Util/DbInitializazer.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.Util/Filters/GlobalExceptionFilter.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.Util/WepApi07.Util.csproj" create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.sln" create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/Controllers/WeatherForecastController.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/Program.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/Properties/launchSettings.json" create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/Startup.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/WeatherForecast.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/WebApi07.csproj" create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.Development.json" create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.json" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Api/WepApi07.Api.csproj" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Date/Admin07Dbcontext.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Date/BaseEntity.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Logs.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Roles.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Users.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Date/WepApi07.Data.csproj" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Domain/EfResponsitory.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Domain/Enum/LogLevel.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Domain/IResponsitory.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Domain/WepApi07.Domain.csproj" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Implement/WepApi07.Implement.csproj" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Intenface/WepApi07.Intenface.csproj" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Server/WepApi07.Server.csproj" diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.Server/Class1.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07.Server/Class1.cs" new file mode 100644 index 0000000..ecffa7b --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07.Server/Class1.cs" @@ -0,0 +1,8 @@ +using System; + +namespace WebApi07.Server +{ + public class Class1 + { + } +} diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.Server/WebApi07.Server.csproj" "b/\350\223\235\346\231\223\346\242\205/WebApi07.Server/WebApi07.Server.csproj" new file mode 100644 index 0000000..9f5c4f4 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07.Server/WebApi07.Server.csproj" @@ -0,0 +1,7 @@ + + + + netstandard2.0 + + + diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.Test/UnitTest1.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07.Test/UnitTest1.cs" new file mode 100644 index 0000000..1f50f33 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07.Test/UnitTest1.cs" @@ -0,0 +1,18 @@ +using NUnit.Framework; + +namespace WebApi07.Test +{ + public class Tests + { + [SetUp] + public void Setup() + { + } + + [Test] + public void Test1() + { + Assert.Pass(); + } + } +} \ No newline at end of file diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.Test/WepApi07.Test.csproj" "b/\350\223\235\346\231\223\346\242\205/WebApi07.Test/WepApi07.Test.csproj" new file mode 100644 index 0000000..e532582 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07.Test/WepApi07.Test.csproj" @@ -0,0 +1,15 @@ + + + + netcoreapp3.1 + + false + + + + + + + + + diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.Util/DbInitializazer.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07.Util/DbInitializazer.cs" new file mode 100644 index 0000000..f70b768 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07.Util/DbInitializazer.cs" @@ -0,0 +1,55 @@ +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Internal; +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Collections.Generic; +using System.Text; +using WepApi07.Data; +using WepApi07.Data.Entity; +using WepApi07.Domain; +using System.Linq; + +namespace WepApi07.Util +{ + public class DbInitializazer + { + public static void Seed(IServiceProvider serviceProvider) + { + + using(var scope = serviceProvider.CreateScope()) + { + var db = scope.ServiceProvider.GetService(typeof(Admin07Dbcontext)) as Admin07Dbcontext; + + var _user = scope.ServiceProvider.GetService(typeof(IResponsitory)) as EfResponsitory; + + var _role = scope.ServiceProvider.GetService(typeof(IResponsitory)) as EfResponsitory; + + db.Database.EnsureCreated(); + + var hasUser = db.Users.Any(); + + if (!hasUser) + { + var role = new Roles() + { + RoleName = "名字" + }; + + _role.Insert(role); + + var user = new Users() + { + UserName = "张三", + PassWord = "123456", + Roles = role + }; + + _user.Insert(user); + + } + } + } + + + } +} diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.Util/Filters/GlobalExceptionFilter.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07.Util/Filters/GlobalExceptionFilter.cs" new file mode 100644 index 0000000..7af97f2 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07.Util/Filters/GlobalExceptionFilter.cs" @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Mvc.Filters; +using System; +using System.Collections.Generic; +using System.Text; +using WepApi07.Data.Entity; +using WepApi07.Domain; +using WepApi07.Intenface.Log; +using WepApi07.Util.Log; + +namespace WepApi07.Util.Filters +{ + + public class GlobalExceptionFilter:IExceptionFilter + { + private readonly IResponsitory _log; + + public GlobalExceptionFilter(IResponsitory log) + { + _log = log; + } + public void OnException(ExceptionContext context) + { + _log.Fatal(context.Exception); + + _log.Insert(new Logs + { + + }); + + context.ExceptionHandled = true; + } + } +} diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.Util/WepApi07.Util.csproj" "b/\350\223\235\346\231\223\346\242\205/WebApi07.Util/WepApi07.Util.csproj" new file mode 100644 index 0000000..1e89112 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07.Util/WepApi07.Util.csproj" @@ -0,0 +1,18 @@ + + + + netstandard2.0 + + + + + + + + + + + + + + diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.sln" "b/\350\223\235\346\231\223\346\242\205/WebApi07.sln" new file mode 100644 index 0000000..266e1a4 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07.sln" @@ -0,0 +1,73 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30128.74 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApi07", "WebApi07\WebApi07.csproj", "{76208B82-4470-4568-9729-557FA3A3E09E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Api", "WepApi07.Api\WepApi07.Api.csproj", "{8E2AA62E-7335-4A24-B3E3-416376F83219}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Data", "WepApi07.Date\WepApi07.Data.csproj", "{977081DB-1B43-4454-8353-CCFDC48C8A3A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Domain", "WepApi07.Domain\WepApi07.Domain.csproj", "{7A0585CD-992C-44E2-8DBA-5BC74CB25DB4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Implement", "WepApi07.Implement\WepApi07.Implement.csproj", "{D913F77B-76FE-40CC-A52A-5FACE33A565F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Intenface", "WepApi07.Intenface\WepApi07.Intenface.csproj", "{558257E2-8AE4-436A-85BF-D8AD7F74E5C6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Server", "WepApi07.Server\WepApi07.Server.csproj", "{D15084ED-2E92-441C-A17F-4B98D03D7BA9}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Util", "WebApi07.Util\WepApi07.Util.csproj", "{8E564F87-A362-492F-B11D-A28CEC69163A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Test", "WebApi07.Test\WepApi07.Test.csproj", "{89F5D49D-E3AC-4D9F-82DE-437DEC1F795E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {76208B82-4470-4568-9729-557FA3A3E09E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {76208B82-4470-4568-9729-557FA3A3E09E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {76208B82-4470-4568-9729-557FA3A3E09E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {76208B82-4470-4568-9729-557FA3A3E09E}.Release|Any CPU.Build.0 = Release|Any CPU + {8E2AA62E-7335-4A24-B3E3-416376F83219}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8E2AA62E-7335-4A24-B3E3-416376F83219}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8E2AA62E-7335-4A24-B3E3-416376F83219}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8E2AA62E-7335-4A24-B3E3-416376F83219}.Release|Any CPU.Build.0 = Release|Any CPU + {977081DB-1B43-4454-8353-CCFDC48C8A3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {977081DB-1B43-4454-8353-CCFDC48C8A3A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {977081DB-1B43-4454-8353-CCFDC48C8A3A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {977081DB-1B43-4454-8353-CCFDC48C8A3A}.Release|Any CPU.Build.0 = Release|Any CPU + {7A0585CD-992C-44E2-8DBA-5BC74CB25DB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7A0585CD-992C-44E2-8DBA-5BC74CB25DB4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7A0585CD-992C-44E2-8DBA-5BC74CB25DB4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7A0585CD-992C-44E2-8DBA-5BC74CB25DB4}.Release|Any CPU.Build.0 = Release|Any CPU + {D913F77B-76FE-40CC-A52A-5FACE33A565F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D913F77B-76FE-40CC-A52A-5FACE33A565F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D913F77B-76FE-40CC-A52A-5FACE33A565F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D913F77B-76FE-40CC-A52A-5FACE33A565F}.Release|Any CPU.Build.0 = Release|Any CPU + {558257E2-8AE4-436A-85BF-D8AD7F74E5C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {558257E2-8AE4-436A-85BF-D8AD7F74E5C6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {558257E2-8AE4-436A-85BF-D8AD7F74E5C6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {558257E2-8AE4-436A-85BF-D8AD7F74E5C6}.Release|Any CPU.Build.0 = Release|Any CPU + {D15084ED-2E92-441C-A17F-4B98D03D7BA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D15084ED-2E92-441C-A17F-4B98D03D7BA9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D15084ED-2E92-441C-A17F-4B98D03D7BA9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D15084ED-2E92-441C-A17F-4B98D03D7BA9}.Release|Any CPU.Build.0 = Release|Any CPU + {8E564F87-A362-492F-B11D-A28CEC69163A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8E564F87-A362-492F-B11D-A28CEC69163A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8E564F87-A362-492F-B11D-A28CEC69163A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8E564F87-A362-492F-B11D-A28CEC69163A}.Release|Any CPU.Build.0 = Release|Any CPU + {89F5D49D-E3AC-4D9F-82DE-437DEC1F795E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {89F5D49D-E3AC-4D9F-82DE-437DEC1F795E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {89F5D49D-E3AC-4D9F-82DE-437DEC1F795E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {89F5D49D-E3AC-4D9F-82DE-437DEC1F795E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B20BDEDE-CBB0-4C96-8EB9-4C68A8F39F02} + EndGlobalSection +EndGlobal diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07/Controllers/WeatherForecastController.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07/Controllers/WeatherForecastController.cs" new file mode 100644 index 0000000..22238fa --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07/Controllers/WeatherForecastController.cs" @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using WepApi07.Data.Entity; + +namespace WebApi07.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() + { + Student student = new Student(); + + var res = student.PrintStudent(); + + var stu1 = new Student(); + + var stu2 = new Student(); + + Animals animals = new Animals(); + animals.PrintStudent(); + + throw new Exception("错误:error desc"); + + + + //return (IEnumerable)NotFound("没有操作权限"); + + + 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(); + } + } + + public class Student + { + public string StudentName { get; set; } + public string PrintOk() + { + return this.StudentName; + } + } + + public class Animals + { + + } + + public static class StudentHelper + { + public static string PrintStudent(this Animals stu) + { + return "美国英短"; + } + } + +} diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07/Program.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07/Program.cs" new file mode 100644 index 0000000..d097157 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07/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 WebApi07 +{ + 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/\350\223\235\346\231\223\346\242\205/WebApi07/Properties/launchSettings.json" "b/\350\223\235\346\231\223\346\242\205/WebApi07/Properties/launchSettings.json" new file mode 100644 index 0000000..a3d649a --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07/Properties/launchSettings.json" @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:52440", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "WebApi07": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "applicationUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07/Startup.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07/Startup.cs" new file mode 100644 index 0000000..c7d21dc --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07/Startup.cs" @@ -0,0 +1,62 @@ +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; +using WepApi07.Data; +using WepApi07.Domain; +using WepApi07.Implement.Log; +using WepApi07.Intenface.Log; +using WepApi07.Util; +using WepApi07.Util.Filters; + +namespace WebApi07 +{ + 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(options =>options.Filters.Add()); + services.AddDbContext(); + + services.AddScoped(typeof(IResponsitory<>), typeof(EfResponsitory<>)); + services.AddControllers(); + + services.AddScoped(typeof(ILog), typeof(Log)); + } + + // 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(); + }); + + DbInitializazer.Seed(app.ApplicationServices); + } + } +} diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07/WeatherForecast.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07/WeatherForecast.cs" new file mode 100644 index 0000000..2fc6b95 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07/WeatherForecast.cs" @@ -0,0 +1,15 @@ +using System; + +namespace WebApi07 +{ + 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/\350\223\235\346\231\223\346\242\205/WebApi07/WebApi07.csproj" "b/\350\223\235\346\231\223\346\242\205/WebApi07/WebApi07.csproj" new file mode 100644 index 0000000..24cc6ef --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07/WebApi07.csproj" @@ -0,0 +1,13 @@ + + + + netcoreapp3.1 + + + + + + + + + diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.Development.json" "b/\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.Development.json" new file mode 100644 index 0000000..8983e0f --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.Development.json" @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.json" "b/\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.json" new file mode 100644 index 0000000..d9d9a9b --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.json" @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Api/WepApi07.Api.csproj" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Api/WepApi07.Api.csproj" new file mode 100644 index 0000000..9f5c4f4 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Api/WepApi07.Api.csproj" @@ -0,0 +1,7 @@ + + + + netstandard2.0 + + + diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Admin07Dbcontext.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Admin07Dbcontext.cs" new file mode 100644 index 0000000..db8e621 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Admin07Dbcontext.cs" @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Text; +using WepApi07.Data.Entity; + +namespace WepApi07.Data +{ + public class Admin07Dbcontext:DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + var str = "server=.;database=Admin07;uid=sa;pwd=A123456"; + optionsBuilder.UseSqlServer(str); + } + + public DbSet Users { get; set; } + public DbSet Roles { get; set; } + + public DbSet Logs { get; set; } + } +} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/BaseEntity.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/BaseEntity.cs" new file mode 100644 index 0000000..4570046 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/BaseEntity.cs" @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WepApi07.Data +{ + public abstract class BaseEntity + { + public BaseEntity() + { + IsActived = true; + IsDeleted = false; + CreatedTime = DateTime.Now; + UpdatedTime = DateTime.Now; + } + + 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; } + } +} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Logs.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Logs.cs" new file mode 100644 index 0000000..e311789 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Logs.cs" @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WepApi07.Data.Entity +{ + public class Logs:BaseEntity + { + public int LogLevel { get; set; } + + public string ShortMessage { get; set; } + public string FullMessage { get; set; } + public int UserId { get; set; } + public string ReferenceUrl { get; set; } + } +} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Roles.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Roles.cs" new file mode 100644 index 0000000..3f3753e --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Roles.cs" @@ -0,0 +1,12 @@ +using System.Collections; +using System.Collections.Generic; + +namespace WepApi07.Data.Entity +{ + public class Roles:BaseEntity + { + public string RoleName { get; set; } + + public IEnumerable User { get; set; } + } +} \ No newline at end of file diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Users.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Users.cs" new file mode 100644 index 0000000..afe62c7 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Users.cs" @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WepApi07.Data.Entity +{ + public class Users:BaseEntity + { + public string UserName { get; set; } + public string PassWord { get; set; } + + public Roles Roles { get; set; } + } +} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/WepApi07.Data.csproj" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/WepApi07.Data.csproj" new file mode 100644 index 0000000..bc7806e --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/WepApi07.Data.csproj" @@ -0,0 +1,12 @@ + + + + netstandard2.0 + + + + + + + + diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/EfResponsitory.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/EfResponsitory.cs" new file mode 100644 index 0000000..59fa32c --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/EfResponsitory.cs" @@ -0,0 +1,80 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using WepApi07.Data; + +namespace WepApi07.Domain +{ + public class EfResponsitory : IResponsitory where T : BaseEntity + { + private readonly Admin07Dbcontext db; + public EfResponsitory(Admin07Dbcontext admin) + { + db = admin; + } + + private DbSet _entity; + + private DbSet Entity + { + get + { + if (_entity == null) + { + _entity = db.Set(); + } + return _entity; + } + } + public IQueryable Table + { get + { + return _entity; + } + } + + public void Delete(int id) + { + var row = Table.Where(x => x.Id == id).FirstOrDefault(); + Delete(row); + } + + public void Delete(T entity) + { + Entity.Remove(entity); + db.SaveChanges(); + } + + public void Insert(T entity) + { + Entity.Add(entity); + db.SaveChanges(); + } + + public void InsertBulk(IEnumerable entity) + { + + Entity.AddRange(entity); + db.SaveChanges(); + } + + public void Update(T entity) + { + Entity.Update(entity); + db.SaveChanges(); + } + + public void Delete(IEnumerable entities) + { + Entity.RemoveRange(entities); + db.SaveChanges(); + } + + public T GetById(int id) + { + return Entity.Where(x => x.Id == id).FirstOrDefault(); + } + } +} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/Enum/LogLevel.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/Enum/LogLevel.cs" new file mode 100644 index 0000000..ae0a0f0 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/Enum/LogLevel.cs" @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WepApi07.Domain.Enum +{ + public enum LogsLevel + { + 警告=10, + 调试=20, + 信息=30, + 错误=40, + 崩溃=50 + } +} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/IResponsitory.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/IResponsitory.cs" new file mode 100644 index 0000000..144eed5 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/IResponsitory.cs" @@ -0,0 +1,26 @@ +using Microsoft.EntityFrameworkCore.ChangeTracking; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace WepApi07.Domain +{ + public interface IResponsitory + { + IQueryable Table { get; } + void Insert(T entity); + + void InsertBulk(IEnumerable entity); + + void Delete(int id); + + void Delete(T entity); + + void Delete(IEnumerable entities); + + void Update(T entity); + + T GetById(int id); + } +} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/WepApi07.Domain.csproj" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/WepApi07.Domain.csproj" new file mode 100644 index 0000000..c0740cf --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/WepApi07.Domain.csproj" @@ -0,0 +1,11 @@ + + + + netstandard2.0 + + + + + + + diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Implement/WepApi07.Implement.csproj" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Implement/WepApi07.Implement.csproj" new file mode 100644 index 0000000..7080721 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Implement/WepApi07.Implement.csproj" @@ -0,0 +1,11 @@ + + + + netstandard2.0 + + + + + + + diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Intenface/WepApi07.Intenface.csproj" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Intenface/WepApi07.Intenface.csproj" new file mode 100644 index 0000000..70849b3 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Intenface/WepApi07.Intenface.csproj" @@ -0,0 +1,12 @@ + + + + netstandard2.0 + + + + + + + + diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Server/WepApi07.Server.csproj" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Server/WepApi07.Server.csproj" new file mode 100644 index 0000000..9f5c4f4 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Server/WepApi07.Server.csproj" @@ -0,0 +1,7 @@ + + + + netstandard2.0 + + + -- Gitee From faa007c582afcd921452b128d3e9048f99f3e4f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=93=9D=E6=99=93=E6=A2=85?= <7371318+lan_xiaomei@user.noreply.gitee.com> Date: Sun, 14 Jun 2020 22:23:48 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?=E8=93=9D=E6=99=93=E6=A2=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WebApi07.Server/Class1.cs" | 8 -- .../WebApi07.Server/WebApi07.Server.csproj" | 7 -- .../WebApi07.Test/UnitTest1.cs" | 18 ----- .../WebApi07.Test/WepApi07.Test.csproj" | 15 ---- .../WebApi07.Util/DbInitializazer.cs" | 55 ------------- .../Filters/GlobalExceptionFilter.cs" | 33 -------- .../WebApi07.Util/WepApi07.Util.csproj" | 18 ----- .../WebApi07.sln" | 73 ----------------- .../Controllers/WeatherForecastController.cs" | 81 ------------------- .../WebApi07/Program.cs" | 26 ------ .../WebApi07/Properties/launchSettings.json" | 30 ------- .../WebApi07/Startup.cs" | 62 -------------- .../WebApi07/WeatherForecast.cs" | 15 ---- .../WebApi07/WebApi07.csproj" | 13 --- .../WebApi07/appsettings.Development.json" | 9 --- .../WebApi07/appsettings.json" | 10 --- .../WepApi07.Api/WepApi07.Api.csproj" | 7 -- .../WepApi07.Date/Admin07Dbcontext.cs" | 22 ----- .../WepApi07.Date/BaseEntity.cs" | 23 ------ .../WepApi07.Date/Entity/Logs.cs" | 16 ---- .../WepApi07.Date/Entity/Roles.cs" | 12 --- .../WepApi07.Date/Entity/Users.cs" | 14 ---- .../WepApi07.Date/WepApi07.Data.csproj" | 12 --- .../WepApi07.Domain/EfResponsitory.cs" | 80 ------------------ .../WepApi07.Domain/Enum/LogLevel.cs" | 15 ---- .../WepApi07.Domain/IResponsitory.cs" | 26 ------ .../WepApi07.Domain/WepApi07.Domain.csproj" | 11 --- .../WepApi07.Implement.csproj" | 11 --- .../WepApi07.Intenface.csproj" | 12 --- .../WepApi07.Server/WepApi07.Server.csproj" | 7 -- 30 files changed, 741 deletions(-) delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.Server/Class1.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.Server/WebApi07.Server.csproj" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.Test/UnitTest1.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.Test/WepApi07.Test.csproj" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.Util/DbInitializazer.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.Util/Filters/GlobalExceptionFilter.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.Util/WepApi07.Util.csproj" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.sln" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/Controllers/WeatherForecastController.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/Program.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/Properties/launchSettings.json" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/Startup.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/WeatherForecast.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/WebApi07.csproj" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.Development.json" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.json" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Api/WepApi07.Api.csproj" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Date/Admin07Dbcontext.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Date/BaseEntity.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Logs.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Roles.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Users.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Date/WepApi07.Data.csproj" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Domain/EfResponsitory.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Domain/Enum/LogLevel.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Domain/IResponsitory.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Domain/WepApi07.Domain.csproj" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Implement/WepApi07.Implement.csproj" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Intenface/WepApi07.Intenface.csproj" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Server/WepApi07.Server.csproj" diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.Server/Class1.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07.Server/Class1.cs" deleted file mode 100644 index ecffa7b..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07.Server/Class1.cs" +++ /dev/null @@ -1,8 +0,0 @@ -using System; - -namespace WebApi07.Server -{ - public class Class1 - { - } -} diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.Server/WebApi07.Server.csproj" "b/\350\223\235\346\231\223\346\242\205/WebApi07.Server/WebApi07.Server.csproj" deleted file mode 100644 index 9f5c4f4..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07.Server/WebApi07.Server.csproj" +++ /dev/null @@ -1,7 +0,0 @@ - - - - netstandard2.0 - - - diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.Test/UnitTest1.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07.Test/UnitTest1.cs" deleted file mode 100644 index 1f50f33..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07.Test/UnitTest1.cs" +++ /dev/null @@ -1,18 +0,0 @@ -using NUnit.Framework; - -namespace WebApi07.Test -{ - public class Tests - { - [SetUp] - public void Setup() - { - } - - [Test] - public void Test1() - { - Assert.Pass(); - } - } -} \ No newline at end of file diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.Test/WepApi07.Test.csproj" "b/\350\223\235\346\231\223\346\242\205/WebApi07.Test/WepApi07.Test.csproj" deleted file mode 100644 index e532582..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07.Test/WepApi07.Test.csproj" +++ /dev/null @@ -1,15 +0,0 @@ - - - - netcoreapp3.1 - - false - - - - - - - - - diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.Util/DbInitializazer.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07.Util/DbInitializazer.cs" deleted file mode 100644 index f70b768..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07.Util/DbInitializazer.cs" +++ /dev/null @@ -1,55 +0,0 @@ -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Internal; -using Microsoft.Extensions.DependencyInjection; -using System; -using System.Collections.Generic; -using System.Text; -using WepApi07.Data; -using WepApi07.Data.Entity; -using WepApi07.Domain; -using System.Linq; - -namespace WepApi07.Util -{ - public class DbInitializazer - { - public static void Seed(IServiceProvider serviceProvider) - { - - using(var scope = serviceProvider.CreateScope()) - { - var db = scope.ServiceProvider.GetService(typeof(Admin07Dbcontext)) as Admin07Dbcontext; - - var _user = scope.ServiceProvider.GetService(typeof(IResponsitory)) as EfResponsitory; - - var _role = scope.ServiceProvider.GetService(typeof(IResponsitory)) as EfResponsitory; - - db.Database.EnsureCreated(); - - var hasUser = db.Users.Any(); - - if (!hasUser) - { - var role = new Roles() - { - RoleName = "名字" - }; - - _role.Insert(role); - - var user = new Users() - { - UserName = "张三", - PassWord = "123456", - Roles = role - }; - - _user.Insert(user); - - } - } - } - - - } -} diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.Util/Filters/GlobalExceptionFilter.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07.Util/Filters/GlobalExceptionFilter.cs" deleted file mode 100644 index 7af97f2..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07.Util/Filters/GlobalExceptionFilter.cs" +++ /dev/null @@ -1,33 +0,0 @@ -using Microsoft.AspNetCore.Mvc.Filters; -using System; -using System.Collections.Generic; -using System.Text; -using WepApi07.Data.Entity; -using WepApi07.Domain; -using WepApi07.Intenface.Log; -using WepApi07.Util.Log; - -namespace WepApi07.Util.Filters -{ - - public class GlobalExceptionFilter:IExceptionFilter - { - private readonly IResponsitory _log; - - public GlobalExceptionFilter(IResponsitory log) - { - _log = log; - } - public void OnException(ExceptionContext context) - { - _log.Fatal(context.Exception); - - _log.Insert(new Logs - { - - }); - - context.ExceptionHandled = true; - } - } -} diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.Util/WepApi07.Util.csproj" "b/\350\223\235\346\231\223\346\242\205/WebApi07.Util/WepApi07.Util.csproj" deleted file mode 100644 index 1e89112..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07.Util/WepApi07.Util.csproj" +++ /dev/null @@ -1,18 +0,0 @@ - - - - netstandard2.0 - - - - - - - - - - - - - - diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.sln" "b/\350\223\235\346\231\223\346\242\205/WebApi07.sln" deleted file mode 100644 index 266e1a4..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07.sln" +++ /dev/null @@ -1,73 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30128.74 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApi07", "WebApi07\WebApi07.csproj", "{76208B82-4470-4568-9729-557FA3A3E09E}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Api", "WepApi07.Api\WepApi07.Api.csproj", "{8E2AA62E-7335-4A24-B3E3-416376F83219}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Data", "WepApi07.Date\WepApi07.Data.csproj", "{977081DB-1B43-4454-8353-CCFDC48C8A3A}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Domain", "WepApi07.Domain\WepApi07.Domain.csproj", "{7A0585CD-992C-44E2-8DBA-5BC74CB25DB4}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Implement", "WepApi07.Implement\WepApi07.Implement.csproj", "{D913F77B-76FE-40CC-A52A-5FACE33A565F}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Intenface", "WepApi07.Intenface\WepApi07.Intenface.csproj", "{558257E2-8AE4-436A-85BF-D8AD7F74E5C6}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Server", "WepApi07.Server\WepApi07.Server.csproj", "{D15084ED-2E92-441C-A17F-4B98D03D7BA9}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Util", "WebApi07.Util\WepApi07.Util.csproj", "{8E564F87-A362-492F-B11D-A28CEC69163A}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Test", "WebApi07.Test\WepApi07.Test.csproj", "{89F5D49D-E3AC-4D9F-82DE-437DEC1F795E}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {76208B82-4470-4568-9729-557FA3A3E09E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {76208B82-4470-4568-9729-557FA3A3E09E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {76208B82-4470-4568-9729-557FA3A3E09E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {76208B82-4470-4568-9729-557FA3A3E09E}.Release|Any CPU.Build.0 = Release|Any CPU - {8E2AA62E-7335-4A24-B3E3-416376F83219}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8E2AA62E-7335-4A24-B3E3-416376F83219}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8E2AA62E-7335-4A24-B3E3-416376F83219}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8E2AA62E-7335-4A24-B3E3-416376F83219}.Release|Any CPU.Build.0 = Release|Any CPU - {977081DB-1B43-4454-8353-CCFDC48C8A3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {977081DB-1B43-4454-8353-CCFDC48C8A3A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {977081DB-1B43-4454-8353-CCFDC48C8A3A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {977081DB-1B43-4454-8353-CCFDC48C8A3A}.Release|Any CPU.Build.0 = Release|Any CPU - {7A0585CD-992C-44E2-8DBA-5BC74CB25DB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7A0585CD-992C-44E2-8DBA-5BC74CB25DB4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7A0585CD-992C-44E2-8DBA-5BC74CB25DB4}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7A0585CD-992C-44E2-8DBA-5BC74CB25DB4}.Release|Any CPU.Build.0 = Release|Any CPU - {D913F77B-76FE-40CC-A52A-5FACE33A565F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D913F77B-76FE-40CC-A52A-5FACE33A565F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D913F77B-76FE-40CC-A52A-5FACE33A565F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D913F77B-76FE-40CC-A52A-5FACE33A565F}.Release|Any CPU.Build.0 = Release|Any CPU - {558257E2-8AE4-436A-85BF-D8AD7F74E5C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {558257E2-8AE4-436A-85BF-D8AD7F74E5C6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {558257E2-8AE4-436A-85BF-D8AD7F74E5C6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {558257E2-8AE4-436A-85BF-D8AD7F74E5C6}.Release|Any CPU.Build.0 = Release|Any CPU - {D15084ED-2E92-441C-A17F-4B98D03D7BA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D15084ED-2E92-441C-A17F-4B98D03D7BA9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D15084ED-2E92-441C-A17F-4B98D03D7BA9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D15084ED-2E92-441C-A17F-4B98D03D7BA9}.Release|Any CPU.Build.0 = Release|Any CPU - {8E564F87-A362-492F-B11D-A28CEC69163A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8E564F87-A362-492F-B11D-A28CEC69163A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8E564F87-A362-492F-B11D-A28CEC69163A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8E564F87-A362-492F-B11D-A28CEC69163A}.Release|Any CPU.Build.0 = Release|Any CPU - {89F5D49D-E3AC-4D9F-82DE-437DEC1F795E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {89F5D49D-E3AC-4D9F-82DE-437DEC1F795E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {89F5D49D-E3AC-4D9F-82DE-437DEC1F795E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {89F5D49D-E3AC-4D9F-82DE-437DEC1F795E}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {B20BDEDE-CBB0-4C96-8EB9-4C68A8F39F02} - EndGlobalSection -EndGlobal diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07/Controllers/WeatherForecastController.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07/Controllers/WeatherForecastController.cs" deleted file mode 100644 index 22238fa..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07/Controllers/WeatherForecastController.cs" +++ /dev/null @@ -1,81 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; -using WepApi07.Data.Entity; - -namespace WebApi07.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() - { - Student student = new Student(); - - var res = student.PrintStudent(); - - var stu1 = new Student(); - - var stu2 = new Student(); - - Animals animals = new Animals(); - animals.PrintStudent(); - - throw new Exception("错误:error desc"); - - - - //return (IEnumerable)NotFound("没有操作权限"); - - - 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(); - } - } - - public class Student - { - public string StudentName { get; set; } - public string PrintOk() - { - return this.StudentName; - } - } - - public class Animals - { - - } - - public static class StudentHelper - { - public static string PrintStudent(this Animals stu) - { - return "美国英短"; - } - } - -} diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07/Program.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07/Program.cs" deleted file mode 100644 index d097157..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07/Program.cs" +++ /dev/null @@ -1,26 +0,0 @@ -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 WebApi07 -{ - 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/\350\223\235\346\231\223\346\242\205/WebApi07/Properties/launchSettings.json" "b/\350\223\235\346\231\223\346\242\205/WebApi07/Properties/launchSettings.json" deleted file mode 100644 index a3d649a..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07/Properties/launchSettings.json" +++ /dev/null @@ -1,30 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/launchsettings.json", - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:52440", - "sslPort": 0 - } - }, - "profiles": { - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "launchUrl": "weatherforecast", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "WebApi07": { - "commandName": "Project", - "launchBrowser": true, - "launchUrl": "weatherforecast", - "applicationUrl": "http://localhost:5000", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - } - } -} diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07/Startup.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07/Startup.cs" deleted file mode 100644 index c7d21dc..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07/Startup.cs" +++ /dev/null @@ -1,62 +0,0 @@ -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; -using WepApi07.Data; -using WepApi07.Domain; -using WepApi07.Implement.Log; -using WepApi07.Intenface.Log; -using WepApi07.Util; -using WepApi07.Util.Filters; - -namespace WebApi07 -{ - 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(options =>options.Filters.Add()); - services.AddDbContext(); - - services.AddScoped(typeof(IResponsitory<>), typeof(EfResponsitory<>)); - services.AddControllers(); - - services.AddScoped(typeof(ILog), typeof(Log)); - } - - // 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(); - }); - - DbInitializazer.Seed(app.ApplicationServices); - } - } -} diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07/WeatherForecast.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07/WeatherForecast.cs" deleted file mode 100644 index 2fc6b95..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07/WeatherForecast.cs" +++ /dev/null @@ -1,15 +0,0 @@ -using System; - -namespace WebApi07 -{ - 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/\350\223\235\346\231\223\346\242\205/WebApi07/WebApi07.csproj" "b/\350\223\235\346\231\223\346\242\205/WebApi07/WebApi07.csproj" deleted file mode 100644 index 24cc6ef..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07/WebApi07.csproj" +++ /dev/null @@ -1,13 +0,0 @@ - - - - netcoreapp3.1 - - - - - - - - - diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.Development.json" "b/\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.Development.json" deleted file mode 100644 index 8983e0f..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.Development.json" +++ /dev/null @@ -1,9 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" - } - } -} diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.json" "b/\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.json" deleted file mode 100644 index d9d9a9b..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" - } - }, - "AllowedHosts": "*" -} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Api/WepApi07.Api.csproj" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Api/WepApi07.Api.csproj" deleted file mode 100644 index 9f5c4f4..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WepApi07.Api/WepApi07.Api.csproj" +++ /dev/null @@ -1,7 +0,0 @@ - - - - netstandard2.0 - - - diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Admin07Dbcontext.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Admin07Dbcontext.cs" deleted file mode 100644 index db8e621..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Admin07Dbcontext.cs" +++ /dev/null @@ -1,22 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Text; -using WepApi07.Data.Entity; - -namespace WepApi07.Data -{ - public class Admin07Dbcontext:DbContext - { - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - var str = "server=.;database=Admin07;uid=sa;pwd=A123456"; - optionsBuilder.UseSqlServer(str); - } - - public DbSet Users { get; set; } - public DbSet Roles { get; set; } - - public DbSet Logs { get; set; } - } -} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/BaseEntity.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/BaseEntity.cs" deleted file mode 100644 index 4570046..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/BaseEntity.cs" +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace WepApi07.Data -{ - public abstract class BaseEntity - { - public BaseEntity() - { - IsActived = true; - IsDeleted = false; - CreatedTime = DateTime.Now; - UpdatedTime = DateTime.Now; - } - - 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; } - } -} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Logs.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Logs.cs" deleted file mode 100644 index e311789..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Logs.cs" +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace WepApi07.Data.Entity -{ - public class Logs:BaseEntity - { - public int LogLevel { get; set; } - - public string ShortMessage { get; set; } - public string FullMessage { get; set; } - public int UserId { get; set; } - public string ReferenceUrl { get; set; } - } -} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Roles.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Roles.cs" deleted file mode 100644 index 3f3753e..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Roles.cs" +++ /dev/null @@ -1,12 +0,0 @@ -using System.Collections; -using System.Collections.Generic; - -namespace WepApi07.Data.Entity -{ - public class Roles:BaseEntity - { - public string RoleName { get; set; } - - public IEnumerable User { get; set; } - } -} \ No newline at end of file diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Users.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Users.cs" deleted file mode 100644 index afe62c7..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Users.cs" +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace WepApi07.Data.Entity -{ - public class Users:BaseEntity - { - public string UserName { get; set; } - public string PassWord { get; set; } - - public Roles Roles { get; set; } - } -} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/WepApi07.Data.csproj" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/WepApi07.Data.csproj" deleted file mode 100644 index bc7806e..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/WepApi07.Data.csproj" +++ /dev/null @@ -1,12 +0,0 @@ - - - - netstandard2.0 - - - - - - - - diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/EfResponsitory.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/EfResponsitory.cs" deleted file mode 100644 index 59fa32c..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/EfResponsitory.cs" +++ /dev/null @@ -1,80 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using WepApi07.Data; - -namespace WepApi07.Domain -{ - public class EfResponsitory : IResponsitory where T : BaseEntity - { - private readonly Admin07Dbcontext db; - public EfResponsitory(Admin07Dbcontext admin) - { - db = admin; - } - - private DbSet _entity; - - private DbSet Entity - { - get - { - if (_entity == null) - { - _entity = db.Set(); - } - return _entity; - } - } - public IQueryable Table - { get - { - return _entity; - } - } - - public void Delete(int id) - { - var row = Table.Where(x => x.Id == id).FirstOrDefault(); - Delete(row); - } - - public void Delete(T entity) - { - Entity.Remove(entity); - db.SaveChanges(); - } - - public void Insert(T entity) - { - Entity.Add(entity); - db.SaveChanges(); - } - - public void InsertBulk(IEnumerable entity) - { - - Entity.AddRange(entity); - db.SaveChanges(); - } - - public void Update(T entity) - { - Entity.Update(entity); - db.SaveChanges(); - } - - public void Delete(IEnumerable entities) - { - Entity.RemoveRange(entities); - db.SaveChanges(); - } - - public T GetById(int id) - { - return Entity.Where(x => x.Id == id).FirstOrDefault(); - } - } -} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/Enum/LogLevel.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/Enum/LogLevel.cs" deleted file mode 100644 index ae0a0f0..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/Enum/LogLevel.cs" +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace WepApi07.Domain.Enum -{ - public enum LogsLevel - { - 警告=10, - 调试=20, - 信息=30, - 错误=40, - 崩溃=50 - } -} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/IResponsitory.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/IResponsitory.cs" deleted file mode 100644 index 144eed5..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/IResponsitory.cs" +++ /dev/null @@ -1,26 +0,0 @@ -using Microsoft.EntityFrameworkCore.ChangeTracking; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace WepApi07.Domain -{ - public interface IResponsitory - { - IQueryable Table { get; } - void Insert(T entity); - - void InsertBulk(IEnumerable entity); - - void Delete(int id); - - void Delete(T entity); - - void Delete(IEnumerable entities); - - void Update(T entity); - - T GetById(int id); - } -} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/WepApi07.Domain.csproj" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/WepApi07.Domain.csproj" deleted file mode 100644 index c0740cf..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/WepApi07.Domain.csproj" +++ /dev/null @@ -1,11 +0,0 @@ - - - - netstandard2.0 - - - - - - - diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Implement/WepApi07.Implement.csproj" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Implement/WepApi07.Implement.csproj" deleted file mode 100644 index 7080721..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WepApi07.Implement/WepApi07.Implement.csproj" +++ /dev/null @@ -1,11 +0,0 @@ - - - - netstandard2.0 - - - - - - - diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Intenface/WepApi07.Intenface.csproj" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Intenface/WepApi07.Intenface.csproj" deleted file mode 100644 index 70849b3..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WepApi07.Intenface/WepApi07.Intenface.csproj" +++ /dev/null @@ -1,12 +0,0 @@ - - - - netstandard2.0 - - - - - - - - diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Server/WepApi07.Server.csproj" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Server/WepApi07.Server.csproj" deleted file mode 100644 index 9f5c4f4..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WepApi07.Server/WepApi07.Server.csproj" +++ /dev/null @@ -1,7 +0,0 @@ - - - - netstandard2.0 - - - -- Gitee From 1062eb7b4d03ec4ab972d4669eb280634a1b1401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=93=9D=E6=99=93=E6=A2=85?= <2622290440@qq.com> Date: Sun, 14 Jun 2020 23:05:24 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=89=E4=B8=AALog?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WebApi07.Server/Class1.cs" | 8 ++ .../WebApi07.Server/WebApi07.Server.csproj" | 7 ++ .../WebApi07.Test/UnitTest1.cs" | 18 +++++ .../WebApi07.Test/WepApi07.Test.csproj" | 15 ++++ .../WebApi07.Util/DbInitializazer.cs" | 55 +++++++++++++ .../Filters/GlobalExceptionFilter.cs" | 33 ++++++++ .../WebApi07.Util/WepApi07.Util.csproj" | 18 +++++ .../WebApi07.sln" | 73 +++++++++++++++++ .../Controllers/WeatherForecastController.cs" | 81 +++++++++++++++++++ .../WebApi07/Program.cs" | 26 ++++++ .../WebApi07/Properties/launchSettings.json" | 30 +++++++ .../WebApi07/Startup.cs" | 62 ++++++++++++++ .../WebApi07/WeatherForecast.cs" | 15 ++++ .../WebApi07/WebApi07.csproj" | 13 +++ .../WebApi07/appsettings.Development.json" | 9 +++ .../WebApi07/appsettings.json" | 10 +++ .../WepApi07.Api/WepApi07.Api.csproj" | 7 ++ .../WepApi07.Date/Admin07Dbcontext.cs" | 22 +++++ .../WepApi07.Date/BaseEntity.cs" | 23 ++++++ .../WepApi07.Date/Entity/Logs.cs" | 16 ++++ .../WepApi07.Date/Entity/Roles.cs" | 12 +++ .../WepApi07.Date/Entity/Users.cs" | 14 ++++ .../WepApi07.Date/WepApi07.Data.csproj" | 12 +++ .../WepApi07.Domain/EfResponsitory.cs" | 80 ++++++++++++++++++ .../WepApi07.Domain/Enum/LogLevel.cs" | 15 ++++ .../WepApi07.Domain/IResponsitory.cs" | 26 ++++++ .../WepApi07.Domain/WepApi07.Domain.csproj" | 11 +++ .../WepApi07.Implement.csproj" | 11 +++ .../WepApi07.Intenface/Log/ILog.cs" | 21 +++++ .../WepApi07.Intenface.csproj" | 12 +++ .../WepApi07.Server/WepApi07.Server.csproj" | 7 ++ 31 files changed, 762 insertions(+) create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.Server/Class1.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.Server/WebApi07.Server.csproj" create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.Test/UnitTest1.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.Test/WepApi07.Test.csproj" create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.Util/DbInitializazer.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.Util/Filters/GlobalExceptionFilter.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.Util/WepApi07.Util.csproj" create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.sln" create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/Controllers/WeatherForecastController.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/Program.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/Properties/launchSettings.json" create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/Startup.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/WeatherForecast.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/WebApi07.csproj" create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.Development.json" create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.json" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Api/WepApi07.Api.csproj" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Date/Admin07Dbcontext.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Date/BaseEntity.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Logs.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Roles.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Users.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Date/WepApi07.Data.csproj" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Domain/EfResponsitory.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Domain/Enum/LogLevel.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Domain/IResponsitory.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Domain/WepApi07.Domain.csproj" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Implement/WepApi07.Implement.csproj" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Intenface/Log/ILog.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Intenface/WepApi07.Intenface.csproj" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Server/WepApi07.Server.csproj" diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.Server/Class1.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07.Server/Class1.cs" new file mode 100644 index 0000000..ecffa7b --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07.Server/Class1.cs" @@ -0,0 +1,8 @@ +using System; + +namespace WebApi07.Server +{ + public class Class1 + { + } +} diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.Server/WebApi07.Server.csproj" "b/\350\223\235\346\231\223\346\242\205/WebApi07.Server/WebApi07.Server.csproj" new file mode 100644 index 0000000..9f5c4f4 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07.Server/WebApi07.Server.csproj" @@ -0,0 +1,7 @@ + + + + netstandard2.0 + + + diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.Test/UnitTest1.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07.Test/UnitTest1.cs" new file mode 100644 index 0000000..1f50f33 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07.Test/UnitTest1.cs" @@ -0,0 +1,18 @@ +using NUnit.Framework; + +namespace WebApi07.Test +{ + public class Tests + { + [SetUp] + public void Setup() + { + } + + [Test] + public void Test1() + { + Assert.Pass(); + } + } +} \ No newline at end of file diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.Test/WepApi07.Test.csproj" "b/\350\223\235\346\231\223\346\242\205/WebApi07.Test/WepApi07.Test.csproj" new file mode 100644 index 0000000..e532582 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07.Test/WepApi07.Test.csproj" @@ -0,0 +1,15 @@ + + + + netcoreapp3.1 + + false + + + + + + + + + diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.Util/DbInitializazer.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07.Util/DbInitializazer.cs" new file mode 100644 index 0000000..f70b768 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07.Util/DbInitializazer.cs" @@ -0,0 +1,55 @@ +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Internal; +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Collections.Generic; +using System.Text; +using WepApi07.Data; +using WepApi07.Data.Entity; +using WepApi07.Domain; +using System.Linq; + +namespace WepApi07.Util +{ + public class DbInitializazer + { + public static void Seed(IServiceProvider serviceProvider) + { + + using(var scope = serviceProvider.CreateScope()) + { + var db = scope.ServiceProvider.GetService(typeof(Admin07Dbcontext)) as Admin07Dbcontext; + + var _user = scope.ServiceProvider.GetService(typeof(IResponsitory)) as EfResponsitory; + + var _role = scope.ServiceProvider.GetService(typeof(IResponsitory)) as EfResponsitory; + + db.Database.EnsureCreated(); + + var hasUser = db.Users.Any(); + + if (!hasUser) + { + var role = new Roles() + { + RoleName = "名字" + }; + + _role.Insert(role); + + var user = new Users() + { + UserName = "张三", + PassWord = "123456", + Roles = role + }; + + _user.Insert(user); + + } + } + } + + + } +} diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.Util/Filters/GlobalExceptionFilter.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07.Util/Filters/GlobalExceptionFilter.cs" new file mode 100644 index 0000000..7af97f2 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07.Util/Filters/GlobalExceptionFilter.cs" @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Mvc.Filters; +using System; +using System.Collections.Generic; +using System.Text; +using WepApi07.Data.Entity; +using WepApi07.Domain; +using WepApi07.Intenface.Log; +using WepApi07.Util.Log; + +namespace WepApi07.Util.Filters +{ + + public class GlobalExceptionFilter:IExceptionFilter + { + private readonly IResponsitory _log; + + public GlobalExceptionFilter(IResponsitory log) + { + _log = log; + } + public void OnException(ExceptionContext context) + { + _log.Fatal(context.Exception); + + _log.Insert(new Logs + { + + }); + + context.ExceptionHandled = true; + } + } +} diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.Util/WepApi07.Util.csproj" "b/\350\223\235\346\231\223\346\242\205/WebApi07.Util/WepApi07.Util.csproj" new file mode 100644 index 0000000..1e89112 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07.Util/WepApi07.Util.csproj" @@ -0,0 +1,18 @@ + + + + netstandard2.0 + + + + + + + + + + + + + + diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.sln" "b/\350\223\235\346\231\223\346\242\205/WebApi07.sln" new file mode 100644 index 0000000..266e1a4 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07.sln" @@ -0,0 +1,73 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30128.74 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApi07", "WebApi07\WebApi07.csproj", "{76208B82-4470-4568-9729-557FA3A3E09E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Api", "WepApi07.Api\WepApi07.Api.csproj", "{8E2AA62E-7335-4A24-B3E3-416376F83219}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Data", "WepApi07.Date\WepApi07.Data.csproj", "{977081DB-1B43-4454-8353-CCFDC48C8A3A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Domain", "WepApi07.Domain\WepApi07.Domain.csproj", "{7A0585CD-992C-44E2-8DBA-5BC74CB25DB4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Implement", "WepApi07.Implement\WepApi07.Implement.csproj", "{D913F77B-76FE-40CC-A52A-5FACE33A565F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Intenface", "WepApi07.Intenface\WepApi07.Intenface.csproj", "{558257E2-8AE4-436A-85BF-D8AD7F74E5C6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Server", "WepApi07.Server\WepApi07.Server.csproj", "{D15084ED-2E92-441C-A17F-4B98D03D7BA9}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Util", "WebApi07.Util\WepApi07.Util.csproj", "{8E564F87-A362-492F-B11D-A28CEC69163A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Test", "WebApi07.Test\WepApi07.Test.csproj", "{89F5D49D-E3AC-4D9F-82DE-437DEC1F795E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {76208B82-4470-4568-9729-557FA3A3E09E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {76208B82-4470-4568-9729-557FA3A3E09E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {76208B82-4470-4568-9729-557FA3A3E09E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {76208B82-4470-4568-9729-557FA3A3E09E}.Release|Any CPU.Build.0 = Release|Any CPU + {8E2AA62E-7335-4A24-B3E3-416376F83219}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8E2AA62E-7335-4A24-B3E3-416376F83219}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8E2AA62E-7335-4A24-B3E3-416376F83219}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8E2AA62E-7335-4A24-B3E3-416376F83219}.Release|Any CPU.Build.0 = Release|Any CPU + {977081DB-1B43-4454-8353-CCFDC48C8A3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {977081DB-1B43-4454-8353-CCFDC48C8A3A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {977081DB-1B43-4454-8353-CCFDC48C8A3A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {977081DB-1B43-4454-8353-CCFDC48C8A3A}.Release|Any CPU.Build.0 = Release|Any CPU + {7A0585CD-992C-44E2-8DBA-5BC74CB25DB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7A0585CD-992C-44E2-8DBA-5BC74CB25DB4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7A0585CD-992C-44E2-8DBA-5BC74CB25DB4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7A0585CD-992C-44E2-8DBA-5BC74CB25DB4}.Release|Any CPU.Build.0 = Release|Any CPU + {D913F77B-76FE-40CC-A52A-5FACE33A565F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D913F77B-76FE-40CC-A52A-5FACE33A565F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D913F77B-76FE-40CC-A52A-5FACE33A565F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D913F77B-76FE-40CC-A52A-5FACE33A565F}.Release|Any CPU.Build.0 = Release|Any CPU + {558257E2-8AE4-436A-85BF-D8AD7F74E5C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {558257E2-8AE4-436A-85BF-D8AD7F74E5C6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {558257E2-8AE4-436A-85BF-D8AD7F74E5C6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {558257E2-8AE4-436A-85BF-D8AD7F74E5C6}.Release|Any CPU.Build.0 = Release|Any CPU + {D15084ED-2E92-441C-A17F-4B98D03D7BA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D15084ED-2E92-441C-A17F-4B98D03D7BA9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D15084ED-2E92-441C-A17F-4B98D03D7BA9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D15084ED-2E92-441C-A17F-4B98D03D7BA9}.Release|Any CPU.Build.0 = Release|Any CPU + {8E564F87-A362-492F-B11D-A28CEC69163A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8E564F87-A362-492F-B11D-A28CEC69163A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8E564F87-A362-492F-B11D-A28CEC69163A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8E564F87-A362-492F-B11D-A28CEC69163A}.Release|Any CPU.Build.0 = Release|Any CPU + {89F5D49D-E3AC-4D9F-82DE-437DEC1F795E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {89F5D49D-E3AC-4D9F-82DE-437DEC1F795E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {89F5D49D-E3AC-4D9F-82DE-437DEC1F795E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {89F5D49D-E3AC-4D9F-82DE-437DEC1F795E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B20BDEDE-CBB0-4C96-8EB9-4C68A8F39F02} + EndGlobalSection +EndGlobal diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07/Controllers/WeatherForecastController.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07/Controllers/WeatherForecastController.cs" new file mode 100644 index 0000000..752aa4d --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07/Controllers/WeatherForecastController.cs" @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using WepApi07.Data.Entity; + +namespace WebApi07.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() + { + Student student = new Student(); + + //var res = student.PrintStudent(); + + var stu1 = new Student(); + + var stu2 = new Student(); + + Animals animals = new Animals(); + animals.PrintStudent(); + + throw new Exception("错误:error desc"); + + + + //return (IEnumerable)NotFound("没有操作权限"); + + + 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(); + } + } + + public class Student + { + public string StudentName { get; set; } + public string PrintOk() + { + return this.StudentName; + } + } + + public class Animals + { + + } + + public static class StudentHelper + { + public static string PrintStudent(this Animals stu) + { + return "美国英短"; + } + } + +} diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07/Program.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07/Program.cs" new file mode 100644 index 0000000..d097157 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07/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 WebApi07 +{ + 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/\350\223\235\346\231\223\346\242\205/WebApi07/Properties/launchSettings.json" "b/\350\223\235\346\231\223\346\242\205/WebApi07/Properties/launchSettings.json" new file mode 100644 index 0000000..a3d649a --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07/Properties/launchSettings.json" @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:52440", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "WebApi07": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "applicationUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07/Startup.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07/Startup.cs" new file mode 100644 index 0000000..c7d21dc --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07/Startup.cs" @@ -0,0 +1,62 @@ +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; +using WepApi07.Data; +using WepApi07.Domain; +using WepApi07.Implement.Log; +using WepApi07.Intenface.Log; +using WepApi07.Util; +using WepApi07.Util.Filters; + +namespace WebApi07 +{ + 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(options =>options.Filters.Add()); + services.AddDbContext(); + + services.AddScoped(typeof(IResponsitory<>), typeof(EfResponsitory<>)); + services.AddControllers(); + + services.AddScoped(typeof(ILog), typeof(Log)); + } + + // 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(); + }); + + DbInitializazer.Seed(app.ApplicationServices); + } + } +} diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07/WeatherForecast.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07/WeatherForecast.cs" new file mode 100644 index 0000000..2fc6b95 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07/WeatherForecast.cs" @@ -0,0 +1,15 @@ +using System; + +namespace WebApi07 +{ + 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/\350\223\235\346\231\223\346\242\205/WebApi07/WebApi07.csproj" "b/\350\223\235\346\231\223\346\242\205/WebApi07/WebApi07.csproj" new file mode 100644 index 0000000..24cc6ef --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07/WebApi07.csproj" @@ -0,0 +1,13 @@ + + + + netcoreapp3.1 + + + + + + + + + diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.Development.json" "b/\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.Development.json" new file mode 100644 index 0000000..8983e0f --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.Development.json" @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.json" "b/\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.json" new file mode 100644 index 0000000..d9d9a9b --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.json" @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Api/WepApi07.Api.csproj" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Api/WepApi07.Api.csproj" new file mode 100644 index 0000000..9f5c4f4 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Api/WepApi07.Api.csproj" @@ -0,0 +1,7 @@ + + + + netstandard2.0 + + + diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Admin07Dbcontext.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Admin07Dbcontext.cs" new file mode 100644 index 0000000..db8e621 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Admin07Dbcontext.cs" @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Text; +using WepApi07.Data.Entity; + +namespace WepApi07.Data +{ + public class Admin07Dbcontext:DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + var str = "server=.;database=Admin07;uid=sa;pwd=A123456"; + optionsBuilder.UseSqlServer(str); + } + + public DbSet Users { get; set; } + public DbSet Roles { get; set; } + + public DbSet Logs { get; set; } + } +} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/BaseEntity.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/BaseEntity.cs" new file mode 100644 index 0000000..4570046 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/BaseEntity.cs" @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WepApi07.Data +{ + public abstract class BaseEntity + { + public BaseEntity() + { + IsActived = true; + IsDeleted = false; + CreatedTime = DateTime.Now; + UpdatedTime = DateTime.Now; + } + + 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; } + } +} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Logs.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Logs.cs" new file mode 100644 index 0000000..e311789 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Logs.cs" @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WepApi07.Data.Entity +{ + public class Logs:BaseEntity + { + public int LogLevel { get; set; } + + public string ShortMessage { get; set; } + public string FullMessage { get; set; } + public int UserId { get; set; } + public string ReferenceUrl { get; set; } + } +} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Roles.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Roles.cs" new file mode 100644 index 0000000..3f3753e --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Roles.cs" @@ -0,0 +1,12 @@ +using System.Collections; +using System.Collections.Generic; + +namespace WepApi07.Data.Entity +{ + public class Roles:BaseEntity + { + public string RoleName { get; set; } + + public IEnumerable User { get; set; } + } +} \ No newline at end of file diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Users.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Users.cs" new file mode 100644 index 0000000..afe62c7 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Users.cs" @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WepApi07.Data.Entity +{ + public class Users:BaseEntity + { + public string UserName { get; set; } + public string PassWord { get; set; } + + public Roles Roles { get; set; } + } +} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/WepApi07.Data.csproj" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/WepApi07.Data.csproj" new file mode 100644 index 0000000..bc7806e --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/WepApi07.Data.csproj" @@ -0,0 +1,12 @@ + + + + netstandard2.0 + + + + + + + + diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/EfResponsitory.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/EfResponsitory.cs" new file mode 100644 index 0000000..59fa32c --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/EfResponsitory.cs" @@ -0,0 +1,80 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using WepApi07.Data; + +namespace WepApi07.Domain +{ + public class EfResponsitory : IResponsitory where T : BaseEntity + { + private readonly Admin07Dbcontext db; + public EfResponsitory(Admin07Dbcontext admin) + { + db = admin; + } + + private DbSet _entity; + + private DbSet Entity + { + get + { + if (_entity == null) + { + _entity = db.Set(); + } + return _entity; + } + } + public IQueryable Table + { get + { + return _entity; + } + } + + public void Delete(int id) + { + var row = Table.Where(x => x.Id == id).FirstOrDefault(); + Delete(row); + } + + public void Delete(T entity) + { + Entity.Remove(entity); + db.SaveChanges(); + } + + public void Insert(T entity) + { + Entity.Add(entity); + db.SaveChanges(); + } + + public void InsertBulk(IEnumerable entity) + { + + Entity.AddRange(entity); + db.SaveChanges(); + } + + public void Update(T entity) + { + Entity.Update(entity); + db.SaveChanges(); + } + + public void Delete(IEnumerable entities) + { + Entity.RemoveRange(entities); + db.SaveChanges(); + } + + public T GetById(int id) + { + return Entity.Where(x => x.Id == id).FirstOrDefault(); + } + } +} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/Enum/LogLevel.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/Enum/LogLevel.cs" new file mode 100644 index 0000000..ae0a0f0 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/Enum/LogLevel.cs" @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WepApi07.Domain.Enum +{ + public enum LogsLevel + { + 警告=10, + 调试=20, + 信息=30, + 错误=40, + 崩溃=50 + } +} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/IResponsitory.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/IResponsitory.cs" new file mode 100644 index 0000000..144eed5 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/IResponsitory.cs" @@ -0,0 +1,26 @@ +using Microsoft.EntityFrameworkCore.ChangeTracking; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace WepApi07.Domain +{ + public interface IResponsitory + { + IQueryable Table { get; } + void Insert(T entity); + + void InsertBulk(IEnumerable entity); + + void Delete(int id); + + void Delete(T entity); + + void Delete(IEnumerable entities); + + void Update(T entity); + + T GetById(int id); + } +} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/WepApi07.Domain.csproj" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/WepApi07.Domain.csproj" new file mode 100644 index 0000000..c0740cf --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/WepApi07.Domain.csproj" @@ -0,0 +1,11 @@ + + + + netstandard2.0 + + + + + + + diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Implement/WepApi07.Implement.csproj" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Implement/WepApi07.Implement.csproj" new file mode 100644 index 0000000..7080721 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Implement/WepApi07.Implement.csproj" @@ -0,0 +1,11 @@ + + + + netstandard2.0 + + + + + + + diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Intenface/Log/ILog.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Intenface/Log/ILog.cs" new file mode 100644 index 0000000..5070f7d --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Intenface/Log/ILog.cs" @@ -0,0 +1,21 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Text; +using WepApi07.Data; +using WepApi07.Data.Entity; +using WepApi07.Domain.Enum; + +namespace WepApi07.Intenface.Log +{ + public interface ILog + { + Logs GetLogById(int id); + void Insert(Logs log); + + void Delete(Logs log); + IEnumerable MultiQuery(DateTime beginTime, DateTime endTime, LogsLevel logLevel, int userId = 0); + + void Clear(); + } +} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Intenface/WepApi07.Intenface.csproj" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Intenface/WepApi07.Intenface.csproj" new file mode 100644 index 0000000..70849b3 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Intenface/WepApi07.Intenface.csproj" @@ -0,0 +1,12 @@ + + + + netstandard2.0 + + + + + + + + diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Server/WepApi07.Server.csproj" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Server/WepApi07.Server.csproj" new file mode 100644 index 0000000..9f5c4f4 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Server/WepApi07.Server.csproj" @@ -0,0 +1,7 @@ + + + + netstandard2.0 + + + -- Gitee From 3a044fb915591d555bdcc9bf7868338efe9af8ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=93=9D=E6=99=93=E6=A2=85?= <7371318+lan_xiaomei@user.noreply.gitee.com> Date: Mon, 15 Jun 2020 19:51:16 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?=E8=93=9D=E6=99=93=E6=A2=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WebApi07.Server/Class1.cs" | 8 -- .../WebApi07.Server/WebApi07.Server.csproj" | 7 -- .../WebApi07.Test/UnitTest1.cs" | 18 ----- .../WebApi07.Test/WepApi07.Test.csproj" | 15 ---- .../WebApi07.Util/DbInitializazer.cs" | 55 ------------- .../Filters/GlobalExceptionFilter.cs" | 33 -------- .../WebApi07.Util/WepApi07.Util.csproj" | 18 ----- .../WebApi07.sln" | 73 ----------------- .../Controllers/WeatherForecastController.cs" | 81 ------------------- .../WebApi07/Program.cs" | 26 ------ .../WebApi07/Properties/launchSettings.json" | 30 ------- .../WebApi07/Startup.cs" | 62 -------------- .../WebApi07/WeatherForecast.cs" | 15 ---- .../WebApi07/WebApi07.csproj" | 13 --- .../WebApi07/appsettings.Development.json" | 9 --- .../WebApi07/appsettings.json" | 10 --- .../WepApi07.Api/WepApi07.Api.csproj" | 7 -- .../WepApi07.Date/Admin07Dbcontext.cs" | 22 ----- .../WepApi07.Date/BaseEntity.cs" | 23 ------ .../WepApi07.Date/Entity/Logs.cs" | 16 ---- .../WepApi07.Date/Entity/Roles.cs" | 12 --- .../WepApi07.Date/Entity/Users.cs" | 14 ---- .../WepApi07.Date/WepApi07.Data.csproj" | 12 --- .../WepApi07.Domain/EfResponsitory.cs" | 80 ------------------ .../WepApi07.Domain/Enum/LogLevel.cs" | 15 ---- .../WepApi07.Domain/IResponsitory.cs" | 26 ------ .../WepApi07.Domain/WepApi07.Domain.csproj" | 11 --- .../WepApi07.Implement.csproj" | 11 --- .../WepApi07.Intenface/Log/ILog.cs" | 21 ----- .../WepApi07.Intenface.csproj" | 12 --- .../WepApi07.Server/WepApi07.Server.csproj" | 7 -- 31 files changed, 762 deletions(-) delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.Server/Class1.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.Server/WebApi07.Server.csproj" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.Test/UnitTest1.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.Test/WepApi07.Test.csproj" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.Util/DbInitializazer.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.Util/Filters/GlobalExceptionFilter.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.Util/WepApi07.Util.csproj" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.sln" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/Controllers/WeatherForecastController.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/Program.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/Properties/launchSettings.json" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/Startup.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/WeatherForecast.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/WebApi07.csproj" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.Development.json" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.json" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Api/WepApi07.Api.csproj" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Date/Admin07Dbcontext.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Date/BaseEntity.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Logs.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Roles.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Users.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Date/WepApi07.Data.csproj" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Domain/EfResponsitory.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Domain/Enum/LogLevel.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Domain/IResponsitory.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Domain/WepApi07.Domain.csproj" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Implement/WepApi07.Implement.csproj" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Intenface/Log/ILog.cs" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Intenface/WepApi07.Intenface.csproj" delete mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Server/WepApi07.Server.csproj" diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.Server/Class1.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07.Server/Class1.cs" deleted file mode 100644 index ecffa7b..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07.Server/Class1.cs" +++ /dev/null @@ -1,8 +0,0 @@ -using System; - -namespace WebApi07.Server -{ - public class Class1 - { - } -} diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.Server/WebApi07.Server.csproj" "b/\350\223\235\346\231\223\346\242\205/WebApi07.Server/WebApi07.Server.csproj" deleted file mode 100644 index 9f5c4f4..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07.Server/WebApi07.Server.csproj" +++ /dev/null @@ -1,7 +0,0 @@ - - - - netstandard2.0 - - - diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.Test/UnitTest1.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07.Test/UnitTest1.cs" deleted file mode 100644 index 1f50f33..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07.Test/UnitTest1.cs" +++ /dev/null @@ -1,18 +0,0 @@ -using NUnit.Framework; - -namespace WebApi07.Test -{ - public class Tests - { - [SetUp] - public void Setup() - { - } - - [Test] - public void Test1() - { - Assert.Pass(); - } - } -} \ No newline at end of file diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.Test/WepApi07.Test.csproj" "b/\350\223\235\346\231\223\346\242\205/WebApi07.Test/WepApi07.Test.csproj" deleted file mode 100644 index e532582..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07.Test/WepApi07.Test.csproj" +++ /dev/null @@ -1,15 +0,0 @@ - - - - netcoreapp3.1 - - false - - - - - - - - - diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.Util/DbInitializazer.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07.Util/DbInitializazer.cs" deleted file mode 100644 index f70b768..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07.Util/DbInitializazer.cs" +++ /dev/null @@ -1,55 +0,0 @@ -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Internal; -using Microsoft.Extensions.DependencyInjection; -using System; -using System.Collections.Generic; -using System.Text; -using WepApi07.Data; -using WepApi07.Data.Entity; -using WepApi07.Domain; -using System.Linq; - -namespace WepApi07.Util -{ - public class DbInitializazer - { - public static void Seed(IServiceProvider serviceProvider) - { - - using(var scope = serviceProvider.CreateScope()) - { - var db = scope.ServiceProvider.GetService(typeof(Admin07Dbcontext)) as Admin07Dbcontext; - - var _user = scope.ServiceProvider.GetService(typeof(IResponsitory)) as EfResponsitory; - - var _role = scope.ServiceProvider.GetService(typeof(IResponsitory)) as EfResponsitory; - - db.Database.EnsureCreated(); - - var hasUser = db.Users.Any(); - - if (!hasUser) - { - var role = new Roles() - { - RoleName = "名字" - }; - - _role.Insert(role); - - var user = new Users() - { - UserName = "张三", - PassWord = "123456", - Roles = role - }; - - _user.Insert(user); - - } - } - } - - - } -} diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.Util/Filters/GlobalExceptionFilter.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07.Util/Filters/GlobalExceptionFilter.cs" deleted file mode 100644 index 7af97f2..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07.Util/Filters/GlobalExceptionFilter.cs" +++ /dev/null @@ -1,33 +0,0 @@ -using Microsoft.AspNetCore.Mvc.Filters; -using System; -using System.Collections.Generic; -using System.Text; -using WepApi07.Data.Entity; -using WepApi07.Domain; -using WepApi07.Intenface.Log; -using WepApi07.Util.Log; - -namespace WepApi07.Util.Filters -{ - - public class GlobalExceptionFilter:IExceptionFilter - { - private readonly IResponsitory _log; - - public GlobalExceptionFilter(IResponsitory log) - { - _log = log; - } - public void OnException(ExceptionContext context) - { - _log.Fatal(context.Exception); - - _log.Insert(new Logs - { - - }); - - context.ExceptionHandled = true; - } - } -} diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.Util/WepApi07.Util.csproj" "b/\350\223\235\346\231\223\346\242\205/WebApi07.Util/WepApi07.Util.csproj" deleted file mode 100644 index 1e89112..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07.Util/WepApi07.Util.csproj" +++ /dev/null @@ -1,18 +0,0 @@ - - - - netstandard2.0 - - - - - - - - - - - - - - diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.sln" "b/\350\223\235\346\231\223\346\242\205/WebApi07.sln" deleted file mode 100644 index 266e1a4..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07.sln" +++ /dev/null @@ -1,73 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30128.74 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApi07", "WebApi07\WebApi07.csproj", "{76208B82-4470-4568-9729-557FA3A3E09E}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Api", "WepApi07.Api\WepApi07.Api.csproj", "{8E2AA62E-7335-4A24-B3E3-416376F83219}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Data", "WepApi07.Date\WepApi07.Data.csproj", "{977081DB-1B43-4454-8353-CCFDC48C8A3A}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Domain", "WepApi07.Domain\WepApi07.Domain.csproj", "{7A0585CD-992C-44E2-8DBA-5BC74CB25DB4}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Implement", "WepApi07.Implement\WepApi07.Implement.csproj", "{D913F77B-76FE-40CC-A52A-5FACE33A565F}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Intenface", "WepApi07.Intenface\WepApi07.Intenface.csproj", "{558257E2-8AE4-436A-85BF-D8AD7F74E5C6}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Server", "WepApi07.Server\WepApi07.Server.csproj", "{D15084ED-2E92-441C-A17F-4B98D03D7BA9}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Util", "WebApi07.Util\WepApi07.Util.csproj", "{8E564F87-A362-492F-B11D-A28CEC69163A}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WepApi07.Test", "WebApi07.Test\WepApi07.Test.csproj", "{89F5D49D-E3AC-4D9F-82DE-437DEC1F795E}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {76208B82-4470-4568-9729-557FA3A3E09E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {76208B82-4470-4568-9729-557FA3A3E09E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {76208B82-4470-4568-9729-557FA3A3E09E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {76208B82-4470-4568-9729-557FA3A3E09E}.Release|Any CPU.Build.0 = Release|Any CPU - {8E2AA62E-7335-4A24-B3E3-416376F83219}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8E2AA62E-7335-4A24-B3E3-416376F83219}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8E2AA62E-7335-4A24-B3E3-416376F83219}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8E2AA62E-7335-4A24-B3E3-416376F83219}.Release|Any CPU.Build.0 = Release|Any CPU - {977081DB-1B43-4454-8353-CCFDC48C8A3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {977081DB-1B43-4454-8353-CCFDC48C8A3A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {977081DB-1B43-4454-8353-CCFDC48C8A3A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {977081DB-1B43-4454-8353-CCFDC48C8A3A}.Release|Any CPU.Build.0 = Release|Any CPU - {7A0585CD-992C-44E2-8DBA-5BC74CB25DB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7A0585CD-992C-44E2-8DBA-5BC74CB25DB4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7A0585CD-992C-44E2-8DBA-5BC74CB25DB4}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7A0585CD-992C-44E2-8DBA-5BC74CB25DB4}.Release|Any CPU.Build.0 = Release|Any CPU - {D913F77B-76FE-40CC-A52A-5FACE33A565F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D913F77B-76FE-40CC-A52A-5FACE33A565F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D913F77B-76FE-40CC-A52A-5FACE33A565F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D913F77B-76FE-40CC-A52A-5FACE33A565F}.Release|Any CPU.Build.0 = Release|Any CPU - {558257E2-8AE4-436A-85BF-D8AD7F74E5C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {558257E2-8AE4-436A-85BF-D8AD7F74E5C6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {558257E2-8AE4-436A-85BF-D8AD7F74E5C6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {558257E2-8AE4-436A-85BF-D8AD7F74E5C6}.Release|Any CPU.Build.0 = Release|Any CPU - {D15084ED-2E92-441C-A17F-4B98D03D7BA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D15084ED-2E92-441C-A17F-4B98D03D7BA9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D15084ED-2E92-441C-A17F-4B98D03D7BA9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D15084ED-2E92-441C-A17F-4B98D03D7BA9}.Release|Any CPU.Build.0 = Release|Any CPU - {8E564F87-A362-492F-B11D-A28CEC69163A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8E564F87-A362-492F-B11D-A28CEC69163A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8E564F87-A362-492F-B11D-A28CEC69163A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8E564F87-A362-492F-B11D-A28CEC69163A}.Release|Any CPU.Build.0 = Release|Any CPU - {89F5D49D-E3AC-4D9F-82DE-437DEC1F795E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {89F5D49D-E3AC-4D9F-82DE-437DEC1F795E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {89F5D49D-E3AC-4D9F-82DE-437DEC1F795E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {89F5D49D-E3AC-4D9F-82DE-437DEC1F795E}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {B20BDEDE-CBB0-4C96-8EB9-4C68A8F39F02} - EndGlobalSection -EndGlobal diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07/Controllers/WeatherForecastController.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07/Controllers/WeatherForecastController.cs" deleted file mode 100644 index 752aa4d..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07/Controllers/WeatherForecastController.cs" +++ /dev/null @@ -1,81 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; -using WepApi07.Data.Entity; - -namespace WebApi07.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() - { - Student student = new Student(); - - //var res = student.PrintStudent(); - - var stu1 = new Student(); - - var stu2 = new Student(); - - Animals animals = new Animals(); - animals.PrintStudent(); - - throw new Exception("错误:error desc"); - - - - //return (IEnumerable)NotFound("没有操作权限"); - - - 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(); - } - } - - public class Student - { - public string StudentName { get; set; } - public string PrintOk() - { - return this.StudentName; - } - } - - public class Animals - { - - } - - public static class StudentHelper - { - public static string PrintStudent(this Animals stu) - { - return "美国英短"; - } - } - -} diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07/Program.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07/Program.cs" deleted file mode 100644 index d097157..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07/Program.cs" +++ /dev/null @@ -1,26 +0,0 @@ -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 WebApi07 -{ - 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/\350\223\235\346\231\223\346\242\205/WebApi07/Properties/launchSettings.json" "b/\350\223\235\346\231\223\346\242\205/WebApi07/Properties/launchSettings.json" deleted file mode 100644 index a3d649a..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07/Properties/launchSettings.json" +++ /dev/null @@ -1,30 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/launchsettings.json", - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:52440", - "sslPort": 0 - } - }, - "profiles": { - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "launchUrl": "weatherforecast", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "WebApi07": { - "commandName": "Project", - "launchBrowser": true, - "launchUrl": "weatherforecast", - "applicationUrl": "http://localhost:5000", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - } - } -} diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07/Startup.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07/Startup.cs" deleted file mode 100644 index c7d21dc..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07/Startup.cs" +++ /dev/null @@ -1,62 +0,0 @@ -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; -using WepApi07.Data; -using WepApi07.Domain; -using WepApi07.Implement.Log; -using WepApi07.Intenface.Log; -using WepApi07.Util; -using WepApi07.Util.Filters; - -namespace WebApi07 -{ - 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(options =>options.Filters.Add()); - services.AddDbContext(); - - services.AddScoped(typeof(IResponsitory<>), typeof(EfResponsitory<>)); - services.AddControllers(); - - services.AddScoped(typeof(ILog), typeof(Log)); - } - - // 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(); - }); - - DbInitializazer.Seed(app.ApplicationServices); - } - } -} diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07/WeatherForecast.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07/WeatherForecast.cs" deleted file mode 100644 index 2fc6b95..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07/WeatherForecast.cs" +++ /dev/null @@ -1,15 +0,0 @@ -using System; - -namespace WebApi07 -{ - 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/\350\223\235\346\231\223\346\242\205/WebApi07/WebApi07.csproj" "b/\350\223\235\346\231\223\346\242\205/WebApi07/WebApi07.csproj" deleted file mode 100644 index 24cc6ef..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07/WebApi07.csproj" +++ /dev/null @@ -1,13 +0,0 @@ - - - - netcoreapp3.1 - - - - - - - - - diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.Development.json" "b/\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.Development.json" deleted file mode 100644 index 8983e0f..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.Development.json" +++ /dev/null @@ -1,9 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" - } - } -} diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.json" "b/\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.json" deleted file mode 100644 index d9d9a9b..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WebApi07/appsettings.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" - } - }, - "AllowedHosts": "*" -} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Api/WepApi07.Api.csproj" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Api/WepApi07.Api.csproj" deleted file mode 100644 index 9f5c4f4..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WepApi07.Api/WepApi07.Api.csproj" +++ /dev/null @@ -1,7 +0,0 @@ - - - - netstandard2.0 - - - diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Admin07Dbcontext.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Admin07Dbcontext.cs" deleted file mode 100644 index db8e621..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Admin07Dbcontext.cs" +++ /dev/null @@ -1,22 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Text; -using WepApi07.Data.Entity; - -namespace WepApi07.Data -{ - public class Admin07Dbcontext:DbContext - { - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - var str = "server=.;database=Admin07;uid=sa;pwd=A123456"; - optionsBuilder.UseSqlServer(str); - } - - public DbSet Users { get; set; } - public DbSet Roles { get; set; } - - public DbSet Logs { get; set; } - } -} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/BaseEntity.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/BaseEntity.cs" deleted file mode 100644 index 4570046..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/BaseEntity.cs" +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace WepApi07.Data -{ - public abstract class BaseEntity - { - public BaseEntity() - { - IsActived = true; - IsDeleted = false; - CreatedTime = DateTime.Now; - UpdatedTime = DateTime.Now; - } - - 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; } - } -} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Logs.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Logs.cs" deleted file mode 100644 index e311789..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Logs.cs" +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace WepApi07.Data.Entity -{ - public class Logs:BaseEntity - { - public int LogLevel { get; set; } - - public string ShortMessage { get; set; } - public string FullMessage { get; set; } - public int UserId { get; set; } - public string ReferenceUrl { get; set; } - } -} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Roles.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Roles.cs" deleted file mode 100644 index 3f3753e..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Roles.cs" +++ /dev/null @@ -1,12 +0,0 @@ -using System.Collections; -using System.Collections.Generic; - -namespace WepApi07.Data.Entity -{ - public class Roles:BaseEntity - { - public string RoleName { get; set; } - - public IEnumerable User { get; set; } - } -} \ No newline at end of file diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Users.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Users.cs" deleted file mode 100644 index afe62c7..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/Entity/Users.cs" +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace WepApi07.Data.Entity -{ - public class Users:BaseEntity - { - public string UserName { get; set; } - public string PassWord { get; set; } - - public Roles Roles { get; set; } - } -} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/WepApi07.Data.csproj" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Date/WepApi07.Data.csproj" deleted file mode 100644 index bc7806e..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WepApi07.Date/WepApi07.Data.csproj" +++ /dev/null @@ -1,12 +0,0 @@ - - - - netstandard2.0 - - - - - - - - diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/EfResponsitory.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/EfResponsitory.cs" deleted file mode 100644 index 59fa32c..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/EfResponsitory.cs" +++ /dev/null @@ -1,80 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using WepApi07.Data; - -namespace WepApi07.Domain -{ - public class EfResponsitory : IResponsitory where T : BaseEntity - { - private readonly Admin07Dbcontext db; - public EfResponsitory(Admin07Dbcontext admin) - { - db = admin; - } - - private DbSet _entity; - - private DbSet Entity - { - get - { - if (_entity == null) - { - _entity = db.Set(); - } - return _entity; - } - } - public IQueryable Table - { get - { - return _entity; - } - } - - public void Delete(int id) - { - var row = Table.Where(x => x.Id == id).FirstOrDefault(); - Delete(row); - } - - public void Delete(T entity) - { - Entity.Remove(entity); - db.SaveChanges(); - } - - public void Insert(T entity) - { - Entity.Add(entity); - db.SaveChanges(); - } - - public void InsertBulk(IEnumerable entity) - { - - Entity.AddRange(entity); - db.SaveChanges(); - } - - public void Update(T entity) - { - Entity.Update(entity); - db.SaveChanges(); - } - - public void Delete(IEnumerable entities) - { - Entity.RemoveRange(entities); - db.SaveChanges(); - } - - public T GetById(int id) - { - return Entity.Where(x => x.Id == id).FirstOrDefault(); - } - } -} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/Enum/LogLevel.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/Enum/LogLevel.cs" deleted file mode 100644 index ae0a0f0..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/Enum/LogLevel.cs" +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace WepApi07.Domain.Enum -{ - public enum LogsLevel - { - 警告=10, - 调试=20, - 信息=30, - 错误=40, - 崩溃=50 - } -} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/IResponsitory.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/IResponsitory.cs" deleted file mode 100644 index 144eed5..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/IResponsitory.cs" +++ /dev/null @@ -1,26 +0,0 @@ -using Microsoft.EntityFrameworkCore.ChangeTracking; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace WepApi07.Domain -{ - public interface IResponsitory - { - IQueryable Table { get; } - void Insert(T entity); - - void InsertBulk(IEnumerable entity); - - void Delete(int id); - - void Delete(T entity); - - void Delete(IEnumerable entities); - - void Update(T entity); - - T GetById(int id); - } -} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/WepApi07.Domain.csproj" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/WepApi07.Domain.csproj" deleted file mode 100644 index c0740cf..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WepApi07.Domain/WepApi07.Domain.csproj" +++ /dev/null @@ -1,11 +0,0 @@ - - - - netstandard2.0 - - - - - - - diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Implement/WepApi07.Implement.csproj" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Implement/WepApi07.Implement.csproj" deleted file mode 100644 index 7080721..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WepApi07.Implement/WepApi07.Implement.csproj" +++ /dev/null @@ -1,11 +0,0 @@ - - - - netstandard2.0 - - - - - - - diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Intenface/Log/ILog.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Intenface/Log/ILog.cs" deleted file mode 100644 index 5070f7d..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WepApi07.Intenface/Log/ILog.cs" +++ /dev/null @@ -1,21 +0,0 @@ -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Text; -using WepApi07.Data; -using WepApi07.Data.Entity; -using WepApi07.Domain.Enum; - -namespace WepApi07.Intenface.Log -{ - public interface ILog - { - Logs GetLogById(int id); - void Insert(Logs log); - - void Delete(Logs log); - IEnumerable MultiQuery(DateTime beginTime, DateTime endTime, LogsLevel logLevel, int userId = 0); - - void Clear(); - } -} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Intenface/WepApi07.Intenface.csproj" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Intenface/WepApi07.Intenface.csproj" deleted file mode 100644 index 70849b3..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WepApi07.Intenface/WepApi07.Intenface.csproj" +++ /dev/null @@ -1,12 +0,0 @@ - - - - netstandard2.0 - - - - - - - - diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Server/WepApi07.Server.csproj" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Server/WepApi07.Server.csproj" deleted file mode 100644 index 9f5c4f4..0000000 --- "a/\350\223\235\346\231\223\346\242\205/WepApi07.Server/WepApi07.Server.csproj" +++ /dev/null @@ -1,7 +0,0 @@ - - - - netstandard2.0 - - - -- Gitee From 90b4763e4b20753210433475cd0a047b173fd596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=93=9D=E6=99=93=E6=A2=85?= <2622290440@qq.com> Date: Mon, 15 Jun 2020 20:15:23 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E5=B7=B2=E7=BB=8F=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=A5=BD=E7=9A=84log=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WebApi07.Util/Log/LogHelper.cs" | 47 ++++++++++++++ .../WepApi07.Implement/Log/Log.cs" | 61 +++++++++++++++++++ .../WepApi07.Intenface/Log/ILog.cs" | 21 +++++++ 3 files changed, 129 insertions(+) create mode 100644 "\350\223\235\346\231\223\346\242\205/WebApi07.Util/Log/LogHelper.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Implement/Log/Log.cs" create mode 100644 "\350\223\235\346\231\223\346\242\205/WepApi07.Intenface/Log/ILog.cs" diff --git "a/\350\223\235\346\231\223\346\242\205/WebApi07.Util/Log/LogHelper.cs" "b/\350\223\235\346\231\223\346\242\205/WebApi07.Util/Log/LogHelper.cs" new file mode 100644 index 0000000..5527914 --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WebApi07.Util/Log/LogHelper.cs" @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Text; +using WepApi07.Data.Entity; +using WepApi07.Domain; +using WepApi07.Domain.Enum; +using WepApi07.Intenface.Log; + +namespace WepApi07.Util.Log +{ + public static class LogHelper + { + public static void Logger(this IResponsitory log, Exception exception, LogsLevel logsLevel, int userId = 0) + { + var item = new Logs + { + LogLevel = (int)logsLevel, + ShortMessage = exception.Message, + FullMessage = exception.ToString(), + UserId=userId + }; + log.Insert(item); + } + public static void Info(this IResponsitory log, Exception exception, LogsLevel logsLevel = LogsLevel.信息, int userId = 0) + { + Logger(log,exception, logsLevel, userId); + + + } + + public static void Debug(this IResponsitory log, Exception exception, LogsLevel logsLevel = LogsLevel.调试, int userId = 0) + { + Logger(log, exception, logsLevel, userId); + } + + public static void Error(this IResponsitory log, Exception exception, LogsLevel logsLevel = LogsLevel.错误, int userId = 0) + { + Logger(log, exception, logsLevel, userId); + } + + public static void Fatal(this IResponsitory log, Exception exception, LogsLevel logsLevel = LogsLevel.崩溃, int userId = 0) + { + Logger(log, exception, logsLevel, userId); + } + } +} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Implement/Log/Log.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Implement/Log/Log.cs" new file mode 100644 index 0000000..2a9872c --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Implement/Log/Log.cs" @@ -0,0 +1,61 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using WepApi07.Data.Entity; +using WepApi07.Domain; +using WepApi07.Domain.Enum; +using WepApi07.Intenface.Log; + + +namespace WepApi07.Implement.Log +{ + public class Log : ILog + { + private readonly IResponsitory _logsResponsitory; + + + + public Log(IResponsitory logsResponsitory) + { + _logsResponsitory = logsResponsitory; + } + + public void Clear() + { + var list = _logsResponsitory.Table.ToList(); + _logsResponsitory.Delete(list); + } + + public void Delete(Logs log) + { + _logsResponsitory.Delete(log); + } + + public Logs GetLogById(int id) + { + return _logsResponsitory.GetById(id); + } + + public void Insert(Logs log) + { + _logsResponsitory.Insert(log); + } + + public IEnumerable MultiQuery(DateTime beginTime, DateTime endTime, LogsLevel logLevel=LogsLevel.错误, int userId = 0) + { + var bTime = beginTime == null ? DateTime.Now : beginTime; + var eTime = endTime == null ? DateTime.Now : endTime; + + var list = _logsResponsitory.Table.Where(x => x.CreatedTime >= bTime && x.CreatedTime <= eTime && x.LogLevel==(int)logLevel); + + if (userId != 0) + { + list = list.Where(x => x.UserId == userId); + } + + return list; + } + } +} diff --git "a/\350\223\235\346\231\223\346\242\205/WepApi07.Intenface/Log/ILog.cs" "b/\350\223\235\346\231\223\346\242\205/WepApi07.Intenface/Log/ILog.cs" new file mode 100644 index 0000000..5070f7d --- /dev/null +++ "b/\350\223\235\346\231\223\346\242\205/WepApi07.Intenface/Log/ILog.cs" @@ -0,0 +1,21 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Text; +using WepApi07.Data; +using WepApi07.Data.Entity; +using WepApi07.Domain.Enum; + +namespace WepApi07.Intenface.Log +{ + public interface ILog + { + Logs GetLogById(int id); + void Insert(Logs log); + + void Delete(Logs log); + IEnumerable MultiQuery(DateTime beginTime, DateTime endTime, LogsLevel logLevel, int userId = 0); + + void Clear(); + } +} -- Gitee