From a07d5f11ddd64e9596b403b2b44a0520249a79df Mon Sep 17 00:00:00 2001 From: mborzyszkowski Date: Wed, 29 Jul 2020 19:38:39 +0200 Subject: [PATCH 1/2] Rewrite --- .../Controllers/AdminController.cs | 120 +-- src/InternshipSystem.Api/Startup.cs | 2 +- .../DatabaseFiller.cs | 720 ++++++++++-------- .../Model/CompanyReadModel.cs | 4 +- 4 files changed, 454 insertions(+), 392 deletions(-) diff --git a/src/InternshipSystem.Api/Controllers/AdminController.cs b/src/InternshipSystem.Api/Controllers/AdminController.cs index bf7e2e5..f3ed409 100644 --- a/src/InternshipSystem.Api/Controllers/AdminController.cs +++ b/src/InternshipSystem.Api/Controllers/AdminController.cs @@ -1,60 +1,60 @@ -// using System.Threading.Tasks; -// using InternshipSystem.Repository; -// using Microsoft.AspNetCore.Mvc; -// -// namespace Internship.Api.Controller -// { -// [ApiController] -// [Route("admin")] -// public class AdminController : ControllerBase -// { -// public AdminController(DatabaseFiller fillerService) -// { -// FillerService = fillerService; -// } -// -// public DatabaseFiller FillerService { get; } -// -// -// [HttpPost("fill")] -// public async Task Fill() { -// await FillerService.FillCompany(); -// await FillerService.FillInterns(); -// await FillerService.FillInternshipTypes(); -// await FillerService.FillEditions(); -// await FillerService.FillInternShips(); -// return Ok(); -// } -// -// [HttpPost("fill/companies")] -// public async Task FillCompaniesAsync() -// { -// await FillerService.FillCompany(); -// return Ok(); -// } -// -// [HttpPost("fill/interns")] -// public async Task FillInternsAsync() { -// await FillerService.FillInterns(); -// return Ok(); -// } -// -// [HttpPost("fill/internshiptypes")] -// public async Task FillInternshipTypesAsync() { -// await FillerService.FillInternshipTypes(); -// return Ok(); -// } -// -// [HttpPost("fill/editions")] -// public async Task FillEditionsAsync() { -// await FillerService.FillEditions(); -// return Ok(); -// } -// -// [HttpPost("fill/internships")] -// public async Task FillInternShipsAsync() { -// await FillerService.FillInternShips(); -// return Ok(); -// } -// } -// } \ No newline at end of file +using System.Threading.Tasks; +using InternshipSystem.Repository; +using Microsoft.AspNetCore.Mvc; + +namespace InternshipSystem.Api.Controllers +{ + [ApiController] + [Route("admin")] + public class AdminController : ControllerBase + { + public AdminController(DatabaseFiller fillerService) + { + FillerService = fillerService; + } + + public DatabaseFiller FillerService { get; } + + + [HttpPost("fill")] + public async Task Fill() { + await FillerService.FillCompany(); + await FillerService.FillStudents(); + await FillerService.FillInternshipTypes(); + await FillerService.FillEditions(); + await FillerService.FillInternShips(); + return Ok(); + } + + [HttpPost("fill/companies")] + public async Task FillCompaniesAsync() + { + await FillerService.FillCompany(); + return Ok(); + } + + [HttpPost("fill/students")] + public async Task FillStudentsAsync() { + await FillerService.FillStudents(); + return Ok(); + } + + [HttpPost("fill/internshiptypes")] + public async Task FillInternshipTypesAsync() { + await FillerService.FillInternshipTypes(); + return Ok(); + } + + [HttpPost("fill/editions")] + public async Task FillEditionsAsync() { + await FillerService.FillEditions(); + return Ok(); + } + + [HttpPost("fill/internships")] + public async Task FillInternShipsAsync() { + await FillerService.FillInternShips(); + return Ok(); + } + } +} \ No newline at end of file diff --git a/src/InternshipSystem.Api/Startup.cs b/src/InternshipSystem.Api/Startup.cs index 71e2992..aa5f0c8 100644 --- a/src/InternshipSystem.Api/Startup.cs +++ b/src/InternshipSystem.Api/Startup.cs @@ -29,7 +29,7 @@ namespace InternshipSystem.Api var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); options.IncludeXmlComments(xmlPath); }) - // .AddScoped() + .AddScoped() .AddControllers() ; diff --git a/src/InternshipSystem.Repository/DatabaseFiller.cs b/src/InternshipSystem.Repository/DatabaseFiller.cs index 2ff9d4e..65f1f52 100644 --- a/src/InternshipSystem.Repository/DatabaseFiller.cs +++ b/src/InternshipSystem.Repository/DatabaseFiller.cs @@ -1,330 +1,390 @@ -// using System; -// using System.Collections.Generic; -// using System.Linq; -// using System.Threading.Tasks; -// using InternshipSystem.Core; -// -// namespace InternshipSystem.Repository -// { -// public class DatabaseFiller -// { -// public DatabaseFiller(InternshipDbContext context) -// { -// Context = context; -// } -// -// public InternshipDbContext Context { get; } -// -// public async Task FillCompany() -// { -// var companies = new List -// { -// new Company -// { -// Name = "Intel", -// SiteAddress = new Uri("https://www.intel.com/content/www/us/en/jobs/locations/poland.html"), -// Nip = "9570752316", -// Range = RangeOfActivities.International, -// Branches = new List -// { -// new BranchOffice -// { -// Address = new Address -// { -// City = "Gdańsk", -// Street = "ul. Słowackiego", -// Building = "173", -// PostalCode = "80-298", -// Country = "Poland" -// } -// }, -// new BranchOffice -// { -// Address = new Address -// { -// City = "Gdańsk", -// Street = "Jana z Kolna", -// Building = "11", -// PostalCode = "80-001", -// Country = "Poland" -// } -// }, -// new BranchOffice -// { -// Address = new Address -// { -// City = "Boston", -// Street = "State St", -// Building = "53", -// PostalCode = "MA 02109", -// Country = "Stany Zjednoczone" -// } -// } -// } -// }, -// new Company -// { -// Name = "Asseco Poland", -// SiteAddress = new Uri("http://pl.asseco.com"), -// Nip = "5842068320", -// Range = RangeOfActivities.National, -// Branches = new List -// { -// new BranchOffice -// { -// Address = new Address -// { -// City = "Gdańsk", -// Street = "ul. Podolska", -// Building = "21", -// PostalCode = "81-321", -// Country = "Poland" -// } -// }, -// new BranchOffice -// { -// Address = new Address -// { -// City = "Wrocław", -// Street = "Traugutta", -// Building = "1/7", -// PostalCode = "50-449", -// Country = "Poland" -// } -// } -// } -// } -// }; -// Context.Companies.AddRange(companies); -// await Context.SaveChangesAsync(); -// } -// -// public async Task FillInterns() -// { -// var interns = new List -// { -// new Intern { -// Name = "Jan", -// Surname = "Kowalski", -// AlbumNumber = "123456", -// Email = "s123456@student.pg.edu.pl", -// Semester = 4, -// Course = new Course -// { -// Name = "Informatyka", -// DesiredSemesters = new List { 4, 6 }, -// ProgramEntries = new List -// { -// new InternshipProgramEntry -// { -// Description = "Instalacja, konfiguracja i administracja niewielkich sieci komputerowych, w tym bezprzewodowych." -// }, -// new InternshipProgramEntry -// { -// Description = "Implementacja polityki bezpieczeństwa informacji w firmie lub instytucji, instalacja ochrony antywirusowej, konfiguracja zapór ogniowych." -// }, -// new InternshipProgramEntry -// { -// Description = "Instalacja, konfiguracja i administracja oprogramowania, w szczególnościsystemów operacyjnychiserwerów aplikacji." -// }, -// new InternshipProgramEntry -// { -// Description = "Projektowanie, implementacja i modyfikacjeoprogramowaniaw różnych technologiach i dla różnych zastosowań." -// } -// } -// } -// }, -// new Intern { -// Name = "Adam", -// Surname = "Kołek", -// AlbumNumber = "102137", -// Email = "s102137@student.pg.edu.pl", -// Semester = 6, -// Course = new Course -// { -// Name = "Robotyka", -// DesiredSemesters = new List { 6 }, -// ProgramEntries = new List -// { -// new InternshipProgramEntry -// { -// Description = "Testowanie oprogramowania, także z wykorzystaniem narzędzi do testowania automatycznego." -// }, -// new InternshipProgramEntry -// { -// Description = "Wykorzystanie otwartych komponentów programowych z uwzględnieniem prawnych zależności pomiędzy nimi a produktem wynikowym." -// }, -// new InternshipProgramEntry -// { -// Description = "Projektowanie i implementacja baz danych oraz badanie ich wydajności." -// }, -// new InternshipProgramEntry -// { -// Description = "Projektowanie i prototypowaniezaawansowanychinterfejsów użytkownika." -// } -// } -// } -// } -// }; -// Context.Interns.AddRange(interns); -// await Context.SaveChangesAsync(); -// } -// -// public async Task FillInternshipTypes() { -// var internshipTypes = new List -// { -// new InternshipType -// { -// Type = "FreeInternship", -// Description = "Praktyka bezpłatna", -// }, -// new InternshipType -// { -// Type = "GraduateInternship" -// }, -// new InternshipType -// { -// Type = "FreeApprenticeship" -// }, -// new InternshipType -// { -// Type = "PaidApprenticeship", -// Description = "np. przemysłowy" -// }, -// new InternshipType -// { -// Type = "ForeignInternship", -// Description = "np. IAESTE, ERASMUS" -// }, -// new InternshipType -// { -// Type = "UOP" -// }, -// new InternshipType -// { -// Type = "UD" -// }, -// new InternshipType -// { -// Type = "UZ" -// }, -// new InternshipType -// { -// Type = "Other", -// Description = "Należy wprowadzić samodzielnie" -// } -// }; -// Context.InternshipTypes.AddRange(internshipTypes); -// await Context.SaveChangesAsync(); -// } -// -// public async Task FillEditions() { -// var editions = new List -// { -// new Edition -// { -// StartDate = new DateTime(2000, 5, 10), -// EndDate = new DateTime(2000, 11, 10), -// IPPDeadlineDate = new DateTime(2000, 9, 30), -// Subjects = new List -// { -// Context.InternshipProgramEntries -// .Where(i => i.Description == "Instalacja, konfiguracja i administracja niewielkich sieci komputerowych, w tym bezprzewodowych.") -// .First(), -// Context.InternshipProgramEntries -// .Where(i => i.Description == "Projektowanie, implementacja i modyfikacjeoprogramowaniaw różnych technologiach i dla różnych zastosowań.") -// .First() -// } -// } -// }; -// Context.Editions.AddRange(editions); -// await Context.SaveChangesAsync(); -// } -// -// public async Task FillInternShips() { -// var edition = Context.Editions.First(); -// -// var intenrships = new List -// { -// new Internship -// { -// Intern = Context.Interns.Where(i => i.AlbumNumber == "123456").First(), -// Edition = edition, -// BranchOffice = -// Context.Companies -// .Where(c => c.Nip == "9570752316") //Intel -// .First() -// .Branches -// .First(), -// Type = Context.InternshipTypes.Where(t => t.Type == "UOP").First(), -// StartDate = new DateTime(2000, 7, 1), -// EndDate = new DateTime(2000, 8, 30), -// IsAccepted = false, -// DeanAcceptance = new DeanAcceptance -// { -// AcceptanceDate = new DateTime(2000, 6, 26), -// IsDeansAcceptanceRequired = true, -// Reason = DeanAcceptanceReason.Semester -// }, -// Insurance = new Insurance -// { -// InsuranceDeliveryDate = new DateTime(2000, 6, 29), -// IsInsuranceRequired = true -// }, -// LengthInWeeks = 9, -// Grade = 0, -// Program = new List -// { -// edition.Subjects.First() -// }, -// Mentor = new Mentor -// { -// Name = "Horacy", -// Surname = "Wościcki", -// Email = "howos@intel.com", -// Phone = "605-555-555" -// } -// }, -// new Internship -// { -// Intern = Context.Interns.Where(i => i.AlbumNumber == "102137").First(), -// Edition = edition, -// BranchOffice = -// Context.Companies -// .Where(c => c.Nip == "5842068320") //Asseco -// .First() -// .Branches -// .First(), -// Type = Context.InternshipTypes.Where(t => t.Type == "UZ").First(), -// StartDate = new DateTime(2000, 7, 1), -// EndDate = new DateTime(2000, 8, 30), -// IsAccepted = false, -// DeanAcceptance = new DeanAcceptance -// { -// IsDeansAcceptanceRequired = false -// }, -// Insurance = new Insurance -// { -// InsuranceDeliveryDate = new DateTime(2000, 6, 29), -// IsInsuranceRequired = true -// }, -// LengthInWeeks = 9, -// Grade = 0, -// Program = new List -// { -// edition.Subjects.First() -// }, -// Mentor = new Mentor -// { -// Name = "Horacy", -// Surname = "Wościcki", -// Email = "howos@intel.com", -// Phone = "605-555-555" -// } -// } -// }; -// Context.Internships.AddRange(intenrships); -// await Context.SaveChangesAsync(); -// } -// } -// } \ No newline at end of file +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Threading.Tasks; +using InternshipSystem.Core; +using InternshipSystem.Repository.Model; + +namespace InternshipSystem.Repository +{ + public class DatabaseFiller + { + public DatabaseFiller(InternshipDbContext context) + { + Context = context; + } + + public InternshipDbContext Context { get; } + + public async Task FillCompany() + { + var companies = new List + { + new CompanyReadModel + { + Name = "Intel", + SiteAddress = new Uri("https://www.intel.com/content/www/us/en/jobs/locations/poland.html"), + Nip = "9570752316", + Range = RangeOfActivity.International, + Branches = new List + { + new BranchOfficeReadModel + { + City = "Gdańsk", + Street = "ul. Słowackiego", + Building = "173", + PostalCode = "80-298", + Country = "Poland", + }, + new BranchOfficeReadModel + { + City = "Gdańsk", + Street = "Jana z Kolna", + Building = "11", + PostalCode = "80-001", + Country = "Poland", + }, + new BranchOfficeReadModel + { + City = "Boston", + Street = "State St", + Building = "53", + PostalCode = "MA 02109", + Country = "Stany Zjednoczone", + } + } + }, + new CompanyReadModel + { + Name = "Asseco Poland", + SiteAddress = new Uri("http://pl.asseco.com"), + Nip = "5842068320", + Range = RangeOfActivity.National, + Branches = new List + { + new BranchOfficeReadModel + { + City = "Gdańsk", + Street = "ul. Podolska", + Building = "21", + PostalCode = "81-321", + Country = "Poland" + }, + new BranchOfficeReadModel + { + City = "Wrocław", + Street = "Traugutta", + Building = "1/7", + PostalCode = "50-449", + Country = "Poland" + } + } + } + }; + await Context.Companies.AddRangeAsync(companies); + await Context.SaveChangesAsync(); + } + + public async Task FillStudents() + { + var interns = new List + { + new Student { + FirstName = "Jan", + LastName = "Kowalski", + AlbumNumber = 123456, + Email = "s123456@student.pg.edu.pl", + Semester = 4, + }, + new Student { + FirstName = "Adam", + LastName = "Kołek", + AlbumNumber = 102137, + Email = "s102137@student.pg.edu.pl", + Semester = 6, + } + }; + await Context.Students.AddRangeAsync(interns); + await Context.SaveChangesAsync(); + } + + public async Task FillInternshipTypes() { + var internshipTypes = new List + { + new InternshipTypeReadModel + { + Type = "FreeInternship", + Description = "Praktyka bezpłatna", + }, + new InternshipTypeReadModel + { + Type = "GraduateInternship" + }, + new InternshipTypeReadModel + { + Type = "FreeApprenticeship" + }, + new InternshipTypeReadModel + { + Type = "PaidApprenticeship", + Description = "np. przemysłowy" + }, + new InternshipTypeReadModel + { + Type = "ForeignInternship", + Description = "np. IAESTE, ERASMUS" + }, + new InternshipTypeReadModel + { + Type = "UOP" + }, + new InternshipTypeReadModel + { + Type = "UD" + }, + new InternshipTypeReadModel + { + Type = "UZ" + }, + new InternshipTypeReadModel + { + Type = "Other", + Description = "Należy wprowadzić samodzielnie" + } + }; + await Context.InternshipTypes.AddRangeAsync(internshipTypes); + await Context.SaveChangesAsync(); + } + + public async Task FillEditions() { + var editions = new List + { + new EditionReadModel + { + EditionStart = new DateTime(2000, 5, 10), + EditionFinish = new DateTime(2000, 11, 10), + ReportingStart = new DateTime(2000, 9, 30), + AvailableSubjects = new List + { + new EditionSubject + { + InternshipId = Context.InternshipTypes + .First(i => i.Description == "Instalacja, konfiguracja i administracja niewielkich sieci komputerowych, w tym bezprzewodowych.") + .Id, + }, + new EditionSubject + { + InternshipId = Context.InternshipTypes + .First(i => i.Description == "Projektowanie, implementacja i modyfikacjeoprogramowaniaw różnych technologiach i dla różnych zastosowań.") + .Id + } + }.ToImmutableList(), + Course = new Course + { + Name = "Informatyka", + } + } + }; + await Context.Editions.AddRangeAsync(editions); + await Context.SaveChangesAsync(); + } + + public async Task FillInternShips() { + var edition = Context.Editions.First(); + + var intenrships = new List + { + new InternshipReadModel + { + Student = Context.Students.First(i => i.AlbumNumber == 123456), + InternshipRegistration = new InternshipRegistrationReadModel() + { + Company = Context.Companies.First(c => c.Nip == "9570752316"), //Intel + Type = Context.InternshipTypes.First(t => t.Type == "UOP"), + Start = new DateTime(2000, 7, 1), + End = new DateTime(2000, 8, 30), + State = DocumentState.Submitted, + BranchAddress = + Context.Companies + .First(c => c.Nip == "9570752316") + .Branches + .First(), + }, + InternshipProgram = new InternshipProgramReadModel() + { + FirstName = "Horacy", + LastName = "Wościcki", + Email = "howos@intel.com", + PhoneNumber = "605-555-555", + ChosenSubjects = new List + { + new ProgramSubject + { + //TODO + } + } + }, + }, + new InternshipReadModel + { + Student = Context.Students.First(i => i.AlbumNumber == 102137), + InternshipRegistration = new InternshipRegistrationReadModel() + { + Company = Context.Companies.First(c => c.Nip == "5842068320"), //Asseco + Type = Context.InternshipTypes.First(t => t.Type == "UZ"), + Start = new DateTime(2000, 7, 1), + End = new DateTime(2000, 8, 30), + State = DocumentState.Submitted, + BranchAddress = + Context.Companies + .First(c => c.Nip == "5842068320") + .Branches + .First(), + }, + InternshipProgram = new InternshipProgramReadModel() + { + FirstName = "Henryk", + LastName = "Polaciński", + Email = "hepol@asseco.pl", + PhoneNumber = "555-525-545", + ChosenSubjects = new List + { + //TODO + }, + }, + }, + }; + Context.Internships.AddRange(intenrships); + await Context.SaveChangesAsync(); + } + } + + // new Internship + // { + // Intern = Context.Interns.Where(i => i.AlbumNumber == "102137").First(), + // Edition = edition, + // BranchOffice = + // Context.Companies + // .Where(c => c.Nip == "5842068320") //Asseco + // .First() + // .Branches + // .First(), + // Type = Context.InternshipTypes.Where(t => t.Type == "UZ").First(), + // StartDate = new DateTime(2000, 7, 1), + // EndDate = new DateTime(2000, 8, 30), + // IsAccepted = false, + // DeanAcceptance = new DeanAcceptance + // { + // IsDeansAcceptanceRequired = false + // }, + // Insurance = new Insurance + // { + // InsuranceDeliveryDate = new DateTime(2000, 6, 29), + // IsInsuranceRequired = true + // }, + // LengthInWeeks = 9, + // Grade = 0, + // Program = new List + // { + // edition.Subjects.First() + // }, + // Mentor = new Mentor + // { + // Name = "Horacy", + // Surname = "Wościcki", + // Email = "howos@intel.com", + // Phone = "605-555-555" + // } + // } + + // Course = new Course + // { + // Name = "Informatyka", + // DesiredSemesters = new List { 4, 6 }, + // ProgramEntries = new List + // { + // new InternshipProgramEntry + // { + // Description = "Instalacja, konfiguracja i administracja niewielkich sieci komputerowych, w tym bezprzewodowych." + // }, + // new InternshipProgramEntry + // { + // Description = "Implementacja polityki bezpieczeństwa informacji w firmie lub instytucji, instalacja ochrony antywirusowej, konfiguracja zapór ogniowych." + // }, + // new InternshipProgramEntry + // { + // Description = "Instalacja, konfiguracja i administracja oprogramowania, w szczególnościsystemów operacyjnychiserwerów aplikacji." + // }, + // new InternshipProgramEntry + // { + // Description = "Projektowanie, implementacja i modyfikacjeoprogramowaniaw różnych technologiach i dla różnych zastosowań." + // } + // } + // } + + // Course = new Course + // { + // Name = "Robotyka", + // DesiredSemesters = new List { 6 }, + // ProgramEntries = new List + // { + // new InternshipProgramEntry + // { + // Description = "Testowanie oprogramowania, także z wykorzystaniem narzędzi do testowania automatycznego." + // }, + // new InternshipProgramEntry + // { + // Description = "Wykorzystanie otwartych komponentów programowych z uwzględnieniem prawnych zależności pomiędzy nimi a produktem wynikowym." + // }, + // new InternshipProgramEntry + // { + // Description = "Projektowanie i implementacja baz danych oraz badanie ich wydajności." + // }, + // new InternshipProgramEntry + // { + // Description = "Projektowanie i prototypowaniezaawansowanychinterfejsów użytkownika." + // } + // } + // } + + // new Internship + // { + // Intern = Context.Interns.Where(i => i.AlbumNumber == "123456").First(), + // Edition = edition, + // BranchOffice = + // Context.Companies + // .Where(c => c.Nip == "9570752316") //Intel + // .First() + // .Branches + // .First(), + // Type = Context.InternshipTypes.Where(t => t.Type == "UOP").First(), + // StartDate = new DateTime(2000, 7, 1), + // EndDate = new DateTime(2000, 8, 30), + // IsAccepted = false, + // DeanAcceptance = new DeanAcceptance + // { + // AcceptanceDate = new DateTime(2000, 6, 26), + // IsDeansAcceptanceRequired = true, + // Reason = DeanAcceptanceReason.Semester + // }, + // Insurance = new Insurance + // { + // InsuranceDeliveryDate = new DateTime(2000, 6, 29), + // IsInsuranceRequired = true + // }, + // LengthInWeeks = 9, + // Grade = 0, + // Program = new List + // { + // edition.Subjects.First() + // }, + // Mentor = new Mentor + // { + // Name = "Horacy", + // Surname = "Wościcki", + // Email = "howos@intel.com", + // Phone = "605-555-555" + // } + // }, +} \ No newline at end of file diff --git a/src/InternshipSystem.Repository/Model/CompanyReadModel.cs b/src/InternshipSystem.Repository/Model/CompanyReadModel.cs index 2a5b2c9..b800da9 100644 --- a/src/InternshipSystem.Repository/Model/CompanyReadModel.cs +++ b/src/InternshipSystem.Repository/Model/CompanyReadModel.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using InternshipSystem.Core; namespace InternshipSystem.Repository.Model @@ -8,6 +9,7 @@ namespace InternshipSystem.Repository.Model public long Id { get; set; } public string Nip { get; set; } public string Name { get; set; } + public Uri SiteAddress { get; set; } public RangeOfActivity Range { get; set; } public List Branches { get; set; } } -- 2.45.2 From d5f3963a26208f4f2696921a33dcdfe67f310b86 Mon Sep 17 00:00:00 2001 From: mborzyszkowski Date: Tue, 4 Aug 2020 16:43:13 +0200 Subject: [PATCH 2/2] migration v2 --- .../Controllers/AdminController.cs | 68 ++--- .../DatabaseFiller.cs | 239 ++++++------------ 2 files changed, 118 insertions(+), 189 deletions(-) diff --git a/src/InternshipSystem.Api/Controllers/AdminController.cs b/src/InternshipSystem.Api/Controllers/AdminController.cs index f3ed409..84db31e 100644 --- a/src/InternshipSystem.Api/Controllers/AdminController.cs +++ b/src/InternshipSystem.Api/Controllers/AdminController.cs @@ -20,41 +20,49 @@ namespace InternshipSystem.Api.Controllers public async Task Fill() { await FillerService.FillCompany(); await FillerService.FillStudents(); + await FillerService.FillSubjects(); await FillerService.FillInternshipTypes(); await FillerService.FillEditions(); await FillerService.FillInternShips(); return Ok(); } - [HttpPost("fill/companies")] - public async Task FillCompaniesAsync() - { - await FillerService.FillCompany(); - return Ok(); - } - - [HttpPost("fill/students")] - public async Task FillStudentsAsync() { - await FillerService.FillStudents(); - return Ok(); - } - - [HttpPost("fill/internshiptypes")] - public async Task FillInternshipTypesAsync() { - await FillerService.FillInternshipTypes(); - return Ok(); - } - - [HttpPost("fill/editions")] - public async Task FillEditionsAsync() { - await FillerService.FillEditions(); - return Ok(); - } - - [HttpPost("fill/internships")] - public async Task FillInternShipsAsync() { - await FillerService.FillInternShips(); - return Ok(); - } + // [HttpPost("fill/companies")] + // public async Task FillCompaniesAsync() + // { + // await FillerService.FillCompany(); + // return Ok(); + // } + // + // [HttpPost("fill/students")] + // public async Task FillStudentsAsync() { + // await FillerService.FillStudents(); + // return Ok(); + // } + // + // [HttpPost("fill/subjects")] + // public async Task FillSubjectsAsync() + // { + // await FillerService.FillSubjects(); + // return Ok(); + // } + // + // [HttpPost("fill/internshiptypes")] + // public async Task FillInternshipTypesAsync() { + // await FillerService.FillInternshipTypes(); + // return Ok(); + // } + // + // [HttpPost("fill/editions")] + // public async Task FillEditionsAsync() { + // await FillerService.FillEditions(); + // return Ok(); + // } + // + // [HttpPost("fill/internships")] + // public async Task FillInternShipsAsync() { + // await FillerService.FillInternShips(); + // return Ok(); + // } } } \ No newline at end of file diff --git a/src/InternshipSystem.Repository/DatabaseFiller.cs b/src/InternshipSystem.Repository/DatabaseFiller.cs index 65f1f52..fc813a5 100644 --- a/src/InternshipSystem.Repository/DatabaseFiller.cs +++ b/src/InternshipSystem.Repository/DatabaseFiller.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Threading.Tasks; using InternshipSystem.Core; using InternshipSystem.Repository.Model; +using Microsoft.EntityFrameworkCore; namespace InternshipSystem.Repository { @@ -84,20 +85,22 @@ namespace InternshipSystem.Repository }; await Context.Companies.AddRangeAsync(companies); await Context.SaveChangesAsync(); - } + } - public async Task FillStudents() + public async Task FillStudents() { var interns = new List { - new Student { + new Student + { FirstName = "Jan", LastName = "Kowalski", AlbumNumber = 123456, Email = "s123456@student.pg.edu.pl", Semester = 4, }, - new Student { + new Student + { FirstName = "Adam", LastName = "Kołek", AlbumNumber = 102137, @@ -109,19 +112,20 @@ namespace InternshipSystem.Repository await Context.SaveChangesAsync(); } - public async Task FillInternshipTypes() { + public async Task FillInternshipTypes() + { var internshipTypes = new List { - new InternshipTypeReadModel + new InternshipTypeReadModel { Type = "FreeInternship", Description = "Praktyka bezpłatna", }, - new InternshipTypeReadModel + new InternshipTypeReadModel { Type = "GraduateInternship" }, - new InternshipTypeReadModel + new InternshipTypeReadModel { Type = "FreeApprenticeship" }, @@ -157,26 +161,54 @@ namespace InternshipSystem.Repository await Context.SaveChangesAsync(); } - public async Task FillEditions() { + public async Task FillSubjects() + { + var subjects = new List + { + new InternshipSubjectReadModel + { + Description = "Modelowanie baz danych" + }, + new InternshipSubjectReadModel + { + Description = "Oprogramowywanie kart graficznych" + }, + new InternshipSubjectReadModel + { + Description = "Projektowanie UI" + } + }; + await Context.Subjects.AddRangeAsync(subjects); + await Context.SaveChangesAsync(); + } + + public async Task FillEditions() + { var editions = new List { - new EditionReadModel + new EditionReadModel { EditionStart = new DateTime(2000, 5, 10), EditionFinish = new DateTime(2000, 11, 10), ReportingStart = new DateTime(2000, 9, 30), AvailableSubjects = new List { - new EditionSubject + new EditionSubject { - InternshipId = Context.InternshipTypes - .First(i => i.Description == "Instalacja, konfiguracja i administracja niewielkich sieci komputerowych, w tym bezprzewodowych.") + InternshipId = Context.Subjects + .First(i => i.Description.Equals("Modelowanie baz danych")) .Id, }, new EditionSubject { - InternshipId = Context.InternshipTypes - .First(i => i.Description == "Projektowanie, implementacja i modyfikacjeoprogramowaniaw różnych technologiach i dla różnych zastosowań.") + InternshipId = Context.Subjects + .First(i => i.Description.Equals("Oprogramowywanie kart graficznych")) + .Id + }, + new EditionSubject + { + InternshipId = Context.Subjects + .First(i => i.Description.Equals("Projektowanie UI")) .Id } }.ToImmutableList(), @@ -190,24 +222,24 @@ namespace InternshipSystem.Repository await Context.SaveChangesAsync(); } - public async Task FillInternShips() { - var edition = Context.Editions.First(); - + public async Task FillInternShips() + { var intenrships = new List { new InternshipReadModel { - Student = Context.Students.First(i => i.AlbumNumber == 123456), + Student = Context.Students.First(i => i.AlbumNumber.Equals(123456)), InternshipRegistration = new InternshipRegistrationReadModel() { - Company = Context.Companies.First(c => c.Nip == "9570752316"), //Intel - Type = Context.InternshipTypes.First(t => t.Type == "UOP"), + Company = Context.Companies.First(c => c.Nip.Equals("9570752316")), //Intel + Type = Context.InternshipTypes.First(t => t.Type.Equals("UOP")), Start = new DateTime(2000, 7, 1), End = new DateTime(2000, 8, 30), State = DocumentState.Submitted, - BranchAddress = + BranchAddress = Context.Companies - .First(c => c.Nip == "9570752316") + .Include(c => c.Branches) + .First(c => c.Nip.Equals("9570752316")) .Branches .First(), }, @@ -221,7 +253,17 @@ namespace InternshipSystem.Repository { new ProgramSubject { - //TODO + InternshipSubjectId = + Context.Subjects + .First(s => s.Description.Equals("Projektowanie UI")) + .Id + }, + new ProgramSubject + { + InternshipSubjectId = + Context.Subjects + .First(s => s.Description.Equals("Oprogramowywanie kart graficznych")) + .Id } } }, @@ -231,14 +273,15 @@ namespace InternshipSystem.Repository Student = Context.Students.First(i => i.AlbumNumber == 102137), InternshipRegistration = new InternshipRegistrationReadModel() { - Company = Context.Companies.First(c => c.Nip == "5842068320"), //Asseco - Type = Context.InternshipTypes.First(t => t.Type == "UZ"), + Company = Context.Companies.First(c => c.Nip.Equals("5842068320")), //Asseco + Type = Context.InternshipTypes.First(t => t.Type.Equals("UZ")), Start = new DateTime(2000, 7, 1), End = new DateTime(2000, 8, 30), State = DocumentState.Submitted, - BranchAddress = + BranchAddress = Context.Companies - .First(c => c.Nip == "5842068320") + .Include(c => c.Branches) + .First(c => c.Nip.Equals("5842068320")) .Branches .First(), }, @@ -250,141 +293,19 @@ namespace InternshipSystem.Repository PhoneNumber = "555-525-545", ChosenSubjects = new List { - //TODO + new ProgramSubject + { + InternshipSubjectId = + Context.Subjects + .First(s => s.Description.Equals("Modelowanie baz danych")) + .Id + } }, }, }, }; - Context.Internships.AddRange(intenrships); + await Context.Internships.AddRangeAsync(intenrships); await Context.SaveChangesAsync(); } - } - - // new Internship - // { - // Intern = Context.Interns.Where(i => i.AlbumNumber == "102137").First(), - // Edition = edition, - // BranchOffice = - // Context.Companies - // .Where(c => c.Nip == "5842068320") //Asseco - // .First() - // .Branches - // .First(), - // Type = Context.InternshipTypes.Where(t => t.Type == "UZ").First(), - // StartDate = new DateTime(2000, 7, 1), - // EndDate = new DateTime(2000, 8, 30), - // IsAccepted = false, - // DeanAcceptance = new DeanAcceptance - // { - // IsDeansAcceptanceRequired = false - // }, - // Insurance = new Insurance - // { - // InsuranceDeliveryDate = new DateTime(2000, 6, 29), - // IsInsuranceRequired = true - // }, - // LengthInWeeks = 9, - // Grade = 0, - // Program = new List - // { - // edition.Subjects.First() - // }, - // Mentor = new Mentor - // { - // Name = "Horacy", - // Surname = "Wościcki", - // Email = "howos@intel.com", - // Phone = "605-555-555" - // } - // } - - // Course = new Course - // { - // Name = "Informatyka", - // DesiredSemesters = new List { 4, 6 }, - // ProgramEntries = new List - // { - // new InternshipProgramEntry - // { - // Description = "Instalacja, konfiguracja i administracja niewielkich sieci komputerowych, w tym bezprzewodowych." - // }, - // new InternshipProgramEntry - // { - // Description = "Implementacja polityki bezpieczeństwa informacji w firmie lub instytucji, instalacja ochrony antywirusowej, konfiguracja zapór ogniowych." - // }, - // new InternshipProgramEntry - // { - // Description = "Instalacja, konfiguracja i administracja oprogramowania, w szczególnościsystemów operacyjnychiserwerów aplikacji." - // }, - // new InternshipProgramEntry - // { - // Description = "Projektowanie, implementacja i modyfikacjeoprogramowaniaw różnych technologiach i dla różnych zastosowań." - // } - // } - // } - - // Course = new Course - // { - // Name = "Robotyka", - // DesiredSemesters = new List { 6 }, - // ProgramEntries = new List - // { - // new InternshipProgramEntry - // { - // Description = "Testowanie oprogramowania, także z wykorzystaniem narzędzi do testowania automatycznego." - // }, - // new InternshipProgramEntry - // { - // Description = "Wykorzystanie otwartych komponentów programowych z uwzględnieniem prawnych zależności pomiędzy nimi a produktem wynikowym." - // }, - // new InternshipProgramEntry - // { - // Description = "Projektowanie i implementacja baz danych oraz badanie ich wydajności." - // }, - // new InternshipProgramEntry - // { - // Description = "Projektowanie i prototypowaniezaawansowanychinterfejsów użytkownika." - // } - // } - // } - - // new Internship - // { - // Intern = Context.Interns.Where(i => i.AlbumNumber == "123456").First(), - // Edition = edition, - // BranchOffice = - // Context.Companies - // .Where(c => c.Nip == "9570752316") //Intel - // .First() - // .Branches - // .First(), - // Type = Context.InternshipTypes.Where(t => t.Type == "UOP").First(), - // StartDate = new DateTime(2000, 7, 1), - // EndDate = new DateTime(2000, 8, 30), - // IsAccepted = false, - // DeanAcceptance = new DeanAcceptance - // { - // AcceptanceDate = new DateTime(2000, 6, 26), - // IsDeansAcceptanceRequired = true, - // Reason = DeanAcceptanceReason.Semester - // }, - // Insurance = new Insurance - // { - // InsuranceDeliveryDate = new DateTime(2000, 6, 29), - // IsInsuranceRequired = true - // }, - // LengthInWeeks = 9, - // Grade = 0, - // Program = new List - // { - // edition.Subjects.First() - // }, - // Mentor = new Mentor - // { - // Name = "Horacy", - // Surname = "Wościcki", - // Email = "howos@intel.com", - // Phone = "605-555-555" - // } - // }, + } } \ No newline at end of file -- 2.45.2