migration v2

This commit is contained in:
mborzyszkowski 2020-08-04 16:43:13 +02:00
parent a07d5f11dd
commit d5f3963a26
2 changed files with 118 additions and 189 deletions

View File

@ -20,41 +20,49 @@ namespace InternshipSystem.Api.Controllers
public async Task<IActionResult> Fill() { public async Task<IActionResult> Fill() {
await FillerService.FillCompany(); await FillerService.FillCompany();
await FillerService.FillStudents(); await FillerService.FillStudents();
await FillerService.FillSubjects();
await FillerService.FillInternshipTypes(); await FillerService.FillInternshipTypes();
await FillerService.FillEditions(); await FillerService.FillEditions();
await FillerService.FillInternShips(); await FillerService.FillInternShips();
return Ok(); return Ok();
} }
[HttpPost("fill/companies")] // [HttpPost("fill/companies")]
public async Task<IActionResult> FillCompaniesAsync() // public async Task<IActionResult> FillCompaniesAsync()
{ // {
await FillerService.FillCompany(); // await FillerService.FillCompany();
return Ok(); // return Ok();
} // }
//
[HttpPost("fill/students")] // [HttpPost("fill/students")]
public async Task<IActionResult> FillStudentsAsync() { // public async Task<IActionResult> FillStudentsAsync() {
await FillerService.FillStudents(); // await FillerService.FillStudents();
return Ok(); // return Ok();
} // }
//
[HttpPost("fill/internshiptypes")] // [HttpPost("fill/subjects")]
public async Task<IActionResult> FillInternshipTypesAsync() { // public async Task<IActionResult> FillSubjectsAsync()
await FillerService.FillInternshipTypes(); // {
return Ok(); // await FillerService.FillSubjects();
} // return Ok();
// }
[HttpPost("fill/editions")] //
public async Task<IActionResult> FillEditionsAsync() { // [HttpPost("fill/internshiptypes")]
await FillerService.FillEditions(); // public async Task<IActionResult> FillInternshipTypesAsync() {
return Ok(); // await FillerService.FillInternshipTypes();
} // return Ok();
// }
[HttpPost("fill/internships")] //
public async Task<IActionResult> FillInternShipsAsync() { // [HttpPost("fill/editions")]
await FillerService.FillInternShips(); // public async Task<IActionResult> FillEditionsAsync() {
return Ok(); // await FillerService.FillEditions();
} // return Ok();
// }
//
// [HttpPost("fill/internships")]
// public async Task<IActionResult> FillInternShipsAsync() {
// await FillerService.FillInternShips();
// return Ok();
// }
} }
} }

View File

