diff --git "a/\346\261\237\346\226\260\344\273\201/Admin5000.sln" "b/\346\261\237\346\226\260\344\273\201/Admin5000.sln" new file mode 100644 index 0000000000000000000000000000000000000000..1a2bcff34dbc886a89e6b79c0d4fc68530b9629b --- /dev/null +++ "b/\346\261\237\346\226\260\344\273\201/Admin5000.sln" @@ -0,0 +1,25 @@ + +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}") = "Admin5000", "Admin5000\Admin5000.csproj", "{2C94A791-69C6-4C67-A9AA-1FB475A5F854}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2C94A791-69C6-4C67-A9AA-1FB475A5F854}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2C94A791-69C6-4C67-A9AA-1FB475A5F854}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2C94A791-69C6-4C67-A9AA-1FB475A5F854}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2C94A791-69C6-4C67-A9AA-1FB475A5F854}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D9CDE350-184C-43EA-BCAF-03FE0FADB9F8} + EndGlobalSection +EndGlobal diff --git "a/\346\261\237\346\226\260\344\273\201/Admin5000/Admin5000.csproj" "b/\346\261\237\346\226\260\344\273\201/Admin5000/Admin5000.csproj" new file mode 100644 index 0000000000000000000000000000000000000000..f21bc119dbc166a19e771496ec3896dfcb72d621 --- /dev/null +++ "b/\346\261\237\346\226\260\344\273\201/Admin5000/Admin5000.csproj" @@ -0,0 +1,15 @@ + + + + netcoreapp3.1 + + + + + + + + + + + diff --git "a/\346\261\237\346\226\260\344\273\201/Admin5000/Controllers/Test5000Controller.cs" "b/\346\261\237\346\226\260\344\273\201/Admin5000/Controllers/Test5000Controller.cs" new file mode 100644 index 0000000000000000000000000000000000000000..55120bf6fa4b5c5f80a6df8cbd466e245c586eae --- /dev/null +++ "b/\346\261\237\346\226\260\344\273\201/Admin5000/Controllers/Test5000Controller.cs" @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Admin5000.Domain.Entity; +using Admin5000.Helper; +using Admin5000.Interface; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace Admin5000.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class Test5000Controller : ControllerBase + { + private readonly IPespository _userPespository; + public Test5000Controller(IPespository userPespository) + { + _userPespository = userPespository; + } + + + [Route("Get")] + public string Get() + { + var list = _userPespository.Table.Include(x => x.Roles).ToList(); + return JsonHelper.SerializeObject(list); + } + + [Route("GetId/{id}")] + + public string GetId(int id) + { + var list = _userPespository.GetById(id); + + return JsonHelper.SerializeObject(list); + } + + [Route("DeleteId/{id}")] + public string DeleteProduct(int id) + { + _userPespository.Delete(id); + + var list = _userPespository.Table.ToList(); + return JsonHelper.SerializeObject(list); + } + [Route("insert")] + public string Insert() + { + var user = new Users + { + UserName = "老胡", + Passsword = "132654", + RolesId = 3 + }; + _userPespository.Insert(user); + return JsonHelper.SerializeObject(_userPespository.Table.ToList()); + } + + [Route("Update")] + public string Update() + { + var user = new Users + { + Id = 5, + UserName = "脑残片", + Passsword = "7754321", + RolesId = 3 + }; + _userPespository.Update(user); + return JsonHelper.SerializeObject(_userPespository.Table.ToList()); + } + } +} \ No newline at end of file diff --git "a/\346\261\237\346\226\260\344\273\201/Admin5000/Controllers/VluesController.cs" "b/\346\261\237\346\226\260\344\273\201/Admin5000/Controllers/VluesController.cs" new file mode 100644 index 0000000000000000000000000000000000000000..ad83ac34d351597796f0acf0c711b14269ff38f7 --- /dev/null +++ "b/\346\261\237\346\226\260\344\273\201/Admin5000/Controllers/VluesController.cs" @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Admin5000.Domain; +using Admin5000.Helper; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace Admin5000.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class VluesController : ControllerBase + { + + private readonly Admin5000DbContext _db; + + public VluesController(Admin5000DbContext admin5000DbContext) + { + _db = admin5000DbContext; + } + + // GET: api/Test + [HttpGet] + public string Get() + { + var res = _db.Users.Include(x => x.Roles).ToList(); + return JsonHelper.SerializeObject(res); + } + + // GET: api/Test/5 + [HttpGet("{id}", Name = "Get")] + public string Get(int id) + { + return "value"; + } + + // POST: api/Test + [HttpPost] + public void Post([FromBody] string value) + { + } + + // PUT: api/Test/5 + [HttpPut("{id}")] + public void Put(int id, [FromBody] string value) + { + } + + // DELETE: api/ApiWithActions/5 + [HttpDelete("{id}")] + public void Delete(int id) + { + } + } +} diff --git "a/\346\261\237\346\226\260\344\273\201/Admin5000/Domain/Admin5000DbContext.cs" "b/\346\261\237\346\226\260\344\273\201/Admin5000/Domain/Admin5000DbContext.cs" new file mode 100644 index 0000000000000000000000000000000000000000..4f78dca582e234c462938d9edaa6e5cb32b01473 --- /dev/null +++ "b/\346\261\237\346\226\260\344\273\201/Admin5000/Domain/Admin5000DbContext.cs" @@ -0,0 +1,23 @@ +using Admin5000.Domain.Entity; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Admin5000.Domain +{ + public class Admin5000DbContext:DbContext + { + + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder.UseSqlServer("server=.;database=Admin5000;uid=sa;password=123456;"); + } + + public DbSet Users { get; set; } + + public DbSet Roles { get; set; } + } +} diff --git "a/\346\261\237\346\226\260\344\273\201/Admin5000/Domain/BaseEntity.cs" "b/\346\261\237\346\226\260\344\273\201/Admin5000/Domain/BaseEntity.cs" new file mode 100644 index 0000000000000000000000000000000000000000..b618ca59d4087ee1e9683cbaf89ba1dc025406b9 --- /dev/null +++ "b/\346\261\237\346\226\260\344\273\201/Admin5000/Domain/BaseEntity.cs" @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Admin5000.Domain +{ + public class BaseEntity + { + + public BaseEntity() + { + IsActioned = true; + IsDeleted = false; + CreateTime = DateTime.Now; + UpdateTime = DateTime.Now; + } + + public int Id { get; set; } + + public bool IsActioned { get; set; } + + public bool IsDeleted { get; set; } + + public int DisplayOrder { get; set; } + + public DateTime CreateTime { get; set; } + + public DateTime UpdateTime { get; set; } + } +} diff --git "a/\346\261\237\346\226\260\344\273\201/Admin5000/Domain/DbInitializeHelper.cs" "b/\346\261\237\346\226\260\344\273\201/Admin5000/Domain/DbInitializeHelper.cs" new file mode 100644 index 0000000000000000000000000000000000000000..e84a8d2e5f7d1065e7a992a70958c3cfc7fbe485 --- /dev/null +++ "b/\346\261\237\346\226\260\344\273\201/Admin5000/Domain/DbInitializeHelper.cs" @@ -0,0 +1,51 @@ +using Admin5000.Domain.Entity; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Admin5000.Domain +{ + public class DbInitializeHelper + { + public static void Seed () + { + using (var db=new Admin5000DbContext()) + { + + db.Database.EnsureCreated(); + var hsaUse = db.Users.Any(); + + if (!hsaUse) + { + var role = new Roles + { + RoleName="管理员", + Description="这是这是一个管理员" + }; + + db.Roles.Add(role); + db.SaveChanges(); + + db.Users.AddRange(new Users[] + { + new Users + { + UserName="大壮", + Passsword="123456", + RolesId=role.Id + }, + new Users + { + UserName="盖伦", + Passsword="123456", + RolesId=role.Id + } + }); + + db.SaveChanges(); + } + } + } + } +} diff --git "a/\346\261\237\346\226\260\344\273\201/Admin5000/Domain/Entity/Roles.cs" "b/\346\261\237\346\226\260\344\273\201/Admin5000/Domain/Entity/Roles.cs" new file mode 100644 index 0000000000000000000000000000000000000000..fa4b2fd3be8b762e750fef29fe15503fff6cf5ba --- /dev/null +++ "b/\346\261\237\346\226\260\344\273\201/Admin5000/Domain/Entity/Roles.cs" @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Admin5000.Domain.Entity +{ + public class Roles:BaseEntity + { + public string RoleName { get; set; } + + public string Description { get; set; } + + public IEnumerable Users { get; set; } + } +} diff --git "a/\346\261\237\346\226\260\344\273\201/Admin5000/Domain/Entity/Users.cs" "b/\346\261\237\346\226\260\344\273\201/Admin5000/Domain/Entity/Users.cs" new file mode 100644 index 0000000000000000000000000000000000000000..a32aea3b05d8489bc1e614871cd4ddc4446d9ffc --- /dev/null +++ "b/\346\261\237\346\226\260\344\273\201/Admin5000/Domain/Entity/Users.cs" @@ -0,0 +1,19 @@ +using Microsoft.AspNetCore.Authorization.Infrastructure; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Admin5000.Domain.Entity +{ + public class Users:BaseEntity + { + public string UserName { get; set; } + + public string Passsword { get; set; } + + public int RolesId { get; set; } + + public Roles Roles { get; set; } + } +} diff --git "a/\346\261\237\346\226\260\344\273\201/Admin5000/Helper/JsonHelper.cs" "b/\346\261\237\346\226\260\344\273\201/Admin5000/Helper/JsonHelper.cs" new file mode 100644 index 0000000000000000000000000000000000000000..7308f7788188e5a9bbf455151536784fcc48586f --- /dev/null +++ "b/\346\261\237\346\226\260\344\273\201/Admin5000/Helper/JsonHelper.cs" @@ -0,0 +1,23 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Admin5000.Helper +{ + public class JsonHelper + { + public static string SerializeObject(object obj) + { + + string str = JsonConvert.SerializeObject(obj, Formatting.Indented, new JsonSerializerSettings() + { + + ReferenceLoopHandling = ReferenceLoopHandling.Ignore, + DateFormatString = "yyyy-dd-mm hh:mm:ss" + }); + return str; + } + } +} diff --git "a/\346\261\237\346\226\260\344\273\201/Admin5000/Implementation/EFPesPository.cs" "b/\346\261\237\346\226\260\344\273\201/Admin5000/Implementation/EFPesPository.cs" new file mode 100644 index 0000000000000000000000000000000000000000..77eade8833b1b191556b8222f9307d5189eb1d65 --- /dev/null +++ "b/\346\261\237\346\226\260\344\273\201/Admin5000/Implementation/EFPesPository.cs" @@ -0,0 +1,84 @@ +using Admin5000.Domain; +using Admin5000.Interface; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Admin5000.Implementation +{ + public class EFPesPository : IPespository where T : BaseEntity + { + private readonly Admin5000DbContext db; + + + private DbSet _entity; + + + protected DbSet Entity + { + get + { + if (_entity == null) + { + _entity = db.Set(); + } + return _entity; + } + } + + public IQueryable Table + { + get + { + return Entity; + } + + } + // entity 和table 都是返回一个entity + + public EFPesPository(Admin5000DbContext dbcontext) + { + db = dbcontext; + } + + public void Delete(T entity) + { + _entity.Remove(entity); + db.SaveChanges(); + } + + public void Delete(int id) + { + var row = Table.Where(x => x.Id == id).FirstOrDefault(); + Delete(row); + } + + + + public T GetById(int id) + { + return Table.Where(x => x.Id == id).FirstOrDefault(); + + } + + public void Insert(T entity) + { + Entity.Add(entity); + db.SaveChanges(); + } + + public void InsertBulk(IEnumerable list) + { + Entity.AddRange(list); + db.SaveChanges(); + } + + public void Update(T entity) + { + Entity.Update(entity); + db.SaveChanges(); + } + } +} diff --git "a/\346\261\237\346\226\260\344\273\201/Admin5000/Interface/IPespository.cs" "b/\346\261\237\346\226\260\344\273\201/Admin5000/Interface/IPespository.cs" new file mode 100644 index 0000000000000000000000000000000000000000..69ae520ae4bcbf99d9ecca425be4e5f5e52cdfa4 --- /dev/null +++ "b/\346\261\237\346\226\260\344\273\201/Admin5000/Interface/IPespository.cs" @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Admin5000.Interface +{ + public interface IPespository + { + IQueryable Table { get; } + + T GetById(int id); + + void Insert(T entity); + void InsertBulk(IEnumerable list); + void Update(T entity); + void Delete(T entity); + void Delete(int id); + } +} diff --git "a/\346\261\237\346\226\260\344\273\201/Admin5000/Program.cs" "b/\346\261\237\346\226\260\344\273\201/Admin5000/Program.cs" new file mode 100644 index 0000000000000000000000000000000000000000..66c2426efe7669428d3b393ed027e2dad42a90a6 --- /dev/null +++ "b/\346\261\237\346\226\260\344\273\201/Admin5000/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 Admin5000 +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git "a/\346\261\237\346\226\260\344\273\201/Admin5000/Properties/launchSettings.json" "b/\346\261\237\346\226\260\344\273\201/Admin5000/Properties/launchSettings.json" new file mode 100644 index 0000000000000000000000000000000000000000..17cb65b3d2bc7c892b10b27459666bd7f3c805d5 --- /dev/null +++ "b/\346\261\237\346\226\260\344\273\201/Admin5000/Properties/launchSettings.json" @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:63578", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Admin5000": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "applicationUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git "a/\346\261\237\346\226\260\344\273\201/Admin5000/Startup.cs" "b/\346\261\237\346\226\260\344\273\201/Admin5000/Startup.cs" new file mode 100644 index 0000000000000000000000000000000000000000..277161cfdbfc516e6c3d6abdfb393984502af8dd --- /dev/null +++ "b/\346\261\237\346\226\260\344\273\201/Admin5000/Startup.cs" @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Admin5000.Domain; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace Admin5000 +{ + 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.AddDbContext(); + + + services.AddControllers(); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + + DbInitializeHelper.Seed(); + } + } +} diff --git "a/\346\261\237\346\226\260\344\273\201/Admin5000/WeatherForecast.cs" "b/\346\261\237\346\226\260\344\273\201/Admin5000/WeatherForecast.cs" new file mode 100644 index 0000000000000000000000000000000000000000..820fd246b4fe1e464c5ae77eff2678665894f168 --- /dev/null +++ "b/\346\261\237\346\226\260\344\273\201/Admin5000/WeatherForecast.cs" @@ -0,0 +1,15 @@ +using System; + +namespace Admin5000 +{ + public class WeatherForecast + { + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string Summary { get; set; } + } +} diff --git "a/\346\261\237\346\226\260\344\273\201/Admin5000/appsettings.Development.json" "b/\346\261\237\346\226\260\344\273\201/Admin5000/appsettings.Development.json" new file mode 100644 index 0000000000000000000000000000000000000000..8983e0fc1c5e2795ccfde0c771c6d66c88ef4a42 --- /dev/null +++ "b/\346\261\237\346\226\260\344\273\201/Admin5000/appsettings.Development.json" @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git "a/\346\261\237\346\226\260\344\273\201/Admin5000/appsettings.json" "b/\346\261\237\346\226\260\344\273\201/Admin5000/appsettings.json" new file mode 100644 index 0000000000000000000000000000000000000000..d9d9a9bff6fd6f3ee7ea00de958f135a4a28c6e6 --- /dev/null +++ "b/\346\261\237\346\226\260\344\273\201/Admin5000/appsettings.json" @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +}