fix double registration (#71)
fix double registration Co-authored-by: MaxchilKH <m.w.bohdanowicz@gmail.com>
This commit is contained in:
parent
2da7349578
commit
80dda549bf
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user