From 7fc9eef6375e1448d8f4b3cf87563261540a7b35 Mon Sep 17 00:00:00 2001 From: MaxchilKH Date: Wed, 11 Nov 2020 17:03:35 +0100 Subject: [PATCH 1/2] dum dum --- .../Controllers/DocumentsController.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/InternshipSystem.Api/Controllers/DocumentsController.cs b/src/InternshipSystem.Api/Controllers/DocumentsController.cs index f680c0f..7b7b715 100644 --- a/src/InternshipSystem.Api/Controllers/DocumentsController.cs +++ b/src/InternshipSystem.Api/Controllers/DocumentsController.cs @@ -101,14 +101,13 @@ namespace InternshipSystem.Api.Controllers var document = internship.Documentation.First(d => d.Id == documentId); - document.Scan = new DocumentScan - { - File = memoryStream.ToArray(), - Size = memoryStream.Length, - Filename = documentScan.FileName, - Mime = _fileValidator.GetFileMime(memoryStream.ToArray()) - }; - + document.Scan ??= new DocumentScan(); + + document.Scan.Size = memoryStream.Length; + document.Scan.Filename = documentScan.FileName; + document.Scan.Mime = _fileValidator.GetFileMime(memoryStream.ToArray()); + document.Scan.File = memoryStream.ToArray(); + document.State = DocumentState.Submitted; await _context.SaveChangesAsync(cancellationToken); -- 2.45.2 From b80372b367962ceb7b4ab6fdd11d81de2ca4dcb2 Mon Sep 17 00:00:00 2001 From: MaxchilKH Date: Thu, 12 Nov 2020 00:26:17 +0100 Subject: [PATCH 2/2] form --- .../Controllers/DocumentsController.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/InternshipSystem.Api/Controllers/DocumentsController.cs b/src/InternshipSystem.Api/Controllers/DocumentsController.cs index 7b7b715..88ca5dd 100644 --- a/src/InternshipSystem.Api/Controllers/DocumentsController.cs +++ b/src/InternshipSystem.Api/Controllers/DocumentsController.cs @@ -96,10 +96,14 @@ namespace InternshipSystem.Api.Controllers await _context.Entry(edition) .Collection(e => e.Internships) .Query() - .Include(i => i.Documentation) + .Include(i => i.Documentation) .FirstAsync(i => i.Student.Id == user.PersonNumber, cancellationToken); - var document = internship.Documentation.First(d => d.Id == documentId); + var document = await _context.Entry(internship) + .Collection(i => i.Documentation) + .Query() + .Include(d => d.Scan) + .FirstAsync(d => d.Id == documentId, cancellationToken); document.Scan ??= new DocumentScan(); @@ -109,7 +113,7 @@ namespace InternshipSystem.Api.Controllers document.Scan.File = memoryStream.ToArray(); document.State = DocumentState.Submitted; - + await _context.SaveChangesAsync(cancellationToken); return Ok(); -- 2.45.2