diff --git "a/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000.sln" "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000.sln" new file mode 100644 index 0000000000000000000000000000000000000000..3b377fe1a948894e14f4c2bcde40ce9bf0ca0b68 --- /dev/null +++ "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000.sln" @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.757 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Admin1000", "Admin1000\Admin1000.csproj", "{DF66A4BA-0BC7-4BA5-AA66-AB6757460F95}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DF66A4BA-0BC7-4BA5-AA66-AB6757460F95}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DF66A4BA-0BC7-4BA5-AA66-AB6757460F95}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DF66A4BA-0BC7-4BA5-AA66-AB6757460F95}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DF66A4BA-0BC7-4BA5-AA66-AB6757460F95}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {907EECD4-3C45-4844-B18F-6BC0F6D22310} + EndGlobalSection +EndGlobal diff --git "a/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Admin1000.csproj" "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Admin1000.csproj" new file mode 100644 index 0000000000000000000000000000000000000000..6ba5fd12e74ec7902e41baa10c96e83faa6c8330 --- /dev/null +++ "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Admin1000.csproj" @@ -0,0 +1,19 @@ + + + + netcoreapp2.1 + + + + + + + + + + + + + + + diff --git "a/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Animals.cs" "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Animals.cs" new file mode 100644 index 0000000000000000000000000000000000000000..af4bf7564ec24776cf13069514e4dce0661d9c4c --- /dev/null +++ "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Animals.cs" @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Admin1000 +{ + public class Animals + { + public virtual void Eat() + { + Console.WriteLine("动物进食"); + } + } + public class Dog : Animals + { + public override void Eat() + { + Console.WriteLine("狗啃骨头"); + } + } + public class Cat : Animals + { + public override void Eat() + { + Console.WriteLine("猫抓老鼠"); + } + } +} diff --git "a/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Controllers/TestController.cs" "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Controllers/TestController.cs" new file mode 100644 index 0000000000000000000000000000000000000000..3867678591fe3f025f075dc7be356bd4995aabfd --- /dev/null +++ "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Controllers/TestController.cs" @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Admin1000.Domain.Entity; +using Admin1000.Helper; +using Admin1000.Interface; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace Admin1000.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class TestController : ControllerBase + { + private readonly IRespository _userRepository; + public TestController(IRespository userRepository) + { + _userRepository = userRepository; + } + public string Get() + { + var list = _userRepository.Table.ToList(); + return JsonHelper.SerializeObject(list); + + } + } +} \ No newline at end of file diff --git "a/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Controllers/ValuesController.cs" "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Controllers/ValuesController.cs" new file mode 100644 index 0000000000000000000000000000000000000000..1cf4c5e41a4f08263e9c23b8c67984ba363f86fb --- /dev/null +++ "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Controllers/ValuesController.cs" @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Admin1000.Domain.Entity; +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; + +namespace Admin1000.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class ValuesController : ControllerBase + { + private readonly Domain.Admin1000DbContext _db; + + + public ValuesController(Domain.Admin1000DbContext dbContext) + { + _db = dbContext; + } + + // GET api/values + [HttpGet] + public string Get() + { + var res = _db.Users.ToList(); + + + var x=JsonConvert.SerializeObject(res,Formatting.Indented); + + return x; + + //return new string[] { "value1", "value2" }; + } + + // GET api/values/5 + [HttpGet("{id}")] + public ActionResult Get(int id) + { + return "value"; + } + + // POST api/values + [HttpPost] + public void Post([FromBody] string value) + { + } + + // PUT api/values/5 + [HttpPut("{id}")] + public void Put(int id, [FromBody] string value) + { + } + + // DELETE api/values/5 + [HttpDelete("{id}")] + public void Delete(int id) + { + } + } +} diff --git "a/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Domain/Admin1000DbContext.cs" "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Domain/Admin1000DbContext.cs" new file mode 100644 index 0000000000000000000000000000000000000000..3a0cd7d29ec0fc6b9ae36275c7ac16f2afb17ce1 --- /dev/null +++ "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Domain/Admin1000DbContext.cs" @@ -0,0 +1,32 @@ +using Admin1000.Domain.Entity; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Admin1000.Domain +{ + public class Admin1000DbContext:DbContext + { + + public Admin1000DbContext() + { + + } + + public Admin1000DbContext(DbContextOptions options) : base(options) + { + + } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder.UseSqlServer("server=.;database=Admin1000;uid=sa;pwd=123456"); + } + + public DbSet Users { get; set; } + + public DbSet Roles { get; set; } + } +} diff --git "a/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Domain/BaseEntity.cs" "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Domain/BaseEntity.cs" new file mode 100644 index 0000000000000000000000000000000000000000..d7ab3b96d9c5a419f6352b72e2e087f695e6c26f --- /dev/null +++ "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Domain/BaseEntity.cs" @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Admin1000.Domain +{ + 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; } + + public string Remarks { get; set; } + } +} diff --git "a/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Domain/DbInitializer.cs" "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Domain/DbInitializer.cs" new file mode 100644 index 0000000000000000000000000000000000000000..0741a61e23c30ded6892563f65b85d4406880a54 --- /dev/null +++ "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Domain/DbInitializer.cs" @@ -0,0 +1,46 @@ +using Admin1000.Domain.Entity; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Admin1000.Domain +{ + public class DbInitializer + { + public static void Seed() + { + using(Admin1000DbContext db=new Admin1000DbContext()) + { + db.Database.EnsureCreated(); + + + var hasUser = db.Users.Any(); + + if (!hasUser) + { + var role = new Roles + { + RoleName = "管理员", + Description = "如你所见,这是一个管理员" + }; + + db.Roles.Add(role); + + db.SaveChanges(); + + db.Users.Add(new Users + { + Username = "admin", + Password = "admin", + RolesId = role.Id + }); + + db.SaveChanges(); + + + } + } + } + } +} diff --git "a/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Domain/Entity/Roles.cs" "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Domain/Entity/Roles.cs" new file mode 100644 index 0000000000000000000000000000000000000000..bba420be8bdb2b312da72024acd2fdd35db0b874 --- /dev/null +++ "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Domain/Entity/Roles.cs" @@ -0,0 +1,13 @@ +using System.Collections.Generic; + +namespace Admin1000.Domain.Entity +{ + public class Roles : BaseEntity + { + public string RoleName { get; set; } + + public string Description { get; set; } + + public IEnumerable Users { get; set; } + } +} \ No newline at end of file diff --git "a/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Domain/Entity/Users.cs" "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Domain/Entity/Users.cs" new file mode 100644 index 0000000000000000000000000000000000000000..af16920d720cb9cbf71e4b7ac67197ee3c0c4c12 --- /dev/null +++ "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Domain/Entity/Users.cs" @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Admin1000.Domain.Entity +{ + public class Users:BaseEntity + { + public string Username { get; set; } + + public string Password { get; set; } + + public int RolesId { get; set; } + + public Roles Roles { get; set; } + } +} diff --git "a/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Helper/JsonHelper.cs" "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Helper/JsonHelper.cs" new file mode 100644 index 0000000000000000000000000000000000000000..f6e813c1753d83ab7463e6052949978d654c46e3 --- /dev/null +++ "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Helper/JsonHelper.cs" @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Admin1000.Domain.Entity; + +namespace Admin1000.Helper +{ + public class JsonHelper + { + internal static string SerializeObject(List list) + { + throw new NotImplementedException(); + } + } +} diff --git "a/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Implementation/EfRespository.cs" "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Implementation/EfRespository.cs" new file mode 100644 index 0000000000000000000000000000000000000000..0988b3b417556489f672606aca8d1e163194fd85 --- /dev/null +++ "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Implementation/EfRespository.cs" @@ -0,0 +1,68 @@ +using Admin1000.Domain; +using Admin1000.Interface; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Admin1000.Implementation +{ + public class EfRespository:IRespositorywhere T :BaseEntity + { + private readonly Admin1000DbContext db; + private DbSet _entity; + protected DbSet Entity + { + get + { + if (_entity == null) + { + _entity = db.Set(); + } + return _entity; + } + } + public IQueryable Table + { + get + { + + return Entity; + } + } + public EfRespository(Admin1000DbContext dbContext) + { + db = dbContext; + } + public void Delete(T entity) + { + this._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 _entity.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/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Interface/IRespository.cs" "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Interface/IRespository.cs" new file mode 100644 index 0000000000000000000000000000000000000000..45e65ad2396cb3099f580a2864a092fdbfb7f80f --- /dev/null +++ "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Interface/IRespository.cs" @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Admin1000.Interface +{ + public interface IRespository + { + 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/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Program.cs" "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Program.cs" new file mode 100644 index 0000000000000000000000000000000000000000..68695243ed693156a3d3b631f8f3bf775f7b8efa --- /dev/null +++ "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Program.cs" @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; + +namespace Admin1000 +{ + public class Program + { + public static void Main(string[] args) + { + CreateWebHostBuilder(args).Build().Run(); + } + + public static IWebHostBuilder CreateWebHostBuilder(string[] args) => + WebHost.CreateDefaultBuilder(args) + .UseStartup(); + } +} diff --git "a/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Properties/launchSettings.json" "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Properties/launchSettings.json" new file mode 100644 index 0000000000000000000000000000000000000000..045615e836b0402e9d0099508f71799cc993e9f6 --- /dev/null +++ "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Properties/launchSettings.json" @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:1498", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "api/values", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Admin1000": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "api/values", + "applicationUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} \ No newline at end of file diff --git "a/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Startup.cs" "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Startup.cs" new file mode 100644 index 0000000000000000000000000000000000000000..7fbda0296bd256b4497760f4c25bc9e71c3c37a3 --- /dev/null +++ "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/Startup.cs" @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Admin1000.Domain; +using Admin1000.Implementation; +using Admin1000.Interface; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; + +namespace Admin1000 +{ + 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.AddScoped(typeof(IRespository<>), typeof(EfRespository<>)); + + + services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IHostingEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseMvc(); + + + DbInitializer.Seed(); + } + } +} diff --git "a/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/appsettings.Development.json" "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/appsettings.Development.json" new file mode 100644 index 0000000000000000000000000000000000000000..e203e9407e74a6b9662aab8fde5d73ae64665f18 --- /dev/null +++ "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/appsettings.Development.json" @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + } +} diff --git "a/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/appsettings.json" "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/appsettings.json" new file mode 100644 index 0000000000000000000000000000000000000000..def9159a7d9403c04a926f64e71ef3ee7c9e4c57 --- /dev/null +++ "b/\347\250\213\345\215\232\346\226\207/Admin1000/Admin1000/appsettings.json" @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Warning" + } + }, + "AllowedHosts": "*" +}