diff --git a/LaDOSE.Src/LaDOSE.Api/Context/LaDOSEDbContext.cs b/LaDOSE.Src/LaDOSE.Api/Context/LaDOSEDbContext.cs new file mode 100644 index 0000000..2540afe --- /dev/null +++ b/LaDOSE.Src/LaDOSE.Api/Context/LaDOSEDbContext.cs @@ -0,0 +1,20 @@ + +using System; +using LaDOSE.Entity; +using Microsoft.EntityFrameworkCore; +namespace LaDOSE.Api.Context +{ + public class LaDOSEDbContext : DbContext + { + public DbSet Game { get; set; } + + public LaDOSEDbContext(DbContextOptions options) : base(options) + { + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + } + } +} \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/ValuesController.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/ValuesController.cs index 3d3c939..667bd81 100644 --- a/LaDOSE.Src/LaDOSE.Api/Controllers/ValuesController.cs +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/ValuesController.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using LaDOSE.Api.Context; +using LaDOSE.Entity; using Microsoft.AspNetCore.Mvc; namespace LaDOSE.Api.Controllers @@ -10,11 +12,20 @@ namespace LaDOSE.Api.Controllers [ApiController] public class ConfigController : ControllerBase { + + private readonly LaDOSEDbContext _db; + + public ConfigController(LaDOSEDbContext db) + { + _db = db; + } // GET api/Config [HttpGet] - public ActionResult> Get() + public ActionResult> Get() { - return new string[] { "value1", "value2" }; + + return _db.Game.ToList(); + } // GET api/Config/5 diff --git a/LaDOSE.Src/LaDOSE.Api/LaDOSE.Api.csproj b/LaDOSE.Src/LaDOSE.Api/LaDOSE.Api.csproj index 710a1eb..15e1856 100644 --- a/LaDOSE.Src/LaDOSE.Api/LaDOSE.Api.csproj +++ b/LaDOSE.Src/LaDOSE.Api/LaDOSE.Api.csproj @@ -10,6 +10,11 @@ + + + + + diff --git a/LaDOSE.Src/LaDOSE.Api/Startup.cs b/LaDOSE.Src/LaDOSE.Api/Startup.cs index 1c01cd9..6c289a5 100644 --- a/LaDOSE.Src/LaDOSE.Api/Startup.cs +++ b/LaDOSE.Src/LaDOSE.Api/Startup.cs @@ -2,14 +2,18 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using LaDOSE.Api.Context; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using Pomelo.EntityFrameworkCore.MySql; +using Pomelo.EntityFrameworkCore.MySql.Infrastructure; namespace LaDOSE.Api { @@ -26,7 +30,16 @@ namespace LaDOSE.Api public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); + services.AddDbContextPool( // replace "YourDbContext" with the class name of your DbContext + options => options.UseMySql("Server=localhost;Database=ladose;User=root;Password=;", // replace with your Connection String + mysqlOptions => + { + mysqlOptions.ServerVersion(new Version(10, 1, 16), ServerType.MariaDb); // replace with your Server Version and Type + } + )); } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) diff --git a/LaDOSE.Src/LaDOSE.Entity/Game.cs b/LaDOSE.Src/LaDOSE.Entity/Game.cs new file mode 100644 index 0000000..d3f0021 --- /dev/null +++ b/LaDOSE.Src/LaDOSE.Entity/Game.cs @@ -0,0 +1,11 @@ +using System; + +namespace LaDOSE.Entity +{ + public class Game + { + public int Id { get; set; } + public string Name { get; set; } + public string ImgUrl { get; set; } + } +} diff --git a/LaDOSE.Src/LaDOSE.Entity/LaDOSE.Entity.csproj b/LaDOSE.Src/LaDOSE.Entity/LaDOSE.Entity.csproj new file mode 100644 index 0000000..86ea3bb --- /dev/null +++ b/LaDOSE.Src/LaDOSE.Entity/LaDOSE.Entity.csproj @@ -0,0 +1,7 @@ + + + + netcoreapp2.1 + + + diff --git a/LaDOSE.Src/LaDOSE.sln b/LaDOSE.Src/LaDOSE.sln index 65cc72c..728de3e 100644 --- a/LaDOSE.Src/LaDOSE.sln +++ b/LaDOSE.Src/LaDOSE.sln @@ -5,7 +5,9 @@ VisualStudioVersion = 15.0.28010.2041 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LaDOSE.DiscordBot", "LaDOSE.DiscordBot\LaDOSE.DiscordBot.csproj", "{C1E8FAF6-3A75-44AC-938D-CA56A5322D1C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaDOSE.Api", "LaDOSE.Api\LaDOSE.Api.csproj", "{4D7ED4CC-F78F-4860-B8CE-DA01DCACCBB9}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LaDOSE.Api", "LaDOSE.Api\LaDOSE.Api.csproj", "{4D7ED4CC-F78F-4860-B8CE-DA01DCACCBB9}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaDOSE.Entity", "LaDOSE.Entity\LaDOSE.Entity.csproj", "{B32A4AD5-9A4B-4D12-AAD5-55541F170E2A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -21,6 +23,10 @@ Global {4D7ED4CC-F78F-4860-B8CE-DA01DCACCBB9}.Debug|Any CPU.Build.0 = Debug|Any CPU {4D7ED4CC-F78F-4860-B8CE-DA01DCACCBB9}.Release|Any CPU.ActiveCfg = Release|Any CPU {4D7ED4CC-F78F-4860-B8CE-DA01DCACCBB9}.Release|Any CPU.Build.0 = Release|Any CPU + {B32A4AD5-9A4B-4D12-AAD5-55541F170E2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B32A4AD5-9A4B-4D12-AAD5-55541F170E2A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B32A4AD5-9A4B-4D12-AAD5-55541F170E2A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B32A4AD5-9A4B-4D12-AAD5-55541F170E2A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE