diff --git a/src/InternshipSystem.Api/Controllers/CompaniesController.cs b/src/InternshipSystem.Api/Controllers/CompaniesController.cs index 59b99ad..9502fac 100644 --- a/src/InternshipSystem.Api/Controllers/CompaniesController.cs +++ b/src/InternshipSystem.Api/Controllers/CompaniesController.cs @@ -18,14 +18,12 @@ namespace InternshipSystem.Api.Controllers [Route("companies")] public class CompaniesController : ControllerBase { - public CompaniesController(InternshipDbContext context, InternshipPractiseSupervisorDbContext practiseSupervisorDbContext) + public CompaniesController(InternshipDbContext context) { Context = context; - PractiseSupervisorDbContext = practiseSupervisorDbContext; } private InternshipDbContext Context { get; } - private InternshipPractiseSupervisorDbContext PractiseSupervisorDbContext { get; } /// /// Get companies matching provided paginated query @@ -94,7 +92,7 @@ namespace InternshipSystem.Api.Controllers if (companyForm.Id.HasValue) { - var companyToUpdate = await PractiseSupervisorDbContext.Companies.FindAsync(companyForm.Id); + var companyToUpdate = await Context.Companies.FindAsync(companyForm.Id); if (companyToUpdate != null) { @@ -113,10 +111,10 @@ namespace InternshipSystem.Api.Controllers Name = companyForm.Name, Nip = companyForm.Nip, }; - await PractiseSupervisorDbContext.Companies.AddAsync(newCompany, cancellationToken); + await Context.Companies.AddAsync(newCompany, cancellationToken); } - await PractiseSupervisorDbContext.SaveChangesAsync(cancellationToken); + await Context.SaveChangesAsync(cancellationToken); return Ok($"Company updated successfully"); } @@ -135,7 +133,7 @@ namespace InternshipSystem.Api.Controllers [Authorize] public async Task DeleteCompany(long companyId, CancellationToken cancellationToken) { - var companyToDelete = await PractiseSupervisorDbContext.Companies + var companyToDelete = await Context.Companies .Include(c => c.Branches) .FirstOrDefaultAsync(c => c.Id.Equals(companyId), cancellationToken: cancellationToken); @@ -144,9 +142,9 @@ namespace InternshipSystem.Api.Controllers return NotFound($"Company with id: {companyId} does not exist"); } - PractiseSupervisorDbContext.Companies.Attach(companyToDelete); - PractiseSupervisorDbContext.Companies.Remove(companyToDelete); - await PractiseSupervisorDbContext.SaveChangesAsync(cancellationToken); + Context.Companies.Attach(companyToDelete); + Context.Companies.Remove(companyToDelete); + await Context.SaveChangesAsync(cancellationToken); return Ok($"Company with id: {companyId} deleted successfully"); } @@ -174,7 +172,7 @@ namespace InternshipSystem.Api.Controllers return BadRequest(validationResult.ToString()); } - var company = await PractiseSupervisorDbContext.Companies + var company = await Context.Companies .Include(c => c.Branches) .FirstOrDefaultAsync(c => c.Id.Equals(companyId), cancellationToken: cancellationToken); @@ -214,7 +212,7 @@ namespace InternshipSystem.Api.Controllers company.Branches.Add(newBranchOffice); } - await PractiseSupervisorDbContext.SaveChangesAsync(cancellationToken); + await Context.SaveChangesAsync(cancellationToken); return Ok($"Branch office updated successfully"); } @@ -234,7 +232,7 @@ namespace InternshipSystem.Api.Controllers public async Task DeleteBranch(long branchOfficeId, CancellationToken cancellationToken) { var company = - await PractiseSupervisorDbContext.Companies + await Context.Companies .Include(c => c.Branches) .Where(c => c.Branches.Any(b => b.Id.Equals(branchOfficeId))) .FirstOrDefaultAsync(cancellationToken: cancellationToken); @@ -247,7 +245,7 @@ namespace InternshipSystem.Api.Controllers var branchOffice = company.Branches.Find(b => b.Id.Equals(branchOfficeId)); company.Branches.Remove(branchOffice); - await PractiseSupervisorDbContext.SaveChangesAsync(cancellationToken); + await Context.SaveChangesAsync(cancellationToken); return Ok($"Branch office with id: {branchOfficeId} deleted successfully"); } } diff --git a/src/InternshipSystem.Api/Controllers/RegistrationController.cs b/src/InternshipSystem.Api/Controllers/RegistrationController.cs index f01080a..19a92c6 100644 --- a/src/InternshipSystem.Api/Controllers/RegistrationController.cs +++ b/src/InternshipSystem.Api/Controllers/RegistrationController.cs @@ -1,9 +1,7 @@ using System; -using System.Linq; using System.Threading; using System.Threading.Tasks; using InternshipSystem.Api.Security; -using InternshipSystem.Core; using InternshipSystem.Repository; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; @@ -22,7 +20,7 @@ namespace InternshipSystem.Api.Controllers { _context = context; } - + /// /// Register student for edition using provided registration code /// @@ -51,9 +49,8 @@ namespace InternshipSystem.Api.Controllers edition.RegisterInternship(student); await _context.SaveChangesAsync(token); - + return Ok(); } - } } \ No newline at end of file diff --git a/src/InternshipSystem.Api/Extensions/ApplicationBuilderExtensions.cs b/src/InternshipSystem.Api/Extensions/ApplicationBuilderExtensions.cs index 5dffba4..b82f2b3 100644 --- a/src/InternshipSystem.Api/Extensions/ApplicationBuilderExtensions.cs +++ b/src/InternshipSystem.Api/Extensions/ApplicationBuilderExtensions.cs @@ -17,7 +17,7 @@ namespace InternshipSystem.Api.Extensions try { using var serviceScope = app.ApplicationServices.GetRequiredService().CreateScope(); - using var context = serviceScope.ServiceProvider.GetService(); + using var context = serviceScope.ServiceProvider.GetService(); context.Database.Migrate(); @@ -35,7 +35,7 @@ namespace InternshipSystem.Api.Extensions public static IApplicationBuilder UseDefaultData(this IApplicationBuilder app, bool useDefaultData) { using var serviceScope = app.ApplicationServices.GetRequiredService().CreateScope(); - using var context = serviceScope.ServiceProvider.GetService(); + using var context = serviceScope.ServiceProvider.GetService(); var filler = serviceScope.ServiceProvider.GetService(); context.Database.Migrate(); diff --git a/src/InternshipSystem.Api/Startup.cs b/src/InternshipSystem.Api/Startup.cs index e2db791..3dfb538 100644 --- a/src/InternshipSystem.Api/Startup.cs +++ b/src/InternshipSystem.Api/Startup.cs @@ -42,8 +42,6 @@ namespace InternshipSystem.Api services .AddDbContext(o => o.UseNpgsql(Configuration.GetConnectionString("InternshipDatabase"))) - .AddDbContext(o => - o.UseNpgsql(Configuration.GetConnectionString("InternshipDatabase"))) .AddScoped() .AddScoped() .AddScoped() diff --git a/src/InternshipSystem.Repository/DatabaseFiller.cs b/src/InternshipSystem.Repository/DatabaseFiller.cs index 64b0621..be55afa 100644 --- a/src/InternshipSystem.Repository/DatabaseFiller.cs +++ b/src/InternshipSystem.Repository/DatabaseFiller.cs @@ -169,6 +169,16 @@ namespace InternshipSystem.Repository public async Task FillEditions() { + var student = new Student + { + FirstName = "Trzeci", + LastName = "Trzecikowski", + AlbumNumber = 142351, + Email = "s102137@student.pg.edu.pl", + }; + + await Context.Students.AddAsync(student); + var editions = new List { new Edition diff --git a/src/InternshipSystem.Repository/InternshipPractiseSupervisorDbContext.cs b/src/InternshipSystem.Repository/InternshipPractiseSupervisorDbContext.cs deleted file mode 100644 index d7e66bb..0000000 --- a/src/InternshipSystem.Repository/InternshipPractiseSupervisorDbContext.cs +++ /dev/null @@ -1,12 +0,0 @@ -using InternshipSystem.Core; -using Microsoft.EntityFrameworkCore; - -namespace InternshipSystem.Repository -{ - public class InternshipPractiseSupervisorDbContext : InternshipDbContext - { - public InternshipPractiseSupervisorDbContext(DbContextOptions options) : base(options) - { - } - } -} \ No newline at end of file diff --git a/src/InternshipSystem.Repository/InternshipPractiseSupervisorDbContextFactory.cs b/src/InternshipSystem.Repository/InternshipPractiseSupervisorDbContextFactory.cs deleted file mode 100644 index 57b3a2b..0000000 --- a/src/InternshipSystem.Repository/InternshipPractiseSupervisorDbContextFactory.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Design; - -namespace InternshipSystem.Repository -{ - public class InternshipPractiseSupervisorDbContextFactory : IDesignTimeDbContextFactory - { - public InternshipPractiseSupervisorDbContext CreateDbContext(string[] args) - { - var optionsBuilder = new DbContextOptionsBuilder(); - optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=postgres;Username=postgres;Password=szwoniu"); - - return new InternshipPractiseSupervisorDbContext(optionsBuilder.Options); - } - } -} \ No newline at end of file diff --git a/src/InternshipSystem.Repository/Migrations/20200923103350_init.Designer.cs b/src/InternshipSystem.Repository/Migrations/20200927114840_init.Designer.cs similarity index 99% rename from src/InternshipSystem.Repository/Migrations/20200923103350_init.Designer.cs rename to src/InternshipSystem.Repository/Migrations/20200927114840_init.Designer.cs index fddfc9e..79cf8f6 100644 --- a/src/InternshipSystem.Repository/Migrations/20200923103350_init.Designer.cs +++ b/src/InternshipSystem.Repository/Migrations/20200927114840_init.Designer.cs @@ -9,8 +9,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace InternshipSystem.Repository.Migrations { - [DbContext(typeof(InternshipPractiseSupervisorDbContext))] - [Migration("20200923103350_init")] + [DbContext(typeof(InternshipDbContext))] + [Migration("20200927114840_init")] partial class init { protected override void BuildTargetModel(ModelBuilder modelBuilder) diff --git a/src/InternshipSystem.Repository/Migrations/20200923103350_init.cs b/src/InternshipSystem.Repository/Migrations/20200927114840_init.cs similarity index 100% rename from src/InternshipSystem.Repository/Migrations/20200923103350_init.cs rename to src/InternshipSystem.Repository/Migrations/20200927114840_init.cs diff --git a/src/InternshipSystem.Repository/Migrations/InternshipPractiseSupervisorDbContextModelSnapshot.cs b/src/InternshipSystem.Repository/Migrations/InternshipDbContextModelSnapshot.cs similarity index 99% rename from src/InternshipSystem.Repository/Migrations/InternshipPractiseSupervisorDbContextModelSnapshot.cs rename to src/InternshipSystem.Repository/Migrations/InternshipDbContextModelSnapshot.cs index c99d560..529a966 100644 --- a/src/InternshipSystem.Repository/Migrations/InternshipPractiseSupervisorDbContextModelSnapshot.cs +++ b/src/InternshipSystem.Repository/Migrations/InternshipDbContextModelSnapshot.cs @@ -8,8 +8,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace InternshipSystem.Repository.Migrations { - [DbContext(typeof(InternshipPractiseSupervisorDbContext))] - partial class InternshipPractiseSupervisorDbContextModelSnapshot : ModelSnapshot + [DbContext(typeof(InternshipDbContext))] + partial class InternshipDbContextModelSnapshot : ModelSnapshot { protected override void BuildModel(ModelBuilder modelBuilder) {