diff --git a/Selector.Model/Selector.Model.csproj b/Selector.Model/Selector.Model.csproj index b71519e..cb4910c 100644 --- a/Selector.Model/Selector.Model.csproj +++ b/Selector.Model/Selector.Model.csproj @@ -1,7 +1,7 @@ - netstandard2.1 + net5.0 true latest @@ -12,7 +12,13 @@ + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + diff --git a/Selector.Model/SelectorContext.cs b/Selector.Model/SelectorContext.cs new file mode 100644 index 0000000..d92e0ad --- /dev/null +++ b/Selector.Model/SelectorContext.cs @@ -0,0 +1,45 @@ + +using System; +using System.IO; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Design; +using Microsoft.Extensions.Configuration; + +namespace Selector.Model +{ + + public class SelectorContext : DbContext + { + public DbSet Watcher { get; set; } + + public SelectorContext(DbContextOptions options) : base(options) + { + + } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + } + } + + public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory + { + public SelectorContext CreateDbContext(string[] args) + { + IConfigurationRoot configuration = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile(@Directory.GetCurrentDirectory() + "/../Selector.Web/appsettings.Development.json") + .Build(); + + var builder = new DbContextOptionsBuilder(); + builder.UseNpgsql(configuration.GetConnectionString("Default")); + + return new SelectorContext(builder.Options); + } + } +} \ No newline at end of file diff --git a/Selector.Model/Watcher.cs b/Selector.Model/Watcher.cs index a5054aa..4bf03dd 100644 --- a/Selector.Model/Watcher.cs +++ b/Selector.Model/Watcher.cs @@ -1,9 +1,11 @@ using System; +using System.ComponentModel.DataAnnotations; +using Microsoft.EntityFrameworkCore; namespace Selector.Model { public class Watcher { - + public int Id { get; set; } } } \ No newline at end of file diff --git a/Selector.Web/Controller/TestController.cs b/Selector.Web/Controller/TestController.cs index 71a2268..fa9e6a0 100644 --- a/Selector.Web/Controller/TestController.cs +++ b/Selector.Web/Controller/TestController.cs @@ -1,5 +1,10 @@ using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Selector.Model; namespace Selector.Web.Controller { @@ -7,10 +12,18 @@ namespace Selector.Web.Controller { [Route("api/[controller]")] public class TestController { - [HttpGet] - public ActionResult Get() + private readonly SelectorContext db; + + public TestController(SelectorContext context) { - return "Hello World!"; + db = context; + } + + [HttpGet] + public async Task>> Get() + { + // var watchers = ; + return await db.Watcher.ToListAsync(); } } } \ No newline at end of file diff --git a/Selector.Web/Pages/Index.cshtml b/Selector.Web/Pages/Index.cshtml index b5f0c15..388b71f 100644 --- a/Selector.Web/Pages/Index.cshtml +++ b/Selector.Web/Pages/Index.cshtml @@ -8,3 +8,7 @@

Welcome

Learn about building Web apps with ASP.NET Core.

+ +@section Scripts { + +} \ No newline at end of file diff --git a/Selector.Web/Pages/Shared/_Layout.cshtml b/Selector.Web/Pages/Shared/_Layout.cshtml index daeaa43..0b80af1 100644 --- a/Selector.Web/Pages/Shared/_Layout.cshtml +++ b/Selector.Web/Pages/Shared/_Layout.cshtml @@ -4,7 +4,7 @@ @ViewData["Title"] - Selector - +
@@ -40,8 +40,6 @@ - - @await RenderSectionAsync("Scripts", required: false) diff --git a/Selector.Web/Program.cs b/Selector.Web/Program.cs index 2737617..3cc641e 100644 --- a/Selector.Web/Program.cs +++ b/Selector.Web/Program.cs @@ -7,6 +7,8 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; + namespace Selector.Web { public class Program @@ -21,6 +23,11 @@ namespace Selector.Web .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); + }) + .ConfigureLogging((context, builder) => { + builder.ClearProviders(); + builder.SetMinimumLevel(LogLevel.Trace); + builder.AddNLog(context.Configuration); }); } } diff --git a/Selector.Web/Selector.Web.csproj b/Selector.Web/Selector.Web.csproj index c676c98..029b3a1 100644 --- a/Selector.Web/Selector.Web.csproj +++ b/Selector.Web/Selector.Web.csproj @@ -12,16 +12,33 @@ + + all runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + diff --git a/Selector.Web/Startup.cs b/Selector.Web/Startup.cs index 70b3923..ba9401b 100644 --- a/Selector.Web/Startup.cs +++ b/Selector.Web/Startup.cs @@ -9,6 +9,10 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Microsoft.EntityFrameworkCore; + +using Selector.Model; + namespace Selector.Web { public class Startup @@ -23,8 +27,12 @@ namespace Selector.Web // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - services.AddRazorPages(); + services.AddRazorPages().AddRazorRuntimeCompilation(); services.AddControllers(); + + services.AddDbContext(options => + options.UseNpgsql(Configuration.GetConnectionString("Default")) + ); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. diff --git a/Selector.Web/nlog.config b/Selector.Web/nlog.config new file mode 100644 index 0000000..bf69176 --- /dev/null +++ b/Selector.Web/nlog.config @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Selector.Web/webpack.common.js b/Selector.Web/webpack.common.js index 4d0f953..861eb74 100644 --- a/Selector.Web/webpack.common.js +++ b/Selector.Web/webpack.common.js @@ -3,7 +3,7 @@ const { CleanWebpackPlugin } = require('clean-webpack-plugin'); module.exports = { entry: { - app: './scripts/index.ts', + index: './scripts/index.ts', }, module: { rules: [