private DocumentDto UpdateDocumentFile(UpdateFileToDocumentCommand cmd, FileInfo file, string text)
 {
     SaveTextFile(file, text);
     return(repository
            .UpdateDocumentFile(cmd.DocumentId, file.Name, IssueAnalizer.ObtenerAsunto(text))
            .ToDocumentDto());
 }
        private DocumentDto PerformSideEffect(UpdateFileToDocumentCommand cmd)
        {
            // eliminar el archivo anterior
            var oldFile = repository.GetFileIfExist(cmd.DocumentId);

            if (oldFile != null)
            {
                DeleteFilesInOs(oldFile);
            }
            // crear el archivo nuevo
            var test = from file in SaveFile(cmd.File)
                       from text in new OcrPdfToText().GetText(file)
                       select UpdateDocumentFile(cmd, file, text);

            return(test.Try().Match(x => x, e => throw e));
        }
 private Validation <Error, UpdateFileToDocumentCommand> ValidateUpdateFileToDocumentCommand(UpdateFileToDocumentCommand cmd)
 => from x in ValidateNonNull(cmd)
 from y in ValidateFile(x)
 select cmd;
 public Try <Validation <Error, DocumentDto> > Execute(UpdateFileToDocumentCommand cmd)
 => ()
 => from x in ValidateUpdateFileToDocumentCommand(cmd)
 select PerformSideEffect(x);