Oj tak tak modeliczq +49

This commit is contained in:
MaxchilKH 2020-07-29 18:28:25 +02:00
parent ba31cd89df
commit af2f225f6c
49 changed files with 846 additions and 614 deletions

View File

@ -6,14 +6,13 @@ services:
environment:
CONNECTIONSTRINGS__INTERNSHIPDATABASE: "Host=db.postgres;Port=5432;Database=postgres;Username=postgres;Password=szwoniu"
ASPNETCORE_ENVIRONMENT: Development
APIPREFIX: /api
depends_on:
- db.postgres
ports:
- 8080:80
db.postgres:
image: mborzyszkowski/internship_system_db:latest
image: postgres:latest
restart: always
environment:
POSTGRES_PASSWORD: szwoniu

View File

@ -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<IActionResult> Fill() {
await FillerService.FillCompany();
await FillerService.FillInterns();
await FillerService.FillInternshipTypes();
await FillerService.FillEditions();
await FillerService.FillInternShips();
return Ok();
}
[HttpPost("fill/companies")]
public async Task<IActionResult> FillCompaniesAsync()
{
await FillerService.FillCompany();
return Ok();
}
[HttpPost("fill/interns")]
public async Task<IActionResult> FillInternsAsync() {
await FillerService.FillInterns();
return Ok();
}
[HttpPost("fill/internshiptypes")]
public async Task<IActionResult> FillInternshipTypesAsync() {
await FillerService.FillInternshipTypes();
return Ok();
}
[HttpPost("fill/editions")]
public async Task<IActionResult> FillEditionsAsync() {
await FillerService.FillEditions();
return Ok();
}
[HttpPost("fill/internships")]
public async Task<IActionResult> FillInternShipsAsync() {
await FillerService.FillInternShips();
return Ok();
}
}
}
// 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<IActionResult> Fill() {
// await FillerService.FillCompany();
// await FillerService.FillInterns();
// await FillerService.FillInternshipTypes();
// await FillerService.FillEditions();
// await FillerService.FillInternShips();
// return Ok();
// }
//
// [HttpPost("fill/companies")]
// public async Task<IActionResult> FillCompaniesAsync()
// {
// await FillerService.FillCompany();
// return Ok();
// }
//
// [HttpPost("fill/interns")]
// public async Task<IActionResult> FillInternsAsync() {
// await FillerService.FillInterns();
// return Ok();
// }
//
// [HttpPost("fill/internshiptypes")]
// public async Task<IActionResult> FillInternshipTypesAsync() {
// await FillerService.FillInternshipTypes();
// return Ok();
// }
//
// [HttpPost("fill/editions")]
// public async Task<IActionResult> FillEditionsAsync() {
// await FillerService.FillEditions();
// return Ok();
// }
//
// [HttpPost("fill/internships")]
// public async Task<IActionResult> FillInternShipsAsync() {
// await FillerService.FillInternShips();
// return Ok();
// }
// }
// }

View File

@ -1,40 +1,40 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using InternshipSystem.Api.Queries;
using InternshipSystem.Core;
using InternshipSystem.Repository;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace InternshipSystem.Api.Controllers
{
[ApiController]
[Route("companies")]
public class CompaniesController : ControllerBase
{
public CompaniesController(InternshipDbContext context)
{
Context = context;
}
private InternshipDbContext Context { get; }
/// <summary>
/// Get companies matching provided paginated query
/// </summary>
/// <param name="searchQuery">Paginated query description</param>
/// <returns>Part of companies collection</returns>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IReadOnlyCollection<Company>> SearchByNameAsync([FromQuery] SearchQuery searchQuery, CancellationToken cancellationToken) =>
await Context.Companies
.Where(c => c.Name.ToLower().Contains(searchQuery.Query.ToLower()))
.OrderBy(o => o.Name)
.Skip(searchQuery.Page * searchQuery.PerPage)
.Take(searchQuery.PerPage)
.ToListAsync(cancellationToken);
}
}
// using System.Collections.Generic;
// using System.Linq;
// using System.Threading;
// using System.Threading.Tasks;
// using InternshipSystem.Api.Queries;
// using InternshipSystem.Core;
// using InternshipSystem.Repository;
// using Microsoft.AspNetCore.Http;
// using Microsoft.AspNetCore.Mvc;
// using Microsoft.EntityFrameworkCore;
//
// namespace InternshipSystem.Api.Controllers
// {
// [ApiController]
// [Route("companies")]
// public class CompaniesController : ControllerBase
// {
// public CompaniesController(InternshipDbContext context)
// {
// Context = context;
// }
// private InternshipDbContext Context { get; }
//
// /// <summary>
// /// Get companies matching provided paginated query
// /// </summary>
// /// <param name="searchQuery">Paginated query description</param>
// /// <returns>Part of companies collection</returns>
// [HttpGet]
// [ProducesResponseType(StatusCodes.Status200OK)]
// public async Task<IReadOnlyCollection<Company>> SearchByNameAsync([FromQuery] SearchQuery searchQuery, CancellationToken cancellationToken) =>
// await Context.Companies
// .Where(c => c.Name.ToLower().Contains(searchQuery.Query.ToLower()))
// .OrderBy(o => o.Name)
// .Skip(searchQuery.Page * searchQuery.PerPage)
// .Take(searchQuery.PerPage)
// .ToListAsync(cancellationToken);
// }
//
// }

