/// <summary>
        /// Find attachments that are not in the file system based on the application Id
        /// </summary>
        /// <param name="application">Application Object</param>
        /// <returns>List of attachments not exist in the file system</returns>
        public List <VerifyAttachmentViewModel> FindAllApplicationAttachmentsNotExistInFileSystem(ApplicationSubmission application)
        {
            List <VerifyAttachmentViewModel> attachmentNotExists = new List <VerifyAttachmentViewModel>();
            var allAttachments = _attachmentService.GetApplicationAttachments(ref application);

            foreach (var attachment in allAttachments)
            {
                if (attachment.Value != null)
                {
                    // Remove attachment Id from the DB
                    // Notify aplication attachment does not exist
                    using (var outMemoryStream = new MemoryStream())
                    {
                        try
                        {
                            // Check if the attachment exist in the file system
                            _attachmentService.DownloadAttachment(outMemoryStream, application.Id, new Guid(attachment.Value.Id));
                        }
                        catch
                        {
                            // Attachment does not exist in the file system
                            attachmentNotExists.Add(new VerifyAttachmentViewModel()
                            {
                                AttachmentId = attachment.Value.Id, AttachmentName = attachment.Value.OriginalFileName
                            });
                            // Remove attachment from datadase
                            _attachmentService.DeleteAttachement(application.Id, new Guid(attachment.Value.Id));
                        }
                    }
                }
            }
            return(attachmentNotExists);
        }
Пример #2
0
        public async Task DownloadAttachmentTest()
        {
            Workspace workspace = await CreateWorkspace();

            Attachment attachment = await UploadAttachment(workspace);

            Stream fileStream = await service.DownloadAttachment(workspace.Id, filename);

            Assert.True(fileStream.Length == attachment.Size);
            await DeleteWorkspace(workspace);
        }
        public IHttpActionResult Download(string ApplicationId, Guid fileId)
        {
            AccountController account = new AccountController(_employerService, _organizationService, _identityService);

            account.UserManager = UserManager;
            var userInfo = account.GetUserInfo();
            // make sure user has rights to the Id
            var hasPermission     = _identityService.HasSavePermission(userInfo, ApplicationId);
            var hasViewAllFeature = _identityService.UserHasFeatureClaim(User, ApplicationClaimTypes.ViewAllApplications);

            if (!hasPermission && !hasViewAllFeature)
            {
                Unauthorized("User doesn't have rights to download attachments from this Id");
            }

            var result = new HttpResponseMessage(HttpStatusCode.OK);

            try
            {
                var memoryStream = new MemoryStream();  // Disponsed by Framework

                var attachmentDownload = _attachmentService.DownloadAttachment(memoryStream, ApplicationId, fileId);

                result.Content = new StreamContent(attachmentDownload.MemoryStream); // Disponsed by Framework

                result.Content.Headers.ContentType        = new MediaTypeHeaderValue(attachmentDownload.Attachment.MimeType);
                result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                {
                    FileName = attachmentDownload.Attachment.OriginalFileName
                };
            }
            catch (Exception ex)
            {
                if (ex is ObjectNotFoundException || ex is FileNotFoundException)
                {
                    NotFound("Not found");
                }

                throw;
            }
            return(ResponseMessage(result)); //result;
        }
Пример #4
0
        public IHttpActionResult Download(string EIN, Guid fileId)
        {
            // make sure user has rights to the EIN or has View All Application rights
            var hasEINClaim       = _identityService.UserHasEINClaim(User, EIN);
            var hasViewAllFeature = _identityService.UserHasFeatureClaim(User, ApplicationClaimTypes.ViewAllApplications);

            if (!hasEINClaim && !hasViewAllFeature)
            {
                Unauthorized("User doesn't have rights to download attachments from this EIN");
            }

            var result = new HttpResponseMessage(HttpStatusCode.OK);

            try
            {
                var memoryStream = new MemoryStream();  // Disponsed by Framework

                var attachmentDownload = _attachmentService.DownloadAttachment(memoryStream, EIN, fileId);

                result.Content = new StreamContent(attachmentDownload.MemoryStream); // Disponsed by Framework

                result.Content.Headers.ContentType        = new MediaTypeHeaderValue(attachmentDownload.Attachment.MimeType);
                result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                {
                    FileName = attachmentDownload.Attachment.OriginalFileName
                };
            }
            catch (Exception ex)
            {
                if (ex is ObjectNotFoundException || ex is FileNotFoundException)
                {
                    NotFound("Not found");
                }

                throw;
            }
            return(ResponseMessage(result)); //result;
        }