fix double registration

This commit is contained in:
MaxchilKH 2020-10-27 20:56:57 +01:00
parent 2da7349578
commit d839cc4fcb
2 changed files with 14 additions and 2 deletions

View File

@ -47,8 +47,15 @@ namespace InternshipSystem.Api.Controllers
var student = await _context.Students.FindAsync(user.PersonNumber);
try
{
edition.RegisterInternship(student);
await _context.SaveChangesAsync(token);
}
catch (ArgumentException e)
{
return BadRequest(e.Message);
}
return Ok();
}

View File

@ -31,6 +31,11 @@ namespace InternshipSystem.Core
public void RegisterInternship(Student student)
{
if (Internships.Any(i => i.Student.Id == student.Id))
{
throw new ArgumentException("error.registration.already_registered");
}
var internship = Internship.CreateStudentsInternship(student);
Internships.Add(internship);