fix double registration #71

Merged
maxchil merged 1 commits from fix/registration into master 2020-10-27 20:57:52 +01:00
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);
edition.RegisterInternship(student);
await _context.SaveChangesAsync(token);
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);