diff --git a/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs b/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs index 07ecf55..0f35ff5 100644 --- a/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs +++ b/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs @@ -1,15 +1,11 @@ -using System.Linq; -using System.Threading; +using System.Threading; using System.Threading.Tasks; using InternshipSystem.Api.Queries; using InternshipSystem.Api.Security; -using InternshipSystem.Core.Commands; using InternshipSystem.Repository; using Microsoft.AspNetCore.Authorization; -using InternshipSystem.Api.Security; using InternshipSystem.Api.Services; using InternshipSystem.Core; -using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; diff --git a/src/InternshipSystem.Api/Services/InternshipService.cs b/src/InternshipSystem.Api/Services/InternshipService.cs index fc0d9ad..fa920d0 100644 --- a/src/InternshipSystem.Api/Services/InternshipService.cs +++ b/src/InternshipSystem.Api/Services/InternshipService.cs @@ -25,11 +25,16 @@ namespace InternshipSystem.Api.Services public async Task SubmitRegistration(RegistrationFormQuery registrationQuery, User user, CancellationToken cancellationToken) { - var edition = await _context.Editions.FindAsync(user.EditionId); + var edition = await _context.Editions + .Include(e => e.AvailableInternshipTypes) + .FirstOrDefaultAsync(e => e.Id.Equals(user.EditionId), cancellationToken: cancellationToken); var internship = await _context.Entry(edition) .Collection(e => e.Internships) .Query() + .Include(i => i.InternshipRegistration) + .Include(i => i.InternshipRegistration.Company) + .Include(i => i.InternshipRegistration.BranchAddress) .SingleAsync(i => i.Student.Id == user.PersonNumber, cancellationToken); var internshipRegistration = internship.InternshipRegistration; @@ -74,7 +79,7 @@ namespace InternshipSystem.Api.Services return new BadRequestObjectResult("Edition doesn't have this type of employment in available employments type"); } - internshipRegistration.Type = registrationQuery.Type ?? internshipRegistration.Type; + internshipRegistration.Type = registrationQuery.Type != null ? edition.AvailableInternshipTypes.Find(ai => ai.Id.Equals(registrationQuery.Type.Id)) : internshipRegistration.Type; await _context.SaveChangesAsync(cancellationToken); return new OkResult(); @@ -88,6 +93,7 @@ namespace InternshipSystem.Api.Services var internship = await _context.Entry(edition) .Collection(e => e.Internships) .Query() + .Include(i => i.Documentation) .SingleAsync(i => i.Student.Id == user.PersonNumber, cancellationToken); var document = Mapper.Map(documentRequest);