added (unused) database stuffs

This commit is contained in:
Shuozhe 2021-06-04 01:53:27 +02:00
parent c359776a22
commit 39ca7cba3b
10 changed files with 42 additions and 9 deletions

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace vue_dotnet_example.Controllers
namespace ProjectGrid.Controllers
{
[ApiController]
public class UsersController : ControllerBase

View File

@ -0,0 +1,21 @@
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using ProjectGrid.Models;
namespace ProjectGrid.Data
{
class DataAccessContex : DbContext
{
public DataAccessContex(DbContextOptions<DataAccessContex> options) { }
public DbSet<UserModel> Users;
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<UserModel>().ToTable("[USER]");
}
}
}

View File

@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
namespace vue_dotnet_example.Models
namespace ProjectGrid.Models
{
public interface IUserRepository
{

View File

@ -1,4 +1,4 @@
namespace vue_dotnet_example.Models
namespace ProjectGrid.Models
{
public class UserModel
{

View File

@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
namespace vue_dotnet_example.Models
namespace ProjectGrid.Models
{
public class UserRepository: IUserRepository
{

View File

@ -7,7 +7,7 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace vue_dotnet_example
namespace ProjectGrid
{
public class Program
{

View File

@ -8,6 +8,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="5.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.6" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
</ItemGroup>

View File

@ -17,7 +17,7 @@
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"vue_dotnet_example": {
"ProjectGrid": {
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": true,

View File

@ -11,8 +11,10 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
using Microsoft.EntityFrameworkCore;
using ProjectGrid.Data;
namespace vue_dotnet_example
namespace ProjectGrid
{
public class Startup
{
@ -27,10 +29,15 @@ namespace vue_dotnet_example
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<DataAccessContex>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
// TODO: for Testing
services.AddDatabaseDeveloperPageExceptionFilter();
services.AddControllers();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "vue_dotnet_example", Version = "v1" });
c.SwaggerDoc("v1", new OpenApiInfo { Title = "ProjectGrid", Version = "v1" });
});
}
@ -41,7 +48,7 @@ namespace vue_dotnet_example
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "vue_dotnet_example v1"));
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "ProjectGrid v1"));
}
app.UseHttpsRedirection();

View File

@ -1,4 +1,7 @@
{
"ConnectionStrings": {
"DefaultConnection": "Server=hello-world.games;Database=ProjectGrid;Driver=SQL Server;uid=net;pwd=15123456"
},
"Logging": {
"LogLevel": {
"Default": "Information",