Exemple #1
0
        public HttpResponseMessage DeleteAttachment(long docId)
        {
            AttachmentViewModel viewModel = new AttachmentViewModel()
            {
                DocumentID = docId
            };

            var successMessage = string.Empty;

            try
            {
                AttachmentResponse resonse = docrepositoryService.DeleteAttachment(
                    new AttachmentRequest()
                {
                    AttachmentViewModel = viewModel
                });

                if (resonse.Exception != null)
                {
                    successMessage = resonse.Exception.Message;
                }
                else
                {
                    successMessage = "Successfully Deleted Attachement";
                }
            }
            catch (Exception ex)
            {
                successMessage = ex.Message;
            }


            return(Request.CreateResponse(successMessage));
        }
        public void DeleteAttachment_ByGuidAndKey_Should_DeleteAttachment()
        {
            // ARRANGE
            _mockAttachmentRepository.Setup(x =>
                                            x.IsAttachmentAllowedToDelete(It.IsAny <string>(), It.IsAny <Uri>(), It.IsAny <Uri>(), It.IsAny <Uri>()))
            .Returns(true);

            var guid              = Guid.NewGuid();
            var fileName          = "total+cool filename.jpg";
            var expectedObjectUrl = $"http://{guid}/{fileName}";

            _mockAwsS3Service.Setup(x => x.GenerateS3ObjectUrl(It.IsAny <string>(), guid.ToString(), fileName))
            .Returns(expectedObjectUrl);

            var interceptedKeyName = string.Empty;

            _mockAwsS3Service.Setup(x => x.DeleteFileAsync(It.IsAny <string>(), It.IsAny <string>()))
            .Callback <string, string>((bucket, key) => interceptedKeyName = key);

            // ACT
            _service.DeleteAttachment(guid, fileName);

            // ASSERT
            _mockAwsS3Service.Verify(x => x.DeleteFileAsync(It.IsAny <string>(), It.IsAny <string>()), Times.Once);
            _mockAttachmentRepository.Verify(x => x.DeleteEntity(It.IsAny <string>(), It.IsAny <Uri>()), Times.Exactly(2));
            Assert.Equal(expectedObjectUrl.Replace("http://", ""), interceptedKeyName);
        }
Exemple #3
0
        /// <summary>
        /// Deletes the attachment.
        /// </summary>
        /// <param name="docId">The document identifier.</param>
        /// <returns></returns>
        public ActionResult DeleteAttachment(long docId)
        {
            AttachmentViewModel viewModel = new AttachmentViewModel()
            {
                DocumentID = docId
            };

            attachmentService.DeleteAttachment(
                new AttachmentRequest()
            {
                AttachmentViewModel = viewModel
            });
            return(Json(new { success = true, response = "" }, JsonRequestBehavior.AllowGet));
        }
Exemple #4
0
        public async Task DeleteGetAttachmentsTest()
        {
            Workspace workspace = await CreateWorkspace();

            List <Attachment> attachments = await service.GetAttachments(workspace.Id);

            Assert.IsFalse(attachments.Any());
            await UploadAttachment(workspace);

            attachments = await service.GetAttachments(workspace.Id);

            foreach (Attachment attachment in attachments)
            {
                Assert.NotNull(attachment.Id);
            }
            await service.DeleteAttachment(workspace.Id, filename);

            List <Attachment> newList = await service.GetAttachments(workspace.Id);

            Assert.True(newList.Count == attachments.Count - 1);
            await DeleteWorkspace(workspace);
        }
Exemple #5
0
        public async Task <JsonResult> RemoveAttachmentSingle([FromHeader] int accountId, [FromRoute] int attachmentId, [FromRoute] int tokenId)
        {
            var attachment = await _attachmentService.GetAttachmentById(attachmentId);

            if (attachment == null)
            {
                return(new JsonResult(new JsonResponse {
                    Result = SharedEnums.RequestResults.Failed, Message = "An issue happened while getting data."
                }));
            }

            var removeResult = await _attachmentService.DeleteAttachment(attachment);

            if (!removeResult.HasValue || !removeResult.Value)
            {
                return(new JsonResult(new JsonResponse {
                    Result = SharedEnums.RequestResults.Failed, Message = "An issue happened while removing data."
                }));
            }

            if (attachment.AttachmentType == (byte)SharedEnums.AttachmentTypes.Address || attachment.IsHttp)
            {
                return(new JsonResult(new JsonResponse {
                    Result = SharedEnums.RequestResults.Success
                }));
            }

            var httpResult = await _fileService.SendDeleteFilesRequestToRoutinizeStorageApi(
                tokenId, accountId, attachment.ItemId, new[] { Helpers.ExtractImageNameFromPath(attachment.AttachmentUrl) }
                );

            return(httpResult.Error ? new JsonResult(new JsonResponse {
                Result = SharedEnums.RequestResults.Partial
            })
                                    : new JsonResult(new JsonResponse {
                Result = SharedEnums.RequestResults.Success
            }));
        }
        public async Task <IActionResult> DeleteAttachment([FromQuery] Guid guid, [FromQuery] string fileName)
        {
            await _attachmentService.DeleteAttachment(guid, fileName);

            return(NoContent());
        }