This repository has been archived by the owner on Jan 17, 2024. It is now read-only.
forked from 18F/dol-whd-14c
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from AppliedIS/feature-removesave
Feature removesave
- Loading branch information
Showing
35 changed files
with
852 additions
and
294 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.IO; | ||
using DOL.WHD.Section14c.Domain.Models.Submission; | ||
using DOL.WHD.Section14c.Domain.ViewModels; | ||
|
||
namespace DOL.WHD.Section14c.Business | ||
{ | ||
public interface IAttachmentService : IDisposable | ||
{ | ||
Attachment UploadAttachment(string EIN, MemoryStream memoryStream, string fileName, string fileType); | ||
AttachementDownload DownloadAttachment(MemoryStream memoryStream, string EIN, Guid fileId); | ||
void DeleteAttachement(string EIN, Guid fileId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System; | ||
using System.Data; | ||
using System.IO; | ||
using System.Linq; | ||
using DOL.WHD.Section14c.DataAccess; | ||
using DOL.WHD.Section14c.Domain.Models.Submission; | ||
using DOL.WHD.Section14c.Domain.ViewModels; | ||
|
||
namespace DOL.WHD.Section14c.Business.Services | ||
{ | ||
public class AttachmentService : IAttachmentService | ||
{ | ||
private readonly IFileRepository _fileRepository; | ||
private readonly IAttachmentRepository _attachmentRepository; | ||
|
||
public AttachmentService(IFileRepository fileRepository, IAttachmentRepository attachmentRepository) | ||
{ | ||
_fileRepository = fileRepository; | ||
_attachmentRepository = attachmentRepository; | ||
} | ||
|
||
public Attachment UploadAttachment(string EIN, MemoryStream memoryStream, string fileName, string fileType) | ||
{ | ||
var fileUpload = new Attachment() | ||
{ | ||
FileSize = memoryStream.Length, | ||
MimeType = fileType, | ||
OriginalFileName = fileName, | ||
Deleted = false, | ||
EIN = EIN | ||
}; | ||
|
||
fileUpload.RepositoryFilePath = $@"{EIN}\{fileUpload.Id}"; | ||
|
||
_fileRepository.Upload(memoryStream, fileUpload.RepositoryFilePath); | ||
|
||
_attachmentRepository.Add(fileUpload); | ||
_attachmentRepository.SaveChanges(); | ||
|
||
return fileUpload; | ||
} | ||
|
||
public AttachementDownload DownloadAttachment(MemoryStream memoryStream, string EIN, Guid fileId) | ||
{ | ||
var attachment = _attachmentRepository.Get() | ||
.Where(x => x.EIN == EIN) | ||
.SingleOrDefault(x => x.Deleted == false && x.Id == fileId); | ||
|
||
if (attachment == null) | ||
throw new ObjectNotFoundException(); | ||
|
||
var stream = _fileRepository.Download(memoryStream, attachment.RepositoryFilePath); | ||
|
||
return new AttachementDownload() | ||
{ | ||
MemoryStream = stream, | ||
Attachment = attachment | ||
}; | ||
} | ||
|
||
public void DeleteAttachement(string EIN, Guid fileId) | ||
{ | ||
var attachment = _attachmentRepository.Get() | ||
.Where(x => x.EIN == EIN) | ||
.SingleOrDefault(x => x.Deleted == false && x.Id == fileId); | ||
|
||
if (attachment == null) | ||
throw new ObjectNotFoundException(); | ||
|
||
attachment.Deleted = true; | ||
|
||
_attachmentRepository.SaveChanges(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_attachmentRepository.Dispose(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.