diff --git "a/\347\253\240\345\273\272\345\206\233/WebApplication1/Demain/AdminDb.cs" "b/\347\253\240\345\273\272\345\206\233/WebApiV.Data/Admin10086Db.cs" similarity index 48% rename from "\347\253\240\345\273\272\345\206\233/WebApplication1/Demain/AdminDb.cs" rename to "\347\253\240\345\273\272\345\206\233/WebApiV.Data/Admin10086Db.cs" index 877b5d664564e56aa181bd027092779c964f4911..515777a98cc893aa8579c783a7d591e9b854304c 100644 --- "a/\347\253\240\345\273\272\345\206\233/WebApplication1/Demain/AdminDb.cs" +++ "b/\347\253\240\345\273\272\345\206\233/WebApiV.Data/Admin10086Db.cs" @@ -1,20 +1,21 @@ using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using WebApplication1.Controllers.Demain; +using System.Text; +using WebApiV.Data.Entity; -namespace WebApplication1.Controllers +namespace WebApiV.Data { - public class AdminDb:DbContext + public class Admin10086Db:DbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlServer("server=.;database=AdminDb0001;uid=sa;pwd=123;"); + optionsBuilder.UseSqlServer("server=.;database=Admin10086Db;uid=sa;pwd=123"); } - public DbSet Clbums { get; set; } - public DbSet Students { get; set; } + + public DbSet Roles { get; set; } + public DbSet Users { get; set; } + public DbSet Logs { get; set; } } } diff --git "a/\347\253\240\345\273\272\345\206\233/WebApplication1/Demain/BaseEntity.cs" "b/\347\253\240\345\273\272\345\206\233/WebApiV.Data/BaseEntity.cs" similarity index 63% rename from "\347\253\240\345\273\272\345\206\233/WebApplication1/Demain/BaseEntity.cs" rename to "\347\253\240\345\273\272\345\206\233/WebApiV.Data/BaseEntity.cs" index f81987438a989e6e42ee2ca2dab628b2267dd4f7..e1f49479919379f730ca5e6c6c2cd5df5d8bc52b 100644 --- "a/\347\253\240\345\273\272\345\206\233/WebApplication1/Demain/BaseEntity.cs" +++ "b/\347\253\240\345\273\272\345\206\233/WebApiV.Data/BaseEntity.cs" @@ -1,25 +1,24 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using System.Text; -namespace WebApplication1.Controllers.Demain +namespace WebApiV.Data { - public abstract class BaseEntity + public class BaseEntity { public BaseEntity() { IsActived = true; IsDeleted = false; - Createtime = DateTime.Now; + CreateTime = DateTime.Now; UpdateTime = DateTime.Now; - Remarks = "hello"; + Remarks = "what"; } public int Id { get; set; } public bool IsActived { get; set; } public bool IsDeleted { get; set; } - public DateTime Createtime { get; set; } + public DateTime CreateTime { get; set; } public DateTime UpdateTime { get; set; } public string Remarks { get; set; } } diff --git "a/\347\253\240\345\273\272\345\206\233/WebApiV.Data/Entity/Logs.cs" "b/\347\253\240\345\273\272\345\206\233/WebApiV.Data/Entity/Logs.cs" new file mode 100644 index 0000000000000000000000000000000000000000..1c8a921f11bdc0b1c77abe05108f9563840e6f6f --- /dev/null +++ "b/\347\253\240\345\273\272\345\206\233/WebApiV.Data/Entity/Logs.cs" @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WebApiV.Data.Entity +{ + public class Logs:BaseEntity + { + public int LogsLevel { 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/\347\253\240\345\273\272\345\206\233/WebApiV.Data/Entity/Role.cs" "b/\347\253\240\345\273\272\345\206\233/WebApiV.Data/Entity/Role.cs" new file mode 100644 index 0000000000000000000000000000000000000000..e2dee3a6b977fe45b8cab9b69e5b22242dee07e3 --- /dev/null +++ "b/\347\253\240\345\273\272\345\206\233/WebApiV.Data/Entity/Role.cs" @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WebApiV.Data.Entity +{ + public class Role:BaseEntity + { + public string RoleName { get; set; } + public string ShortTell { get; set; } + public IEnumerable Users { get; set; } + } +} diff --git "a/\347\253\240\345\273\272\345\206\233/WebApiV.Data/Entity/User.cs" "b/\347\253\240\345\273\272\345\206\233/WebApiV.Data/Entity/User.cs" new file mode 100644 index 0000000000000000000000000000000000000000..9d932b67ca9c034d881728bed39aee876839c176 --- /dev/null +++ "b/\347\253\240\345\273\272\345\206\233/WebApiV.Data/Entity/User.cs" @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WebApiV.Data.Entity +{ + public class User:BaseEntity + { + public string UserName { get; set; } + public string PassWord { get; set; } + public int RoleId { get; set; } + public Role Role { get; set; } + } +} diff --git "a/\347\253\240\345\273\272\345\206\233/WebApiV.Data/WebApiV.Data.csproj" "b/\347\253\240\345\273\272\345\206\233/WebApiV.Data/WebApiV.Data.csproj" new file mode 100644 index 0000000000000000000000000000000000000000..45bf2afe85420b18068bc496fcd0083de405c5e9 --- /dev/null +++ "b/\347\253\240\345\273\272\345\206\233/WebApiV.Data/WebApiV.Data.csproj" @@ -0,0 +1,12 @@ + + + + netstandard2.0 + + + + + + + + diff --git "a/\347\253\240\345\273\272\345\206\233/WebApplication1/Implementation/EfRespositoryy.cs" "b/\347\253\240\345\273\272\345\206\233/WebApiV.Domain/EfRespository.cs" similarity index 49% rename from "\347\253\240\345\273\272\345\206\233/WebApplication1/Implementation/EfRespositoryy.cs" rename to "\347\253\240\345\273\272\345\206\233/WebApiV.Domain/EfRespository.cs" index ff5c3c76bede3c50a1d2e6757852471ead04b1a8..646ebee18366608f8b593eee1f44207b905b1fb1 100644 --- "a/\347\253\240\345\273\272\345\206\233/WebApplication1/Implementation/EfRespositoryy.cs" +++ "b/\347\253\240\345\273\272\345\206\233/WebApiV.Domain/EfRespository.cs" @@ -2,29 +2,26 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; -using WebApplication1.Controllers; -using WebApplication1.Controllers.Demain; -using WebApplication1.Demain.Hellper.Interface; +using System.Text; +using WebApiV.Data; -namespace WebApplication1.Demain.Hellper.Implementation +namespace WebApiV.Domain { - public class EfRespositoryy : IRespository where T : BaseEntity + public class EfRespository : IRespository where T : BaseEntity { - private readonly AdminDb db; + private readonly Admin10086Db db; - private DbSet _entity; + private DbSet entity; - protected DbSet Entity + public DbSet Entity { get { - if (_entity == null) + if (entity == null) { - _entity = db.Set(); + entity = db.Set(); } - return _entity; - + return entity; } } @@ -32,49 +29,53 @@ namespace WebApplication1.Demain.Hellper.Implementation { get { - return Entity; + return entity; } } - public EfRespositoryy(AdminDb admin) + public EfRespository(Admin10086Db admin) { db = admin; } - public void Delete(T entity) - { - _entity.Remove(entity); - - db.SaveChanges(); - } public void Delete(int id) { var del = Table.Where(x => x.Id == id).FirstOrDefault(); - Delete(del); } - public T GetById(int id) + public void Delete(T entity) { - return _entity.Where(x => x.Id == id).FirstOrDefault(); + Entity.Remove(entity); + db.SaveChanges(); } - public void insert(T entity) + public void Insert(T entity) { - _entity.Add(entity); + Entity.Add(entity); db.SaveChanges(); } - public void InsertBulk(IEnumerable list) + public void InsertBlck(IEnumerable list) { - _entity.AddRange(list); + Entity.AddRange(list); db.SaveChanges(); } + public T GetById(int id) + { + return entity.Where(x => x.Id == id).FirstOrDefault(); + } public void Update(T entity) { - _entity.Update(entity); + Entity.Update(entity); + db.SaveChanges(); + } + + public void Delete(IEnumerable entities) + { + Entity.RemoveRange(entities); db.SaveChanges(); } } diff --git "a/\347\253\240\345\273\272\345\206\233/WebApiV.Domain/Enum/LogsLevel.cs" "b/\347\253\240\345\273\272\345\206\233/WebApiV.Domain/Enum/LogsLevel.cs" new file mode 100644 index 0000000000000000000000000000000000000000..e92b4c6b9f029754ce0b05d378da09a9b656ebe1 --- /dev/null +++ "b/\347\253\240\345\273\272\345\206\233/WebApiV.Domain/Enum/LogsLevel.cs" @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WebApiV.Domain.Enum +{ + public enum LogsLevel + { + 信息=10, + 调试=20, + 警告=30, + 错误=40, + 崩溃=50, + } +} diff --git "a/\347\253\240\345\273\272\345\206\233/WebApplication1/Interface/IRespository.cs" "b/\347\253\240\345\273\272\345\206\233/WebApiV.Domain/IRespository.cs" similarity index 48% rename from "\347\253\240\345\273\272\345\206\233/WebApplication1/Interface/IRespository.cs" rename to "\347\253\240\345\273\272\345\206\233/WebApiV.Domain/IRespository.cs" index 91478a7deeaa359b6fe21e4cb0422faa145ea91f..9592776c98560971d55c0875f725efbceb764f84 100644 --- "a/\347\253\240\345\273\272\345\206\233/WebApplication1/Interface/IRespository.cs" +++ "b/\347\253\240\345\273\272\345\206\233/WebApiV.Domain/IRespository.cs" @@ -1,26 +1,21 @@ -using Microsoft.EntityFrameworkCore; -using System; +using System; using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; +using System.Text; -namespace WebApplication1.Demain.Hellper.Interface +namespace WebApiV.Domain { public interface IRespository { IQueryable Table { get; } - T GetById(int id); - - - void insert(T entity); - - void InsertBulk(IEnumerable list); - - void Update(T entity); - + void Insert(T entity); + void InsertBlck(IEnumerable list); + void Delete(int id); void Delete(T entity); + void Delete(IEnumerable entities); + void Update(T entity); - void Delete(int Id); + T GetById(int id); } } diff --git "a/\347\253\240\345\273\272\345\206\233/WebApiV.Domain/WebApiV.Domain.csproj" "b/\347\253\240\345\273\272\345\206\233/WebApiV.Domain/WebApiV.Domain.csproj" new file mode 100644 index 0000000000000000000000000000000000000000..09b3c14bc34f8484694f10bb321a02dd9f7c5bcf --- /dev/null +++ "b/\347\253\240\345\273\272\345\206\233/WebApiV.Domain/WebApiV.Domain.csproj" @@ -0,0 +1,11 @@ + + + + netstandard2.0 + + + + + + + diff --git "a/\347\253\240\345\273\272\345\206\233/WebApiV.Implement/WebApiV.Implement.csproj" "b/\347\253\240\345\273\272\345\206\233/WebApiV.Implement/WebApiV.Implement.csproj" new file mode 100644 index 0000000000000000000000000000000000000000..27484ae61da3b4c1ef575094c5636b32afcfddc7 --- /dev/null +++ "b/\347\253\240\345\273\272\345\206\233/WebApiV.Implement/WebApiV.Implement.csproj" @@ -0,0 +1,11 @@ + + + + netstandard2.0 + + + + + + + diff --git "a/\347\253\240\345\273\272\345\206\233/WebApiV.Interface/WebApiV.Interface.csproj" "b/\347\253\240\345\273\272\345\206\233/WebApiV.Interface/WebApiV.Interface.csproj" new file mode 100644 index 0000000000000000000000000000000000000000..3f1bb7460d16a78aa75993dbb7bce9209e32ecdd --- /dev/null +++ "b/\347\253\240\345\273\272\345\206\233/WebApiV.Interface/WebApiV.Interface.csproj" @@ -0,0 +1,11 @@ + + + + netstandard2.0 + + + + + + + diff --git "a/\347\253\240\345\273\272\345\206\233/WebApiV.Service/WebApiV.Service.csproj" "b/\347\253\240\345\273\272\345\206\233/WebApiV.Service/WebApiV.Service.csproj" new file mode 100644 index 0000000000000000000000000000000000000000..9f5c4f4abb611103e8d62ab979dda9bfcb5a7fc2 --- /dev/null +++ "b/\347\253\240\345\273\272\345\206\233/WebApiV.Service/WebApiV.Service.csproj" @@ -0,0 +1,7 @@ + + + + netstandard2.0 + + + diff --git "a/\347\253\240\345\273\272\345\206\233/WebApiV.Test/WebApiV.Test.csproj" "b/\347\253\240\345\273\272\345\206\233/WebApiV.Test/WebApiV.Test.csproj" new file mode 100644 index 0000000000000000000000000000000000000000..9f5c4f4abb611103e8d62ab979dda9bfcb5a7fc2 --- /dev/null +++ "b/\347\253\240\345\273\272\345\206\233/WebApiV.Test/WebApiV.Test.csproj" @@ -0,0 +1,7 @@ + + + + netstandard2.0 + + + diff --git "a/\347\253\240\345\273\272\345\206\233/WebApiV.Utils/DbInitlizer.cs" "b/\347\253\240\345\273\272\345\206\233/WebApiV.Utils/DbInitlizer.cs" new file mode 100644 index 0000000000000000000000000000000000000000..dad976f87265ec083c440bf70ccc3144935b0e3d --- /dev/null +++ "b/\347\253\240\345\273\272\345\206\233/WebApiV.Utils/DbInitlizer.cs" @@ -0,0 +1,52 @@ +using Microsoft.EntityFrameworkCore.Internal; +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Collections.Generic; +using System.Text; +using WebApiV.Data; +using WebApiV.Data.Entity; +using WebApiV.Domain; + +namespace WebApiV.Utils +{ + public class DbInitlizer + { + public static void Seed(IServiceProvider service) + { + using(var score = service.CreateScope()) + { + var db = score.ServiceProvider.GetService(typeof(Admin10086Db))as Admin10086Db; + var _user = score.ServiceProvider.GetService(typeof(IRespository))as IRespository; + var _role = score.ServiceProvider.GetService(typeof(IRespository)) as IRespository; + db.Database.EnsureCreated(); + + var emp = db.Users.Any(); + if (!emp) + { + var rloe1 = new Role + { + RoleName = "老王隔壁", + ShortTell = "就是老黄", + }; + _role.Insert(rloe1); + + _user.InsertBlck(new User[] + { + new User + { + UserName="sa", + PassWord="123", + RoleId=rloe1.Id, + }, + new User + { + UserName="sb", + PassWord="456", + RoleId=rloe1.Id, + } + }); + } + } + } + } +} diff --git "a/\347\253\240\345\273\272\345\206\233/WebApiV.Utils/File/ClobalExcptionFilter.cs" "b/\347\253\240\345\273\272\345\206\233/WebApiV.Utils/File/ClobalExcptionFilter.cs" new file mode 100644 index 0000000000000000000000000000000000000000..fe5e3d2212352e06a4bd49882131845d5b7102d9 --- /dev/null +++ "b/\347\253\240\345\273\272\345\206\233/WebApiV.Utils/File/ClobalExcptionFilter.cs" @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Mvc.Filters; +using System; +using System.Collections.Generic; +using System.Text; +using WebApiV.Implement.Log; +using WebApiV.Interface.Log; +using WebApiV.Utils.Hellper; + +namespace WebApiV.Utils.File +{ + public class ClobalExcptionFilter : IExceptionFilter + { + private readonly ILog _log; + + public ClobalExcptionFilter(ILog log) + { + _log = log; + } + + public void OnException(ExceptionContext context) + { + _log.Error(context.Exception); + context.ExceptionHandled = true; + } + } +} diff --git "a/\347\253\240\345\273\272\345\206\233/WebApiV.Utils/Hellper/LogHellper.cs" "b/\347\253\240\345\273\272\345\206\233/WebApiV.Utils/Hellper/LogHellper.cs" new file mode 100644 index 0000000000000000000000000000000000000000..2997eff5b2a32f2da2cce59927709bfaec242234 --- /dev/null +++ "b/\347\253\240\345\273\272\345\206\233/WebApiV.Utils/Hellper/LogHellper.cs" @@ -0,0 +1,42 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Text; +using WebApiV.Data.Entity; +using WebApiV.Domain.Enum; +using WebApiV.Interface.Log; + +namespace WebApiV.Utils.Hellper +{ + public static class LogHellper + { + public static void Logger(this ILog log, LogsLevel logLevel, Exception exception, int userId) + { + var item = new Logs + { + LogsLevel = (int)logLevel, + ShortMessage = exception.Message, + FullMessage = exception.ToString(), + UserId = userId + }; + log.Insert(item); + } + + public static void Info(this ILog log, Exception exception, LogsLevel logLevel = LogsLevel.信息, int userId = 0) + { + Logger(log, logLevel, exception, userId); + } + public static void Debug(this ILog log, Exception exception, LogsLevel logLevel = LogsLevel.调试, int userId = 0) + { + Logger(log, logLevel, exception, userId); + } + public static void Error(this ILog log, Exception exception, LogsLevel logLevel = LogsLevel.错误, int userId = 0) + { + Logger(log, logLevel, exception, userId); + } + public static void Fatal(this ILog log, Exception exception, LogsLevel logLevel = LogsLevel.崩溃, int userId = 0) + { + Logger(log, logLevel, exception, userId); + } + } +} diff --git "a/\347\253\240\345\273\272\345\206\233/WebApiV.Utils/WebApiV.Utils.csproj" "b/\347\253\240\345\273\272\345\206\233/WebApiV.Utils/WebApiV.Utils.csproj" new file mode 100644 index 0000000000000000000000000000000000000000..168c6f0542bb2510ed4cde268418817fdad2a961 --- /dev/null +++ "b/\347\253\240\345\273\272\345\206\233/WebApiV.Utils/WebApiV.Utils.csproj" @@ -0,0 +1,18 @@ + + + + netstandard2.0 + + + + + + + + + + + + + + diff --git "a/\347\253\240\345\273\272\345\206\233/WebApiV.sln" "b/\347\253\240\345\273\272\345\206\233/WebApiV.sln" new file mode 100644 index 0000000000000000000000000000000000000000..8c6fc185441b404ada6949b6d7034a70a101496c --- /dev/null +++ "b/\347\253\240\345\273\272\345\206\233/WebApiV.sln" @@ -0,0 +1,67 @@ + +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}") = "WebApiV", "WebApiV\WebApiV.csproj", "{CBBF3F5F-7D0D-4924-9F1F-E006B0663631}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiV.Data", "WebApiV.Data\WebApiV.Data.csproj", "{16157AF0-EC51-4A34-A740-8DE9FC75CB0A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiV.Domain", "WebApiV.Domain\WebApiV.Domain.csproj", "{7D2C94F7-6C3B-4E01-897B-2426DA6B7E70}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiV.Implement", "WebApiV.Implement\WebApiV.Implement.csproj", "{19E026B9-3836-4356-8A9E-34EBC959B55D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiV.Interface", "WebApiV.Interface\WebApiV.Interface.csproj", "{8C0DE35D-12AD-41B0-B810-C0BE9D3CA4BF}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiV.Service", "WebApiV.Service\WebApiV.Service.csproj", "{FCC12D17-1128-406C-9862-A017137C7041}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiV.Test", "WebApiV.Test\WebApiV.Test.csproj", "{58BAB7A4-FE60-47C5-A2BF-CEFFC3CDC698}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiV.Utils", "WebApiV.Utils\WebApiV.Utils.csproj", "{0B396BF6-0569-4672-B89A-50F33839ACF6}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CBBF3F5F-7D0D-4924-9F1F-E006B0663631}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CBBF3F5F-7D0D-4924-9F1F-E006B0663631}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CBBF3F5F-7D0D-4924-9F1F-E006B0663631}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CBBF3F5F-7D0D-4924-9F1F-E006B0663631}.Release|Any CPU.Build.0 = Release|Any CPU + {16157AF0-EC51-4A34-A740-8DE9FC75CB0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {16157AF0-EC51-4A34-A740-8DE9FC75CB0A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {16157AF0-EC51-4A34-A740-8DE9FC75CB0A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {16157AF0-EC51-4A34-A740-8DE9FC75CB0A}.Release|Any CPU.Build.0 = Release|Any CPU + {7D2C94F7-6C3B-4E01-897B-2426DA6B7E70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7D2C94F7-6C3B-4E01-897B-2426DA6B7E70}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7D2C94F7-6C3B-4E01-897B-2426DA6B7E70}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7D2C94F7-6C3B-4E01-897B-2426DA6B7E70}.Release|Any CPU.Build.0 = Release|Any CPU + {19E026B9-3836-4356-8A9E-34EBC959B55D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {19E026B9-3836-4356-8A9E-34EBC959B55D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {19E026B9-3836-4356-8A9E-34EBC959B55D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {19E026B9-3836-4356-8A9E-34EBC959B55D}.Release|Any CPU.Build.0 = Release|Any CPU + {8C0DE35D-12AD-41B0-B810-C0BE9D3CA4BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8C0DE35D-12AD-41B0-B810-C0BE9D3CA4BF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8C0DE35D-12AD-41B0-B810-C0BE9D3CA4BF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8C0DE35D-12AD-41B0-B810-C0BE9D3CA4BF}.Release|Any CPU.Build.0 = Release|Any CPU + {FCC12D17-1128-406C-9862-A017137C7041}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FCC12D17-1128-406C-9862-A017137C7041}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FCC12D17-1128-406C-9862-A017137C7041}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FCC12D17-1128-406C-9862-A017137C7041}.Release|Any CPU.Build.0 = Release|Any CPU + {58BAB7A4-FE60-47C5-A2BF-CEFFC3CDC698}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {58BAB7A4-FE60-47C5-A2BF-CEFFC3CDC698}.Debug|Any CPU.Build.0 = Debug|Any CPU + {58BAB7A4-FE60-47C5-A2BF-CEFFC3CDC698}.Release|Any CPU.ActiveCfg = Release|Any CPU + {58BAB7A4-FE60-47C5-A2BF-CEFFC3CDC698}.Release|Any CPU.Build.0 = Release|Any CPU + {0B396BF6-0569-4672-B89A-50F33839ACF6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0B396BF6-0569-4672-B89A-50F33839ACF6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0B396BF6-0569-4672-B89A-50F33839ACF6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0B396BF6-0569-4672-B89A-50F33839ACF6}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {08D59302-674E-4D7A-A8AC-388D69BCCE35} + EndGlobalSection +EndGlobal diff --git "a/\347\253\240\345\273\272\345\206\233/WebApplication1/Controllers/WeatherForecastController.cs" "b/\347\253\240\345\273\272\345\206\233/WebApiV/Controllers/WeatherForecastController.cs" similarity index 64% rename from "\347\253\240\345\273\272\345\206\233/WebApplication1/Controllers/WeatherForecastController.cs" rename to "\347\253\240\345\273\272\345\206\233/WebApiV/Controllers/WeatherForecastController.cs" index 04743255f319404392c631048fe0a900d3a438f3..2348e57f0cbe447b74c90b8bc85d041fbea09c9d 100644 --- "a/\347\253\240\345\273\272\345\206\233/WebApplication1/Controllers/WeatherForecastController.cs" +++ "b/\347\253\240\345\273\272\345\206\233/WebApiV/Controllers/WeatherForecastController.cs" @@ -3,40 +3,35 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; -using WebApplication1.Controllers.Demain; -using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json; -using Microsoft.EntityFrameworkCore; -using WebApplication1.Demain.Hellper; +using WebApiV.Data; -namespace WebApplication1.Controllers +namespace WebApiV.Controllers { [ApiController] [Route("[controller]")] public class WeatherForecastController : ControllerBase { - private readonly AdminDb _db; - private static readonly string[] Summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" }; private readonly ILogger _logger; + private readonly Admin10086Db _db; - public WeatherForecastController(ILogger logger,AdminDb adminDb) + public WeatherForecastController(ILogger logger,Admin10086Db admin) { _logger = logger; - _db = adminDb; + _db = admin; } [HttpGet] - public string Get() + public IEnumerable Get() { - var res = _db.Students.Include(x=>x.Clbum).ToList(); - - return JsonHellper.SerializeObject(res); + throw new Exception("错误:error desc"); } } } diff --git "a/\347\253\240\345\273\272\345\206\233/WebApplication1/Program.cs" "b/\347\253\240\345\273\272\345\206\233/WebApiV/Program.cs" similarity index 96% rename from "\347\253\240\345\273\272\345\206\233/WebApplication1/Program.cs" rename to "\347\253\240\345\273\272\345\206\233/WebApiV/Program.cs" index c015cb72dc7de67e18932bdb85945153a9eeb84e..8f1d3a0b40a70e41695ea601e3c2da05fc698d9d 100644 --- "a/\347\253\240\345\273\272\345\206\233/WebApplication1/Program.cs" +++ "b/\347\253\240\345\273\272\345\206\233/WebApiV/Program.cs" @@ -7,7 +7,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -namespace WebApplication1 +namespace WebApiV { public class Program { diff --git "a/\347\253\240\345\273\272\345\206\233/WebApplication1/Properties/launchSettings.json" "b/\347\253\240\345\273\272\345\206\233/WebApiV/Properties/launchSettings.json" similarity index 90% rename from "\347\253\240\345\273\272\345\206\233/WebApplication1/Properties/launchSettings.json" rename to "\347\253\240\345\273\272\345\206\233/WebApiV/Properties/launchSettings.json" index 553d6526ad42786df87112f0cc1b674a885d3bba..04194223df638d7b81b96be3a63d898beee0d3ab 100644 --- "a/\347\253\240\345\273\272\345\206\233/WebApplication1/Properties/launchSettings.json" +++ "b/\347\253\240\345\273\272\345\206\233/WebApiV/Properties/launchSettings.json" @@ -4,7 +4,7 @@ "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { - "applicationUrl": "http://localhost:55103", + "applicationUrl": "http://localhost:58622", "sslPort": 0 } }, @@ -17,7 +17,7 @@ "ASPNETCORE_ENVIRONMENT": "Development" } }, - "WebApplication1": { + "WebApiV": { "commandName": "Project", "launchBrowser": true, "launchUrl": "weatherforecast", diff --git "a/\347\253\240\345\273\272\345\206\233/WebApplication1/Startup.cs" "b/\347\253\240\345\273\272\345\206\233/WebApiV/Startup.cs" similarity index 75% rename from "\347\253\240\345\273\272\345\206\233/WebApplication1/Startup.cs" rename to "\347\253\240\345\273\272\345\206\233/WebApiV/Startup.cs" index 570af10cccbb4da98cd25416d42b4d6d91ee3106..e05ad175cc285bed2cbbca0cad12b898fba98cbc 100644 --- "a/\347\253\240\345\273\272\345\206\233/WebApplication1/Startup.cs" +++ "b/\347\253\240\345\273\272\345\206\233/WebApiV/Startup.cs" @@ -9,11 +9,13 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -using WebApplication1.Controllers; -using WebApplication1.Demain.Hellper.Implementation; -using WebApplication1.Demain.Hellper.Interface; +using WebApiV.Domain; +using WebApiV.Implement.Log; +using WebApiV.Interface.Log; +using WebApiV.Utils; +using WebApiV.Utils.File; -namespace WebApplication1 +namespace WebApiV { public class Startup { @@ -27,11 +29,10 @@ namespace WebApplication1 // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - services.AddDbContext(); - - services.AddScoped(typeof(IRespository<>), typeof(EfRespositoryy<>)); - - services.AddControllers(); + services.AddDbContext(); + services.AddScoped(typeof(IRespository<>), typeof(EfRespository<>)); + services.AddScoped(typeof(ILog), typeof(Log)); + services.AddControllers(options => options.Filters.Add()) ; } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -42,7 +43,6 @@ namespace WebApplication1 app.UseDeveloperExceptionPage(); } - app.UseRouting(); app.UseAuthorization(); @@ -51,8 +51,7 @@ namespace WebApplication1 { endpoints.MapControllers(); }); - - DbInit.Init(); + DbInitlizer.Seed(app.ApplicationServices); } } } diff --git "a/\347\253\240\345\273\272\345\206\233/WebApplication1/WeatherForecast.cs" "b/\347\253\240\345\273\272\345\206\233/WebApiV/WeatherForecast.cs" similarity index 91% rename from "\347\253\240\345\273\272\345\206\233/WebApplication1/WeatherForecast.cs" rename to "\347\253\240\345\273\272\345\206\233/WebApiV/WeatherForecast.cs" index 11a0296b7e9c89531aa5392b38b44c4c2c7cd3a0..1cb5a4f8fc3f3ebda527d9917c5905700edb1a0a 100644 --- "a/\347\253\240\345\273\272\345\206\233/WebApplication1/WeatherForecast.cs" +++ "b/\347\253\240\345\273\272\345\206\233/WebApiV/WeatherForecast.cs" @@ -1,6 +1,6 @@ using System; -namespace WebApplication1 +namespace WebApiV { public class WeatherForecast { diff --git "a/\347\253\240\345\273\272\345\206\233/WebApplication1/WebApplication1.csproj" "b/\347\253\240\345\273\272\345\206\233/WebApiV/WebApiV.csproj" similarity index 57% rename from "\347\253\240\345\273\272\345\206\233/WebApplication1/WebApplication1.csproj" rename to "\347\253\240\345\273\272\345\206\233/WebApiV/WebApiV.csproj" index da10d50a32b4ec10963d789edcdb8d045c0da572..e3ee5d0a814eb5cddf4f32f0a436b920de216f85 100644 --- "a/\347\253\240\345\273\272\345\206\233/WebApplication1/WebApplication1.csproj" +++ "b/\347\253\240\345\273\272\345\206\233/WebApiV/WebApiV.csproj" @@ -5,10 +5,13 @@ - - + + + + + diff --git "a/\347\253\240\345\273\272\345\206\233/WebApplication1/appsettings.Development.json" "b/\347\253\240\345\273\272\345\206\233/WebApiV/appsettings.Development.json" similarity index 100% rename from "\347\253\240\345\273\272\345\206\233/WebApplication1/appsettings.Development.json" rename to "\347\253\240\345\273\272\345\206\233/WebApiV/appsettings.Development.json" diff --git "a/\347\253\240\345\273\272\345\206\233/WebApplication1/appsettings.json" "b/\347\253\240\345\273\272\345\206\233/WebApiV/appsettings.json" similarity index 100% rename from "\347\253\240\345\273\272\345\206\233/WebApplication1/appsettings.json" rename to "\347\253\240\345\273\272\345\206\233/WebApiV/appsettings.json" diff --git "a/\347\253\240\345\273\272\345\206\233/WebApplication1.sln" "b/\347\253\240\345\273\272\345\206\233/WebApplication1.sln" deleted file mode 100644 index 787e033078463765cb6ebdf75f10f09c30920cd5..0000000000000000000000000000000000000000 --- "a/\347\253\240\345\273\272\345\206\233/WebApplication1.sln" +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30104.148 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApplication1", "WebApplication1\WebApplication1.csproj", "{0B163740-6BB3-437E-8AB3-B840417B952C}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {0B163740-6BB3-437E-8AB3-B840417B952C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0B163740-6BB3-437E-8AB3-B840417B952C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0B163740-6BB3-437E-8AB3-B840417B952C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0B163740-6BB3-437E-8AB3-B840417B952C}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {04FC1180-0ACB-4A8B-AAE7-CDBFCABCCD0C} - EndGlobalSection -EndGlobal diff --git "a/\347\253\240\345\273\272\345\206\233/WebApplication1/Controllers/TestController.cs" "b/\347\253\240\345\273\272\345\206\233/WebApplication1/Controllers/TestController.cs" deleted file mode 100644 index f7f674a27c1b3dda9d404d18a9bb65a0ea37275e..0000000000000000000000000000000000000000 --- "a/\347\253\240\345\273\272\345\206\233/WebApplication1/Controllers/TestController.cs" +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore.Migrations; -using WebApplication1.Controllers.Demain; -using WebApplication1.Demain.Hellper; -using WebApplication1.Demain.Hellper.Interface; - -namespace WebApplication1.Controllers -{ - [Route("api/[controller]")] - [ApiController] - public class TestController : ControllerBase - { - private readonly IRespository Stu_Respository; - - public TestController(IRespository StuRespository) - { - Stu_Respository = StuRespository; - } - - public string Get() - { - var list = Stu_Respository.Table.ToList(); - return JsonHellper.SerializeObject(list); - } - } -} diff --git "a/\347\253\240\345\273\272\345\206\233/WebApplication1/Demain/DbInit.cs" "b/\347\253\240\345\273\272\345\206\233/WebApplication1/Demain/DbInit.cs" deleted file mode 100644 index b1b8a45ebd74ec477efe139ed632d50c02999fe5..0000000000000000000000000000000000000000 --- "a/\347\253\240\345\273\272\345\206\233/WebApplication1/Demain/DbInit.cs" +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using WebApplication1.Controllers.Demain; - -namespace WebApplication1.Controllers -{ - public class DbInit - { - public static void Init() - { - using(var db = new AdminDb()) - { - db.Database.EnsureCreated(); - - var Emplit = db.Students.Any(); - - if (!Emplit) - { - var Class1 = new Clbum - { - ClassName = "计应4班", - StudentNun = 38 - }; - - db.Clbums.Add(Class1); - db.SaveChanges(); - - - db.AddRange(new Student[] - { - new Student - { - StudentName="华铭隔壁", - Age=18, - Sex="男", - ClbumId=Class1.Id - }, - new Student - { - StudentName="许嘉隔壁", - Age=19, - Sex="男", - ClbumId=Class1.Id - } - }); - db.SaveChanges(); - - } - } - } - } -} diff --git "a/\347\253\240\345\273\272\345\206\233/WebApplication1/Demain/Entity/Clbum.cs" "b/\347\253\240\345\273\272\345\206\233/WebApplication1/Demain/Entity/Clbum.cs" deleted file mode 100644 index d0867c9c56980867982c3f0390096806587b8a9b..0000000000000000000000000000000000000000 --- "a/\347\253\240\345\273\272\345\206\233/WebApplication1/Demain/Entity/Clbum.cs" +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace WebApplication1.Controllers.Demain -{ - public class Clbum:BaseEntity - { - public string ClassName { get; set; } - public int StudentNun { get; set; } - - public IEnumerable Students { get; set; } - } -} diff --git "a/\347\253\240\345\273\272\345\206\233/WebApplication1/Demain/Entity/Student.cs" "b/\347\253\240\345\273\272\345\206\233/WebApplication1/Demain/Entity/Student.cs" deleted file mode 100644 index 0ad8b48f8b7a3feca5fe9477a46ca93ed58dc20b..0000000000000000000000000000000000000000 --- "a/\347\253\240\345\273\272\345\206\233/WebApplication1/Demain/Entity/Student.cs" +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace WebApplication1.Controllers.Demain -{ - public class Student:BaseEntity - { - public string StudentName { get; set; } - public string Sex { get; set; } - public int Age { get; set; } - public int ClbumId { get; set; } - public Clbum Clbum { get; set; } - } -} diff --git "a/\347\253\240\345\273\272\345\206\233/WebApplication1/Hellper/JsonHellper.cs" "b/\347\253\240\345\273\272\345\206\233/WebApplication1/Hellper/JsonHellper.cs" deleted file mode 100644 index ddb2a8edfc86a5088bbd8c4093470345d8b9deed..0000000000000000000000000000000000000000 --- "a/\347\253\240\345\273\272\345\206\233/WebApplication1/Hellper/JsonHellper.cs" +++ /dev/null @@ -1,20 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace WebApplication1.Demain.Hellper -{ - public class JsonHellper - { - public static string SerializeObject(object obj) - { - return JsonConvert.SerializeObject(obj, Formatting.Indented, new JsonSerializerSettings - { - ReferenceLoopHandling = ReferenceLoopHandling.Ignore, - DateFormatString = "yyyy-MM-dd HH:mm:ss" - }); - } - } -} diff --git "a/\351\273\204\347\204\225/DITest/\351\273\204\347\204\225 - \345\277\253\346\215\267\346\226\271\345\274\217.lnk" "b/\351\273\204\347\204\225/DITest/\351\273\204\347\204\225 - \345\277\253\346\215\267\346\226\271\345\274\217.lnk" new file mode 100644 index 0000000000000000000000000000000000000000..c021179fa33cda2d6fe4964b272f296bf419e229 Binary files /dev/null and "b/\351\273\204\347\204\225/DITest/\351\273\204\347\204\225 - \345\277\253\346\215\267\346\226\271\345\274\217.lnk" differ