This commit is contained in:
mborzyszkowski 2020-07-29 19:38:39 +02:00
parent af2f225f6c
commit a07d5f11dd
4 changed files with 454 additions and 392 deletions

View File

@ -1,60 +1,60 @@
// using System.Threading.Tasks; using System.Threading.Tasks;
// using InternshipSystem.Repository; using InternshipSystem.Repository;
// using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
//
// namespace Internship.Api.Controller namespace InternshipSystem.Api.Controllers
// { {
// [ApiController] [ApiController]
// [Route("admin")] [Route("admin")]
// public class AdminController : ControllerBase public class AdminController : ControllerBase
// { {
// public AdminController(DatabaseFiller fillerService) public AdminController(DatabaseFiller fillerService)
// { {
// FillerService = fillerService; FillerService = fillerService;
// } }
//
// public DatabaseFiller FillerService { get; } public DatabaseFiller FillerService { get; }
//
//
// [HttpPost("fill")] [HttpPost("fill")]
// public async Task<IActionResult> Fill() { public async Task<IActionResult> Fill() {
// await FillerService.FillCompany(); await FillerService.FillCompany();
// await FillerService.FillInterns(); await FillerService.FillStudents();
// 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/interns")] [HttpPost("fill/students")]
// public async Task<IActionResult> FillInternsAsync() { public async Task<IActionResult> FillStudentsAsync() {
// await FillerService.FillInterns(); await FillerService.FillStudents();
// return Ok(); return Ok();
// } }
//
// [HttpPost("fill/internshiptypes")] [HttpPost("fill/internshiptypes")]
// public async Task<IActionResult> FillInternshipTypesAsync() { public async Task<IActionResult> FillInternshipTypesAsync() {
// await FillerService.FillInternshipTypes(); await FillerService.FillInternshipTypes();
// return Ok(); return Ok();
// } }
//
// [HttpPost("fill/editions")] [HttpPost("fill/editions")]
// public async Task<IActionResult> FillEditionsAsync() { public async Task<IActionResult> FillEditionsAsync() {
// await FillerService.FillEditions(); await FillerService.FillEditions();
// return Ok(); return Ok();
// } }
//
// [HttpPost("fill/internships")] [HttpPost("fill/internships")]
// public async Task<IActionResult> FillInternShipsAsync() { public async Task<IActionResult> FillInternShipsAsync() {
// await FillerService.FillInternShips(); await FillerService.FillInternShips();
// return Ok(); return Ok();
// } }
// } }
// } }

View File

@ -29,7 +29,7 @@ namespace InternshipSystem.Api
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
options.IncludeXmlComments(xmlPath); options.IncludeXmlComments(xmlPath);
}) })
// .AddScoped<DatabaseFiller>() .AddScoped<DatabaseFiller>()
.AddControllers() .AddControllers()
; ;

View File