View File

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

View File

@ -0,0 +1,9 @@
namespace InternshipSystem.Core
{
public class Approval
{
public long Id { get; set; }
public byte[] Scan { get; set; }
public DocumentState State { get; set; }
}
}

View File

@ -0,0 +1,9 @@
namespace InternshipSystem.Core
{
public class BranchOffice
{
public long Id { get; set; }
public BranchAddress Address { get; set; }
}
}

View File

@ -0,0 +1,28 @@
using System.Collections.Generic;
using System.Linq;
namespace InternshipSystem.Core
{
public class Company
{
public long Id { get; set; }
public Nip Nip { get; set; }
public string Name { get; set; }
public RangeOfActivity Range { get; set; }
public List<BranchOffice> Branches { get; set; }
public Company CreateCompany(Nip nip, RangeOfActivity range, string name)
{
return new Company
{
Nip = nip,
Range = range,
Name = name
};
}
public void AddBranchAddress(BranchAddress branch)
{
}
}
}

View File

@ -0,0 +1,8 @@
namespace InternshipSystem.Core
{
public class Course
{
public long Id { get; set; }
public string Name { get; set; }
}
}

View File

@ -0,0 +1,9 @@
namespace InternshipSystem.Core
{
public class Document
{
public long Id { get; set; }
public string Description { get; set; }
public DocumentState State { get; set; }
}
}

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
namespace InternshipSystem.Core
{
public class Edition
{
public long Id { get; private set; }
public DateTime EditionStart { get; private set; }
public DateTime EditionFinish { get; private set; }
public DateTime ReportingStart { get; private set; }
public Course Course { get; private set; }
public IReadOnlyCollection<InternshipSubject> AvailableSubjects { get; private set; }
public Edition CreateEdition(DateTime start, DateTime end, DateTime reportingStart)
{
return new Edition
{
EditionStart = start,
EditionFinish = end,
ReportingStart = reportingStart
};
}
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
namespace InternshipSystem.Core
{
public class Internship
{
public long Id { get; set; }
public Student Student { get; set; }
public InternshipRegistration InternshipRegistration { get; set; }
public InternshipProgram InternshipProgram { get; set; }
public Report Report { get; set; }
public List<Approval> Approvals { get; set; }
public List<Document> Documents { get; set; }
}
}

View File

@ -0,0 +1,12 @@
using System.Collections.Generic;
namespace InternshipSystem.Core
{
public class InternshipProgram
{
public long Id { get; set; }
public Mentor Mentor { get; set; }
public List<InternshipSubject> ChosenSubjects { get; set; }
public DocumentState State { get; set; }
}
}

View File

@ -0,0 +1,15 @@
using System;
namespace InternshipSystem.Core
{
public class InternshipRegistration
{
public long Id { get; set; }
public Company Company { get; set; }
public BranchOffice BranchAddress { get; set; }
public DateTime Start { get; set; }
public DateTime End { get; set; }
public InternshipType Type { get; set; }
public DocumentState State { get; set; }
}
}

View File

@ -0,0 +1,8 @@
namespace InternshipSystem.Core
{
public class Report
{
public long Id { get; set; }
public DocumentState State { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using System.Collections.Generic;
namespace InternshipSystem.Core
{
public class Student
{
public long Id { get; set; }
public int AlbumNumber { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public int Semester { get; set; }
}
}

View File

@ -0,0 +1,11 @@
using System.Threading;
using System.Threading.Tasks;
namespace InternshipSystem.Core.Interface.Repository
{
public interface IInternshipRepository
{
Task SaveInternship(Internship internship, CancellationToken token);
Task<Internship> GetStudentsInternship(Student student, CancellationToken token);
}
}

View File

@ -0,0 +1,11 @@
using System.Threading;
using System.Threading.Tasks;
namespace InternshipSystem.Core.Interface.Repository
{
public interface IStudentRepository
{
Task<Student> GetAlbumNumber(int album, CancellationToken token);
Task SaveStudent(Student student, CancellationToken token);
}
}

View File

@ -1,6 +1,6 @@
namespace InternshipSystem.Core
{
public class Address
public struct BranchAddress
{
public string Street { get; set; }
public string Building { get; set; }
@ -8,4 +8,4 @@
public string PostalCode { get; set; }
public string Country { get; set; }
}
}
}

View File

@ -0,0 +1,10 @@
namespace InternshipSystem.Core
{
public enum DocumentState
{
Draft,
Submitted,
Accepted,
Rejected
}
}

View File

@ -0,0 +1,7 @@
namespace InternshipSystem.Core
{
public struct InternshipSubject
{
public string Description { get; set; }
}
}

View File

@ -1,8 +1,7 @@
namespace InternshipSystem.Core
{
public class InternshipType
public struct InternshipType
{
public int Id { get; set; }
public string Type { get; set; }
public string Description { get; set; }
}

View File

@ -0,0 +1,10 @@
namespace InternshipSystem.Core
{
public struct Mentor
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public PhoneNumber PhoneNumber { get; set; }
}
}

View File

@ -0,0 +1,18 @@
namespace InternshipSystem.Core
{
public struct Nip
{
private readonly string nip;
private Nip(string maybeNip)
{
nip = maybeNip;
}
public static implicit operator string(Nip nip) =>
nip.nip;
public static implicit operator Nip(string maybeNip) =>
new Nip(maybeNip);
}
}

View File

@ -0,0 +1,6 @@
namespace InternshipSystem.Core
{
public struct PhoneNumber
{
}
}

View File

@ -0,0 +1,9 @@
namespace InternshipSystem.Core
{
public enum RangeOfActivity
{
International,
National,
Local
}
}

View File

@ -1,330 +1,330 @@
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<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
{
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<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
{
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ń."
}
}
}
},
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<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."
}
}
}
}
};
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
{
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"
}
},
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();
}
}
}
// 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<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
// {
// 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<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
// {
// 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ń."
// }
// }
// }
// },
// 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<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."
// }
// }
// }
// }
// };
// 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
// {
// 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"
// }
// },
// 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,18 +1,25 @@
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using InternshipSystem.Core;
using InternshipSystem.Repository.Model;
namespace InternshipSystem.Repository
{
public class InternshipDbContext : DbContext
{
public DbSet<Internship> Internships { get; set; }
public DbSet<Company> Companies { get; set; }
public DbSet<Edition> Editions { get; set; }
public DbSet<Report> Reports { get; set; }
public DbSet<Intern> Interns { get; set; }
public DbSet<InternshipType> InternshipTypes { get; set; }
public DbSet<Mentor> Mentors { get; set; }
public DbSet<InternshipProgramEntry> InternshipProgramEntries { get; set; }
public DbSet<Document> Documents { get; set; }
public DbSet<Course> Courses { get; set; }
public DbSet<CompanyReadModel> Companies { get; set; }
public DbSet<InternshipSubjectReadModel> Subjects { get; set; }
public DbSet<EditionReadModel> Editions { get; set; }
public DbSet<Student> Students { get; set; }
public DbSet<Approval> Approvals { get; set; }
public DbSet<BranchOfficeReadModel> BranchOffices { get; set; }
public DbSet<InternshipRegistrationReadModel> Registrations { get; set; }
public DbSet<InternshipProgramReadModel> Programs { get; set; }
public DbSet<InternshipReadModel> Internships { get; set; }
public DbSet<InternshipTypeReadModel> InternshipTypes { get; set; }
public InternshipDbContext(DbContextOptions<InternshipDbContext> options)
: base(options)
{
@ -22,24 +29,39 @@ namespace InternshipSystem.Repository
optionsBuilder
.UseSnakeCaseNamingConvention();
protected override void OnModelCreating(ModelBuilder modelBuilder) {
modelBuilder
.Entity<Internship>(ie => {
ie.OwnsOne(i => i.DeanAcceptance);
ie.OwnsOne(i => i.Insurance);
});
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<ProgramSubject>(builder =>
{
builder
.HasKey(subject => new { subject.InternshipProgramId, subject.InternshipSubjectId });
builder
.HasOne<InternshipProgramReadModel>()
.WithMany(model => model.ChosenSubjects)
.HasForeignKey(subject => subject.InternshipProgramId);
builder
.HasOne<InternshipSubjectReadModel>()
.WithMany()
.HasForeignKey(subject => subject.InternshipSubjectId);
});
modelBuilder
.Entity<Company>()
.HasKey(c => c.Nip);
modelBuilder
.Entity<BranchOffice>()
.OwnsOne(b => b.Address);
modelBuilder.Entity<EditionSubject>(builder =>
{
builder
.HasKey(subject => new { subject.EditionId, subject.InternshipId});
builder
.HasOne<EditionReadModel>()
.WithMany(model => model.AvailableSubjects)
.HasForeignKey(p => p.EditionId);
modelBuilder
.Entity<Intern>()
.HasKey(i => i.AlbumNumber);
builder
.HasOne<InternshipSubjectReadModel>()
.WithMany()
.HasForeignKey(subject => subject.InternshipId);
});
}
}
}

View File

@ -1,10 +0,0 @@
namespace InternshipSystem.Core
{
public class BranchOffice
{
public int Id { get; set; }
public Address Address { get; set; }
public Company Company { get; set; }
public int Provider { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using InternshipSystem.Core;
namespace InternshipSystem.Repository.Model
{
public class BranchOfficeReadModel
{
public long Id { get; set; }
public string Street { get; set; }
public string Building { get; set; }
public string City { get; set; }
public string PostalCode { get; set; }
public string Country { get; set; }
}
}

View File

@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
namespace InternshipSystem.Core
{
public class Company
{
public string Nip { get; set; }
public string Name { get; set; }
public RangeOfActivities Range { get; set; }
public Uri SiteAddress { get; set; }
public int Provider { get; set; }
public List<BranchOffice> Branches { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using System.Collections.Generic;
using InternshipSystem.Core;
namespace InternshipSystem.Repository.Model
{
public class CompanyReadModel
{
public long Id { get; set; }
public string Nip { get; set; }
public string Name { get; set; }
public RangeOfActivity Range { get; set; }
public List<BranchOfficeReadModel> Branches { get; set; }
}
}

View File

@ -1,12 +0,0 @@
using System.Collections.Generic;
namespace InternshipSystem.Core
{
public class Course
{
public int Id { get; set; }
public string Name { get; set; }
public List<int> DesiredSemesters { get; set; }
public List<InternshipProgramEntry> ProgramEntries { get; set; }
}
}

View File

@ -1,18 +0,0 @@
using System;
namespace InternshipSystem.Core
{
public class DeanAcceptance
{
public DateTime? AcceptanceDate { get; set; }
public bool IsDeansAcceptanceRequired { get; set; }
public DeanAcceptanceReason? Reason { get; set; }
}
public enum DeanAcceptanceReason
{
Semester,
Delay,
Whatever
}
}

View File

@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
namespace InternshipSystem.Core
{
public class Edition
{
public int Id { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public DateTime IPPDeadlineDate { get; set; }
public List<InternshipProgramEntry> Subjects { get; set; }
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using InternshipSystem.Core;
namespace InternshipSystem.Repository.Model
{
public class EditionReadModel
{
public long Id { get; set; }
public DateTime EditionStart { get; set; }
public DateTime EditionFinish { get; set; }
public DateTime ReportingStart { get; set; }
public Course Course { get; set; }
public ImmutableList<EditionSubject> AvailableSubjects { get; set; }
}
}

View File

@ -0,0 +1,8 @@
namespace InternshipSystem.Repository
{
public class EditionSubject
{
public long EditionId { get; set; }
public long InternshipId { get; set; }
}
}

View File

@ -1,10 +0,0 @@
using System;
namespace InternshipSystem.Core
{
public class Insurance
{
public DateTime InsuranceDeliveryDate { get; set; }
public bool IsInsuranceRequired { get; set; }
}
}

View File

@ -1,14 +0,0 @@
using System;
namespace InternshipSystem.Core
{
public class Intern
{
public string AlbumNumber { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
public string Email { get; set; }
public int Semester { get; set; }
public Course Course { get; set; }
}
}

View File

@ -1,24 +0,0 @@
using System;
using System.Collections.Generic;
namespace InternshipSystem.Core
{
public class Internship
{
public int Id { get; set; }
public Intern Intern { get; set; }
public Edition Edition { get; set; }
public Report Report { get; set; }
public BranchOffice BranchOffice { get; set; }
public InternshipType Type { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public bool IsAccepted { get; set; }
public DeanAcceptance DeanAcceptance { get; set; }
public Insurance Insurance { get; set; }
public int LengthInWeeks { get; set; }
public float Grade { get; set; }
public List<InternshipProgramEntry> Program { get; set; }
public Mentor Mentor { get; set; }
}
}

View File

@ -1,9 +0,0 @@
namespace InternshipSystem.Core
{
public class InternshipProgramEntry
{
public int Id { get; set; }
public Course Course { get; set; }
public string Description { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using System.Collections.Generic;
using InternshipSystem.Core;
namespace InternshipSystem.Repository.Model
{
public class InternshipProgramReadModel
{
public long Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string PhoneNumber { get; set; }
public List<ProgramSubject> ChosenSubjects { get; set; }
public DocumentState State { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using System.Collections.Generic;
using InternshipSystem.Core;
namespace InternshipSystem.Repository.Model
{
public class InternshipReadModel
{
public long Id { get; set; }
public Student Student { get; set; }
public InternshipRegistrationReadModel InternshipRegistration { get; set; }
public InternshipProgramReadModel InternshipProgram { get; set; }
public Report Report { get; set; }
public List<Approval> Approvals { get; set; }
public List<Document> Documents { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using System;
using InternshipSystem.Core;
namespace InternshipSystem.Repository.Model
{
public class InternshipRegistrationReadModel
{
public long Id { get; set; }
public CompanyReadModel Company { get; set; }
public BranchOfficeReadModel BranchAddress { get; set; }
public DateTime Start { get; set; }
public DateTime End { get; set; }
public InternshipTypeReadModel Type { get; set; }
public DocumentState State { get; set; }
}
}

View File

@ -0,0 +1,12 @@
using System;
using InternshipSystem.Core;
namespace InternshipSystem.Repository.Model
{
public class InternshipSubjectReadModel
{
public long Id { get; set; }
public string Description { get; set; }
}
}

View File

@ -0,0 +1,9 @@
namespace InternshipSystem.Repository.Model
{
public class InternshipTypeReadModel
{
public long Id { get; set; }
public string Type { get; set; }
public string Description { get; set; }
}
}

View File

@ -1,11 +0,0 @@
namespace InternshipSystem.Core
{
public class Mentor {
public int Id { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public Company Company { get; set; }
}
}

View File

@ -0,0 +1,8 @@
namespace InternshipSystem.Repository.Model
{
public class ProgramSubject
{
public long InternshipProgramId { get; set; }
public long InternshipSubjectId { get; set; }
}
}

View File

@ -1,9 +0,0 @@
namespace InternshipSystem.Core
{
public enum RangeOfActivities
{
Other,
National,
International
}
}

View File

@ -1,7 +0,0 @@
namespace InternshipSystem.Core
{
public class Report
{
public int Id { get; set; }
}
}