public async Task <Guid> SaveDocumentForUserAsync(Guid userId, CreateDocumentDto documentDto)
        {
            var bytes          = Convert.FromBase64String(documentDto.Base64String);
            var stream         = new MemoryStream(bytes);
            var blobIdentifier = await documentStorage.StoreDocument(userId, stream, CancellationToken.None);

            Document document = new Document
            {
                Id             = Guid.NewGuid(),
                UploadedAt     = DateTimeOffset.Now,
                DocumentTime   = documentDto.DocumentTime,
                UserId         = userId,
                ActivityId     = documentDto.ActivityId,
                DocumentType   = documentDto.DocumentType,
                Filename       = documentDto.Filename,
                Mimetype       = documentDto.Mimetype,
                BlobIdentifier = blobIdentifier,
                Title          = documentDto.Title,
                Description    = documentDto.Description
            };

            await documentRepository.InsertAsync(document);

            return(document.Id);
        }
        public void DeleteDocument_ReturnsOK()
        {
            // Arrange
            int    id                  = 123;
            string documentTitle       = "dokument";
            int    categoryId          = 123;
            int    caseId              = 123;
            string documentDescription = "description";
            string documentPath        = "path";
            string documentContent     = "content";

            var document = new CreateDocumentDto()
            {
                DocumentId          = id,
                CaseId              = caseId,
                DocumentTitle       = documentTitle,
                CategoryId          = categoryId,
                DocumentDescription = documentDescription,
                DocumentPath        = documentPath,
                DocumentContent     = documentContent
            };

            var documentRepo = new Mock <IDocumentRepository>();

            documentRepo.Setup(x => x.SaveDocument(document));
            var documentManipulation = new DocumentManipulation(documentRepo.Object);
            var controller           = new DocumentController(documentManipulation);

            // Act
            var result = controller.Delete(id);

            // Assert
            Assert.IsType <OkObjectResult>(result);
        }
예제 #3
0
        protected async Task <string> UploadDocumentsAsync(CreateDocumentDto document)
        {
            List <string> files      = new List <string>();
            string        folderPath = await GetFolderPathAsync(document.Code);

            string uploadFolderPath = await SettingProvider.GetOrNullAsync(DocumentManagementSettings.UploadFilePath);

            if (document.Files != null && document.Files.Any())
            {
                foreach (IFormFile file in document.Files)
                {
                    string filePath = $"{folderPath}/{file.FileName}";
                    document.FolderName = folderPath.Replace(uploadFolderPath, string.Empty);
                    document.LinkFile   = $"/downloadfile/viewfile?sourcedoc={folderPath.Replace(folderPath, string.Empty)}/{file.FileName}";
                    files.Add(file.FileName);
                    await SaveAsAsync(filePath, file);
                }
            }

            if (document.AppendixFiles != null && document.AppendixFiles.Any())
            {
                int index = 0;
                foreach (IFormFile file in document.AppendixFiles)
                {
                    string filePath = $"{folderPath}/{file.FileName}";
                    await SaveAsAsync(filePath, file);

                    document.Appendixes[index].FolderName = folderPath.Replace(uploadFolderPath, string.Empty);
                    document.Appendixes[index].LinkFile   = $"/downloadfile/viewfile?sourcedoc={folderPath.Replace(folderPath, string.Empty)}/{file.FileName}";
                    index++;
                }
            }
            return(string.Join(";", files));
        }
예제 #4
0
        public void DeleteDocument_ReturnsOK()
        {
            // Arrange
            var id                  = 123;
            var documentTitle       = "dokument";
            var categoryId          = 123;
            var caseId              = 123;
            var documentDescription = "description";
            var documentPath        = "path";
            var documentContent     = "content";

            var document = new CreateDocumentDto()
            {
                DocumentId          = id,
                CaseId              = caseId,
                DocumentTitle       = documentTitle,
                CategoryId          = categoryId,
                DocumentDescription = documentDescription,
                DocumentPath        = documentPath,
                DocumentContent     = documentContent
            };

            var documentRepo = new Mock <IDocumentRepository>();

            documentRepo.Setup(x => x.SaveDocument(document));
            var documentManipulation = new DocumentManipulation(documentRepo.Object);
            var logger     = new Mock <Microsoft.Extensions.Logging.ILogger <DocumentController> >().Object;
            var controller = new DocumentController(documentManipulation, logger);
            // Act
            var result = controller.Delete(id);

            // Assert
            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
        }
예제 #5
0
        public async Task <DocumentDto> CreateAndReleaseAsync([FromForm] CreateDocumentDto input)
        {
            var result = await _documentAppService.CreateAsync(input);

            await _documentEmailSenderService.SendMailReleaseDocumentAsync(result);

            return(result);
        }
예제 #6
0
 public string CreateDocument(CreateDocumentDto createDocumentDto)
 {
     context.Documents.Add(new Document
     {
         DocumentName   = createDocumentDto.DocumentName,
         DocumentTypeId = createDocumentDto.DocumentTypeId,
         UserId         = createDocumentDto.UserId
     });
     context.SaveChanges();
     return("Document Created");
 }