@ -1,114 +1,303 @@
// using System; using System;
// using System.Collections.Generic; using System.Collections.Generic;
// using System.Linq; using System.Collections.Immutable;
// using System.Threading.Tasks; using System.Linq;
// using InternshipSystem.Core; using System.Threading.Tasks;
// using InternshipSystem.Core;
// namespace InternshipSystem.Repository 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<CompanyReadModel>
{
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<BranchOfficeReadModel>
{
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<BranchOfficeReadModel>
{
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<Student>
{
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<InternshipTypeReadModel>
{
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<EditionReadModel>
{
new EditionReadModel
{
EditionStart = new DateTime(2000, 5, 10),
EditionFinish = new DateTime(2000, 11, 10),
ReportingStart = new DateTime(2000, 9, 30),
AvailableSubjects = new List<EditionSubject>
{
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<InternshipReadModel>
{
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<ProgramSubject>
{
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<ProgramSubject>
{
//TODO
},
},
},
};
Context.Internships.AddRange(intenrships);
await Context.SaveChangesAsync();
}
}
// new Internship
// { // {
// public class DatabaseFiller // 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
// { // {
// public DatabaseFiller(InternshipDbContext context) // IsDeansAcceptanceRequired = false
// {
// Context = context;
// }
//
// public InternshipDbContext Context { get; }
//
// public async Task FillCompany()
// {
// var companies = new List<Company>
// {
// 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<BranchOffice>
// {
// new BranchOffice
// {
// Address = new Address
// {
// City = "Gdańsk",
// Street = "ul. Słowackiego",
// Building = "173",
// PostalCode = "80-298",
// Country = "Poland"
// }
// }, // },
// new BranchOffice // Insurance = new Insurance
// { // {
// Address = new Address // InsuranceDeliveryDate = new DateTime(2000, 6, 29),
// { // IsInsuranceRequired = true
// City = "Gdańsk",
// Street = "Jana z Kolna",
// Building = "11",
// PostalCode = "80-001",
// Country = "Poland"
// }
// }, // },
// new BranchOffice // LengthInWeeks = 9,
// Grade = 0,
// Program = new List<InternshipProgramEntry>
// { // {
// Address = new Address // edition.Subjects.First()
// {
// City = "Boston",
// Street = "State St",
// Building = "53",
// PostalCode = "MA 02109",
// Country = "Stany Zjednoczone"
// }
// }
// }
// }, // },
// new Company // Mentor = new Mentor
// { // {
// Name = "Asseco Poland", // Name = "Horacy",
// SiteAddress = new Uri("http://pl.asseco.com"), // Surname = "Wościcki",
// Nip = "5842068320", // Email = "howos@intel.com",
// Range = RangeOfActivities.National, // Phone = "605-555-555"
// Branches = new List<BranchOffice>
// {
// 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<Intern>
// {
// new Intern {
// Name = "Jan",
// Surname = "Kowalski",
// AlbumNumber = "123456",
// Email = "s123456@student.pg.edu.pl",
// Semester = 4,
// Course = new Course // Course = new Course
// { // {
// Name = "Informatyka", // Name = "Informatyka",
@ -133,13 +322,7 @@
// } // }
// } // }
// } // }
// },
// new Intern {
// Name = "Adam",
// Surname = "Kołek",
// AlbumNumber = "102137",
// Email = "s102137@student.pg.edu.pl",
// Semester = 6,
// Course = new Course // Course = new Course
// { // {
// Name = "Robotyka", // Name = "Robotyka",
@ -164,88 +347,7 @@
// } // }
// } // }
// } // }
// }
// };
// Context.Interns.AddRange(interns);
// await Context.SaveChangesAsync();
// }
//
// public async Task FillInternshipTypes() {
// var internshipTypes = new List<InternshipType>
// {
// 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<Edition>
// {
// new Edition
// {
// StartDate = new DateTime(2000, 5, 10),
// EndDate = new DateTime(2000, 11, 10),
// IPPDeadlineDate = new DateTime(2000, 9, 30),
// Subjects = new List<InternshipProgramEntry>
// {
// 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<Internship>
// {
// new Internship // new Internship
// { // {
// Intern = Context.Interns.Where(i => i.AlbumNumber == "123456").First(), // Intern = Context.Interns.Where(i => i.AlbumNumber == "123456").First(),
@ -285,46 +387,4 @@
// Phone = "605-555-555" // 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<InternshipProgramEntry>
// {
// 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();
// }
// }
// }

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using InternshipSystem.Core; using InternshipSystem.Core;
namespace InternshipSystem.Repository.Model namespace InternshipSystem.Repository.Model
@ -8,6 +9,7 @@ namespace InternshipSystem.Repository.Model
public long Id { get; set; } public long Id { get; set; }
public string Nip { get; set; } public string Nip { get; set; }
public string Name { get; set; } public string Name { get; set; }
public Uri SiteAddress { get; set; }
public RangeOfActivity Range { get; set; } public RangeOfActivity Range { get; set; }
public List<BranchOfficeReadModel> Branches { get; set; } public List<BranchOfficeReadModel> Branches { get; set; }
} }