diff --git a/.gitignore b/.gitignore index b8f84db..b866a75 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,6 @@ obj .vscode .DS_Store *.db +*appsettings.JSON wwwroot publish \ No newline at end of file diff --git a/Controllers/ValuesController.cs b/Controllers/ValuesController.cs new file mode 100644 index 0000000..c4287c5 --- /dev/null +++ b/Controllers/ValuesController.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using TestApplication.Data; +using TestApplication.Models; + +namespace TestApplication.Controllers +{ + [ApiController] + [Route("[controller]")] + public class ValuesController : ControllerBase + { + private readonly Context _context; + public ValuesController(Context context) + { + _context = context; + } + + [HttpGet] + public async Task>> GetValues() + { + return await _context.Values.ToListAsync(); + } + } +} \ No newline at end of file diff --git a/Data/Context.cs b/Data/Context.cs new file mode 100644 index 0000000..b538cbe --- /dev/null +++ b/Data/Context.cs @@ -0,0 +1,11 @@ +using Microsoft.EntityFrameworkCore; +using TestApplication.Models; + +namespace TestApplication.Data +{ + public class Context : DbContext + { + public Context(DbContextOptions options) : base(options) {} + public DbSet Values {get; set;} + } +} \ No newline at end of file diff --git a/Models/Values.cs b/Models/Values.cs new file mode 100644 index 0000000..ff90972 --- /dev/null +++ b/Models/Values.cs @@ -0,0 +1,11 @@ +using System.ComponentModel.DataAnnotations; + +namespace TestApplication.Models +{ + public class Values + { + [Key] + public int Id { get; set; } + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/Startup.cs b/Startup.cs index ea227a7..a95811d 100644 --- a/Startup.cs +++ b/Startup.cs @@ -1,15 +1,10 @@ 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.Hosting; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using TestApplication.Data; namespace TestApplication { @@ -26,6 +21,10 @@ namespace TestApplication public void ConfigureServices(IServiceCollection services) { services.AddControllers(); + services.AddDbContext(opt => + { + opt.UseMySql(Configuration.GetConnectionString("DefaultConnection")); + }); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. diff --git a/TestApplication.csproj b/TestApplication.csproj index d12c450..5f0d390 100644 --- a/TestApplication.csproj +++ b/TestApplication.csproj @@ -1,8 +1,9 @@ - netcoreapp3.1 - - - + + + + + \ No newline at end of file diff --git a/appsettings.json b/appsettings.json deleted file mode 100644 index d9d9a9b..0000000 --- a/appsettings.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" - } - }, - "AllowedHosts": "*" -}