diff --git a/src/InternshipSystem.Api/Controllers/DocumentsController.cs b/src/InternshipSystem.Api/Controllers/DocumentsController.cs index 7cda5aa..bb124db 100644 --- a/src/InternshipSystem.Api/Controllers/DocumentsController.cs +++ b/src/InternshipSystem.Api/Controllers/DocumentsController.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -63,8 +64,15 @@ namespace InternshipSystem.Api.Controllers .Include(i => i.Documentation) .FirstAsync(i => i.Student.Id == user.PersonNumber, cancellationToken); - internship.AddNewDocument(documentRequest.Description, documentRequest.Type); - await _context.SaveChangesAsync(cancellationToken); + try + { + internship.AddNewDocument(documentRequest.Description, documentRequest.Type); + await _context.SaveChangesAsync(cancellationToken); + } + catch (ArgumentException e) + { + return BadRequest(e.Message); + } return Ok(); } diff --git a/src/InternshipSystem.Api/Controllers/EditionController.cs b/src/InternshipSystem.Api/Controllers/EditionController.cs index 40834d4..35a4bc9 100644 --- a/src/InternshipSystem.Api/Controllers/EditionController.cs +++ b/src/InternshipSystem.Api/Controllers/EditionController.cs @@ -72,7 +72,7 @@ namespace InternshipSystem.Api.Controllers var edition = await Context.Editions .Where(e => e.Id == id) - .ProjectTo(Mapper.ConfigurationProvider) + .ProjectTo(Mapper.ConfigurationProvider) .FirstOrDefaultAsync(token); if (edition == null) diff --git a/src/InternshipSystem.Api/Result/EditionResult.cs b/src/InternshipSystem.Api/Result/EditionResult.cs index 5e91432..73b2a58 100644 --- a/src/InternshipSystem.Api/Result/EditionResult.cs +++ b/src/InternshipSystem.Api/Result/EditionResult.cs @@ -2,7 +2,7 @@ namespace InternshipSystem.Api.Result { - public struct EditionResult + public class EditionResult { public Guid Id { get; set; } public DateTime EditionStart { get; set; } diff --git a/src/InternshipSystem.Core/Entity/Internship/Internship.cs b/src/InternshipSystem.Core/Entity/Internship/Internship.cs index 3d148f4..c2104e6 100644 --- a/src/InternshipSystem.Core/Entity/Internship/Internship.cs +++ b/src/InternshipSystem.Core/Entity/Internship/Internship.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using InternshipSystem.Core.ValueObject; @@ -31,6 +32,11 @@ namespace InternshipSystem.Core.Entity.Internship public void AddNewDocument(string description, DocumentType type) { + if (Documentation.Any(d => d.Type == type)) + { + throw new ArgumentException("Internship already has a document of given type"); + } + var document = new Document { Description = description,