public static AttachmentItemModel GetSampleData_AttachmentItem(int attachmentId) { var result = new AttachmentItemModel { AttachmentId = attachmentId, Filename = "filename.pdf", ContentType = "application/pdf" }; return(result); }
public async Task<ActionResult<AttachmentItemModel>> GetAttachmentDetails(int attachmentId) { if (attachmentId < 0) { return UnprocessableEntity($"Invalid AttachmentId: {attachmentId}"); } AttachmentItemModel attachmentItem = await _attachmentsService.RetrieveAsync(attachmentId); if (attachmentItem is null) { return NotFound(); } return Ok(attachmentItem); }
public async Task<IActionResult> DownloadAttachment(int attachmentId) { if (attachmentId < 1) { return UnprocessableEntity($"Invalid AttachmentId: {attachmentId}"); } AttachmentItemModel attachmentItem = await _attachmentsService.RetrieveAsync(attachmentId); if (attachmentItem is null) { return NotFound(); } byte[] attachmentFile = await _attachmentsService.DownloadAsync(attachmentId); return File(attachmentFile, attachmentItem.ContentType, attachmentItem.Filename); }