diff --git a/src/InternshipSystem.Api/Controllers/DocumentsController.cs b/src/InternshipSystem.Api/Controllers/DocumentsController.cs index 2f59065..7cda5aa 100644 --- a/src/InternshipSystem.Api/Controllers/DocumentsController.cs +++ b/src/InternshipSystem.Api/Controllers/DocumentsController.cs @@ -1,6 +1,5 @@ using System.IO; using System.Linq; -using System.Net.Mime; using System.Threading; using System.Threading.Tasks; using InternshipSystem.Api.Queries; @@ -61,9 +60,11 @@ namespace InternshipSystem.Api.Controllers await _context.Entry(edition) .Collection(e => e.Internships) .Query() + .Include(i => i.Documentation) .FirstAsync(i => i.Student.Id == user.PersonNumber, cancellationToken); internship.AddNewDocument(documentRequest.Description, documentRequest.Type); + await _context.SaveChangesAsync(cancellationToken); return Ok(); } @@ -86,14 +87,12 @@ namespace InternshipSystem.Api.Controllers await _context.Entry(edition) .Collection(e => e.Internships) .Query() + .Include(i => i.Documentation) .FirstAsync(i => i.Student.Id == user.PersonNumber, cancellationToken); - var document = await _context.Entry(internship) - .Collection(i => i.Documentation) - .Query() - .FirstOrDefaultAsync(d => d.Id == documentId, cancellationToken); + var document = internship.Documentation.First(d => d.Id == documentId); - document.Scan = memoryStream.ToArray(); + document.Scan = new DocumentScan { File = memoryStream.ToArray() }; document.State = DocumentState.Submitted; await _context.SaveChangesAsync(cancellationToken); @@ -117,9 +116,10 @@ namespace InternshipSystem.Api.Controllers await _context.Entry(internship) .Collection(i => i.Documentation) .Query() + .Include(d => d.Scan) .FirstOrDefaultAsync(d => d.Id == documentId, cancellationToken); - var stream = new MemoryStream(document.Scan); + var stream = new MemoryStream(document.Scan.File); return File(stream, "application/pdf"); } diff --git a/src/InternshipSystem.Core/Entity/Document.cs b/src/InternshipSystem.Core/Entity/Document.cs index 3cda75c..d98bb74 100644 --- a/src/InternshipSystem.Core/Entity/Document.cs +++ b/src/InternshipSystem.Core/Entity/Document.cs @@ -6,9 +6,16 @@ namespace InternshipSystem.Core { public long Id { get; set; } public string Description { get; set; } - public byte[] Scan { get; set; } + public DocumentScan Scan { get; set; } public DocumentType Type { get; set; } public DocumentState State { get; set; } public string RejectionReason { get; set; } } + + public class DocumentScan + { + public long DocumentId { get; set; } + public Document Document { get; set; } + public byte[] File { get; set; } + } } \ No newline at end of file diff --git a/src/InternshipSystem.Core/Entity/Internship/Internship.cs b/src/InternshipSystem.Core/Entity/Internship/Internship.cs index 91ff865..3d148f4 100644 --- a/src/InternshipSystem.Core/Entity/Internship/Internship.cs +++ b/src/InternshipSystem.Core/Entity/Internship/Internship.cs @@ -45,8 +45,8 @@ namespace InternshipSystem.Core.Entity.Internship { var document = Documentation.First(d => d.Id == documentId); - document.Scan = documentScan; - document.State = DocumentState.Submitted; + // document.Scan = documentScan; + // document.State = DocumentState.Submitted; } } } \ No newline at end of file