Setup ef core tools and sqlite database with some entities
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -11,8 +11,9 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MediatR" Version="6.0.0" />
|
||||
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="6.0.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.All" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using BrightGlimmer.Cqrs.Queries;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
|
||||
59
BrightGlimmer.Api/Controllers/StudentController.cs
Normal file
59
BrightGlimmer.Api/Controllers/StudentController.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using BrightGlimmer.Data.Repositories; /* REMOVE LATER */
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace BrightGlimmer.Api.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class StudentController : ControllerBase
|
||||
{
|
||||
// private readonly IMediator mediator;
|
||||
private readonly StudentRepository studentRepository;
|
||||
|
||||
public StudentController(StudentRepository studentRepository)
|
||||
{
|
||||
this.studentRepository = studentRepository;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult GetAll()
|
||||
{
|
||||
var customers = studentRepository.GetAll();
|
||||
if (customers == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
return new ObjectResult(customers);
|
||||
}
|
||||
|
||||
[HttpGet("createstudent")]
|
||||
public IActionResult CreateStudent()
|
||||
{
|
||||
var created = studentRepository.Create(new Data.Domain.Student
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
FirstName = "Giovani",
|
||||
LastName = "Rodriguez",
|
||||
Email = "giovaniluisrodriguez@gmail.com",
|
||||
Phones = new List<Data.Domain.Phone>
|
||||
{
|
||||
new Data.Domain.Phone
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
AreaCode = 305,
|
||||
Number = 8888888,
|
||||
Type = Data.Domain.PhoneType.HOMEPHONE
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return new ObjectResult(created);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "api/values",
|
||||
"launchUrl": "",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
@@ -20,7 +20,7 @@
|
||||
"BrightGlimmer.Api": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "api/values",
|
||||
"launchUrl": "",
|
||||
"applicationUrl": "https://localhost:5001;http://localhost:5000",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
|
||||
@@ -3,11 +3,13 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using BrightGlimmer.Data;
|
||||
using BrightGlimmer.Data.Repositories; /* REMOVE LATER */
|
||||
using MediatR;
|
||||
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;
|
||||
@@ -30,6 +32,9 @@ namespace BrightGlimmer.Api
|
||||
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
|
||||
services.AddMediatR();
|
||||
services.AddMediatR(typeof(Cqrs.Cqrs).Assembly); // Registers handlers in Cqrs project
|
||||
services.AddScoped<StudentRepository, StudentRepository>(); /* REMOVE LATER */
|
||||
services.AddDbContext<SqliteDatabaseContext>(options => options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));
|
||||
services.AddTransient<SqliteDatabaseContext>();
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
@@ -46,6 +51,13 @@ namespace BrightGlimmer.Api
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseMvc();
|
||||
|
||||
// Makes sure that the database is in fact created
|
||||
using (var serviceScope = app.ApplicationServices.GetService<IServiceScopeFactory>().CreateScope())
|
||||
{
|
||||
var context = serviceScope.ServiceProvider.GetRequiredService<SqliteDatabaseContext>();
|
||||
context.Database.EnsureCreated();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,20 @@
|
||||
{
|
||||
"Logging": {
|
||||
"IncludeScopes": false,
|
||||
"LogLevel": {
|
||||
"Default": "Warning"
|
||||
"Default": "Debug",
|
||||
"System": "Information",
|
||||
"Microsoft": "Information"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Filename=../BrightGlimmer.Data/bright_glimmer.db"
|
||||
},
|
||||
"amqp": {
|
||||
"username": "guest",
|
||||
"password": "guest",
|
||||
"hostname": "localhost",
|
||||
"uri": "amqp://localhost:5672/",
|
||||
"virtualhost": "/"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user