예제 #7
0
        public bool SaveDocument(CreateDocumentDto document)
        {
            if (document == null)
            {
                throw new ArgumentException("Document is not valid.");
            }

            var result = _documentRepository.SaveDocument(document);

            return(result != 0);
        }
        public DocumentDetails SaveDocument(CreateDocumentDto document)
        {
            if (document == null)
            {
                throw new NSIException("Document is not valid.");
            }

            var result = _documentRepository.SaveDocument(document);

            return(result);
        }
 public IActionResult Post([FromBody] CreateDocumentDto document)
 {
     try
     {
         DocumentManipulation.SaveDocument(document);
         return(Ok(document));
     }
     catch (Exception ex)
     {
         Logger.Logger.LogError(ex.Message);
         throw new Exception(ex.Message);
     }
 }
 public IActionResult Post([FromBody] CreateDocumentDto document)
 {
     try
     {
         var doc = DocumentManipulation.SaveDocument(document);
         return(Ok(doc));
     }
     catch (Exception ex)
     {
         Logger.LogError(ex.Message);
         throw new NSIException(ex.Message, DC.Exceptions.Enums.Level.Error, DC.Exceptions.Enums.ErrorType.InvalidParameter);
     }
 }
        public static CreateTorrentDto CreateTorrent(CreateTorrentWidgetModel model)
        {
            CreateImageDto    image    = CreateImage(model);
            CreateDocumentDto document = CreateDocument(model);

            return(new CreateTorrentDto
            {
                Title = model.Title,
                Description = model.Description,
                AdditionalInfo = model.AdditionalInfo,
                Genres = model.Genres,
                ImageDto = image,
                DocumentDto = document
            });
        }
 int IDocumentRepository.SaveDocument(CreateDocumentDto document)
 {
     try
     {
         document.DocumentId = 0;
         var documentEntity = DocumentRepository.MapToDbEntity(document, _dbContext);
         _dbContext.Add(documentEntity);
         var result = _dbContext.SaveChanges();
         AddToHistory(documentEntity);
         return(result);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
예제 #13
0
 DocumentDetails IDocumentRepository.SaveDocument(CreateDocumentDto document)
 {
     try
     {
         document.DocumentId = 0;
         var documentEntity = DocumentRepository.MapToDbEntity(document, _dbContext);
         _dbContext.Add(documentEntity);
         _dbContext.SaveChanges();
         AddToHistory(documentEntity);
         return(DocumentRepository.MapToDbEntity(documentEntity));
     }
     catch (Exception ex)
     {
         Logger.Logger.LogError(ex.Message);
         throw new NSIException(ex.Message, DC.Exceptions.Enums.Level.Error, DC.Exceptions.Enums.ErrorType.InvalidParameter);
     }
 }
예제 #14
0
 public static Document MapToDbEntity(CreateDocumentDto document, IkarusContext _dbContext)
 {
     return(new Document()
     {
         CaseId = document.DocumentId,
         DocumentId = document.DocumentId,
         DocumentCategoryId = document.CategoryId,
         DocumentContent = document.DocumentContent,
         DocumentPath = document.DocumentPath,
         DocumentCategory = _dbContext.DocumentCategory.FirstOrDefault(d => d.DocumentCategoryId == document.CategoryId),
         Description = document.DocumentDescription,
         Case = _dbContext.CaseInfo.FirstOrDefault(c => c.CaseId == document.CaseId),
         // Work here
         FileType = _dbContext.FileType.FirstOrDefault(),
         FileTypeId = 1,
         DocumentHistory = _dbContext.DocumentHistory.Where(d => d.DocumentId == document.DocumentId).ToList(),
         CreatedByUser = _dbContext.UserInfo.FirstOrDefault(),
         CreatedByUserId = _dbContext.UserInfo.FirstOrDefault().UserId,
         Title = document.DocumentTitle
     });
 }
예제 #15
0
        public Document CreateDocumentNativeAPI(CreateDocumentDto createDocumentDto)
        {
            //The document is created as master. The masterDocumentId is assigned to the master version.
            LibrariesManager librariesManager = LibrariesManager.GetManager();
            Guid             documentId       = Guid.NewGuid();
            Document         document         = document = librariesManager.CreateDocument(documentId);

            //Set the parent document library.
            DocumentLibrary documentLibrary = librariesManager.GetDocumentLibraries().SingleOrDefault();

            document.Parent = documentLibrary;

            //Set the properties of the document.
            document.Title            = createDocumentDto.Title;
            document.DateCreated      = DateTime.UtcNow;
            document.PublicationDate  = DateTime.UtcNow;
            document.LastModified     = DateTime.UtcNow;
            document.UrlName          = Regex.Replace($"{createDocumentDto.Title}-{documentId}".ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
            document.MediaFileUrlName = Regex.Replace(createDocumentDto.FileName.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");

            //Upload the document file.
            librariesManager.Upload(document, createDocumentDto.Stream, createDocumentDto.FileExtension);

            //Recompiles and validates the url of the document.
            librariesManager.RecompileAndValidateUrls(document);

            //Save the changes.
            librariesManager.SaveChanges();

            //Publish the DocumentLibraries item. The live version acquires new ID.
            var bag = new Dictionary <string, string>();

            bag.Add("ContentType", typeof(Document).FullName);
            WorkflowManager.MessageWorkflow(documentId, typeof(Document), null, "Publish", false, bag);

            return(document);
        }
예제 #16
0
        public IActionResult CreateDocument([FromBody] CreateDocumentDto createDocumentDto)
        {
            var result = this.documentService.CreateDocument(createDocumentDto);

            return(new OkObjectResult(result));
        }
예제 #17
0
 public async Task <DocumentDto> CreateAsync([FromForm] CreateDocumentDto input)
 {
     return(await _documentAppService.CreateAsync(input));
 }
예제 #18
0
        public async Task <ActionResult> CreateDocument([FromBody] CreateDocumentDto document)
        {
            var result = await documentsInteractor.SaveDocumentForUserAsync(currentUserInformation.UserId, document);

            return(Ok(result));
        }