Merge pull request 'SubmitRegistrationForm - fixes' (#49) from MoreEndpoints into master
This commit is contained in:
commit
1899b934b0
@ -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;
|
||||
|
@ -25,11 +25,16 @@ namespace InternshipSystem.Api.Services
|
||||
public async Task<ActionResult> 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<Document>(documentRequest);
|
||||
|
Loading…
Reference in New Issue
Block a user