@ -5,6 +5,7 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using InternshipSystem.Core; using InternshipSystem.Core;
using InternshipSystem.Repository.Model; using InternshipSystem.Repository.Model;
using Microsoft.EntityFrameworkCore;
namespace InternshipSystem.Repository namespace InternshipSystem.Repository
{ {
@ -90,14 +91,16 @@ namespace InternshipSystem.Repository
{ {
var interns = new List<Student> var interns = new List<Student>
{ {
new Student { new Student
{
FirstName = "Jan", FirstName = "Jan",
LastName = "Kowalski", LastName = "Kowalski",
AlbumNumber = 123456, AlbumNumber = 123456,
Email = "s123456@student.pg.edu.pl", Email = "s123456@student.pg.edu.pl",
Semester = 4, Semester = 4,
}, },
new Student { new Student
{
FirstName = "Adam", FirstName = "Adam",
LastName = "Kołek", LastName = "Kołek",
AlbumNumber = 102137, AlbumNumber = 102137,
@ -109,7 +112,8 @@ namespace InternshipSystem.Repository
await Context.SaveChangesAsync(); await Context.SaveChangesAsync();
} }
public async Task FillInternshipTypes() { public async Task FillInternshipTypes()
{
var internshipTypes = new List<InternshipTypeReadModel> var internshipTypes = new List<InternshipTypeReadModel>
{ {
new InternshipTypeReadModel new InternshipTypeReadModel
@ -157,7 +161,29 @@ namespace InternshipSystem.Repository
await Context.SaveChangesAsync(); await Context.SaveChangesAsync();
} }
public async Task FillEditions() { public async Task FillSubjects()
{
var subjects = new List<InternshipSubjectReadModel>
{
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<EditionReadModel> var editions = new List<EditionReadModel>
{ {
new EditionReadModel new EditionReadModel
@ -169,14 +195,20 @@ namespace InternshipSystem.Repository
{ {
new EditionSubject new EditionSubject
{ {
InternshipId = Context.InternshipTypes InternshipId = Context.Subjects
.First(i => i.Description == "Instalacja, konfiguracja i administracja niewielkich sieci komputerowych, w tym bezprzewodowych.") .First(i => i.Description.Equals("Modelowanie baz danych"))
.Id, .Id,
}, },
new EditionSubject new EditionSubject
{ {
InternshipId = Context.InternshipTypes InternshipId = Context.Subjects
.First(i => i.Description == "Projektowanie, implementacja i modyfikacjeoprogramowaniaw różnych technologiach i dla różnych zastosowań.") .First(i => i.Description.Equals("Oprogramowywanie kart graficznych"))
.Id
},
new EditionSubject
{
InternshipId = Context.Subjects
.First(i => i.Description.Equals("Projektowanie UI"))
.Id .Id
} }
}.ToImmutableList(), }.ToImmutableList(),
@ -190,24 +222,24 @@ namespace InternshipSystem.Repository
await Context.SaveChangesAsync(); await Context.SaveChangesAsync();
} }
public async Task FillInternShips() { public async Task FillInternShips()
var edition = Context.Editions.First(); {
var intenrships = new List<InternshipReadModel> var intenrships = new List<InternshipReadModel>
{ {
new InternshipReadModel new InternshipReadModel
{ {
Student = Context.Students.First(i => i.AlbumNumber == 123456), Student = Context.Students.First(i => i.AlbumNumber.Equals(123456)),
InternshipRegistration = new InternshipRegistrationReadModel() InternshipRegistration = new InternshipRegistrationReadModel()
{ {
Company = Context.Companies.First(c => c.Nip == "9570752316"), //Intel Company = Context.Companies.First(c => c.Nip.Equals("9570752316")), //Intel
Type = Context.InternshipTypes.First(t => t.Type == "UOP"), Type = Context.InternshipTypes.First(t => t.Type.Equals("UOP")),
Start = new DateTime(2000, 7, 1), Start = new DateTime(2000, 7, 1),
End = new DateTime(2000, 8, 30), End = new DateTime(2000, 8, 30),
State = DocumentState.Submitted, State = DocumentState.Submitted,
BranchAddress = BranchAddress =
Context.Companies Context.Companies
.First(c => c.Nip == "9570752316") .Include(c => c.Branches)
.First(c => c.Nip.Equals("9570752316"))
.Branches .Branches
.First(), .First(),
}, },
@ -221,7 +253,17 @@ namespace InternshipSystem.Repository
{ {
new ProgramSubject 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), Student = Context.Students.First(i => i.AlbumNumber == 102137),
InternshipRegistration = new InternshipRegistrationReadModel() InternshipRegistration = new InternshipRegistrationReadModel()
{ {
Company = Context.Companies.First(c => c.Nip == "5842068320"), //Asseco Company = Context.Companies.First(c => c.Nip.Equals("5842068320")), //Asseco
Type = Context.InternshipTypes.First(t => t.Type == "UZ"), Type = Context.InternshipTypes.First(t => t.Type.Equals("UZ")),
Start = new DateTime(2000, 7, 1), Start = new DateTime(2000, 7, 1),
End = new DateTime(2000, 8, 30), End = new DateTime(2000, 8, 30),
State = DocumentState.Submitted, State = DocumentState.Submitted,
BranchAddress = BranchAddress =
Context.Companies Context.Companies
.First(c => c.Nip == "5842068320") .Include(c => c.Branches)
.First(c => c.Nip.Equals("5842068320"))
.Branches .Branches
.First(), .First(),
}, },
@ -250,141 +293,19 @@ namespace InternshipSystem.Repository
PhoneNumber = "555-525-545", PhoneNumber = "555-525-545",
ChosenSubjects = new List<ProgramSubject> ChosenSubjects = new List<ProgramSubject>
{ {
//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(); 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<InternshipProgramEntry>
// {
// 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<int> { 4, 6 },
// ProgramEntries = new List<InternshipProgramEntry>
// {
// 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<int> { 6 },
// ProgramEntries = new List<InternshipProgramEntry>
// {
// 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<InternshipProgramEntry>
// {
// edition.Subjects.First()
// },
// Mentor = new Mentor
// {
// Name = "Horacy",
// Surname = "Wościcki",
// Email = "howos@intel.com",
// Phone = "605-555-555"
// }
// },
} }