public DsMessage EnviarArquivo(string NomeDocumento, List <DsKeyword> ChavesDocumento, DsFile arquivo) { var docTypeId = ConvertTo.DocTypeId(NomeDocumento); if (!docTypeId.HasValue) { throw new InvalidCastException("Tipo de documento inválido!"); } if (docTypeId.Value == 65) { var novoDocumento = documentProxy.Create( new DS3Connector.DTO.CreateDocument <BoxInfo>() { Attachments = new List <DS3Connector.DTO.CreateDocumentAttachment>() { new DS3Connector.DTO.CreateDocumentAttachment() { Base64 = System.Convert.ToBase64String(arquivo.FileData), } }, DocumentInfo = ConvertTo.BoxInfo(ChavesDocumento), } ); return(new DsMessage(novoDocumento.Message, (novoDocumento.Status == SUCCESS ? 0 : 500))); } else { var novoDocumento = documentProxy.Create( new DS3Connector.DTO.CreateDocument <ProcessInfo>() { Attachments = new List <DS3Connector.DTO.CreateDocumentAttachment>() { new DS3Connector.DTO.CreateDocumentAttachment() { Base64 = System.Convert.ToBase64String(arquivo.FileData), } }, DocumentInfo = ConvertTo.ProcessInfo(ChavesDocumento), } ); return(new DsMessage(novoDocumento.Message, (novoDocumento.Status == SUCCESS ? 0 : 500))); } }
public DsMessage updFile(string NomeDocumento, List <DsKeyword> ChavesDocumento, List <DsKeyword> ChavesDocumentoAtualizar, DsFile arquivo) { var docTypeId = ConvertTo.DocTypeId(NomeDocumento); if (!docTypeId.HasValue) { throw new InvalidCastException("Tipo de documento inválido!"); } //Searh Old Document if (docTypeId.Value == 65) { var documentList = documentProxy.Search(new DS3Connector.DTO.SearchRequest <IBoxSearchRequest>() { DocumentInfo = ConvertTo.BoxInfo(ChavesDocumento) }); if (documentList.Status == SUCCESS && documentList.Data != null && documentList.Data.Count > 0 && documentList.Data.First().Attachments.Count > 0) { for (var i = 0; i < documentList.Data.First().Attachments.Count; i++) { var resultDelete = attachProxy.Delete(new DS3Connector.DTO.EditAttach <BoxInfo>() { Id = documentList.Data.First().Attachments[i].Id }); if (resultDelete.Status != SUCCESS) { throw new ApplicationException(resultDelete.Message); } } } var resultadoUpdate = documentProxy.Update(new DS3Connector.DTO.UpdateDocument <BoxInfo>() { DocumentInfo = ConvertTo.BoxInfo(ChavesDocumento), NewDocumentInfo = ConvertTo.BoxInfo(ChavesDocumentoAtualizar), Attachments = new List <DS3Connector.DTO.CreateDocumentAttachment>() { new DS3Connector.DTO.CreateDocumentAttachment() { Base64 = System.Convert.ToBase64String(arquivo.FileData) } } }); return(new DsMessage(resultadoUpdate.Message, (resultadoUpdate.Status == SUCCESS ? 0 : 500))); } else { var documentList = documentProxy.Search(new DS3Connector.DTO.SearchRequest <IProcessSearchRequest>() { DocumentInfo = ConvertTo.ProcessInfo(ChavesDocumento) }); if (documentList.Status == SUCCESS && documentList.Data != null && documentList.Data.Count > 0 && documentList.Data.First().Attachments.Count > 0) { for (var i = 0; i < documentList.Data.First().Attachments.Count; i++) { var resultDelete = attachProxy.Delete(new DS3Connector.DTO.EditAttach <ProcessInfo>() { Id = documentList.Data.First().Attachments[i].Id }); if (resultDelete.Status != SUCCESS) { throw new ApplicationException(resultDelete.Message); } } } var resultadoUpdate = documentProxy.Update(new DS3Connector.DTO.UpdateDocument <ProcessInfo>() { DocumentInfo = ConvertTo.ProcessInfo(ChavesDocumento), NewDocumentInfo = ConvertTo.ProcessInfo(ChavesDocumentoAtualizar), Attachments = new List <DS3Connector.DTO.CreateDocumentAttachment>() { new DS3Connector.DTO.CreateDocumentAttachment() { Base64 = System.Convert.ToBase64String(arquivo.FileData) } } }); return(new DsMessage(resultadoUpdate.Message, (resultadoUpdate.Status == SUCCESS ? 0 : 500))); } }