public Task <bool> GetUrlFileGoogleDrive(string id, string permissionValue, string userRule) { return(Task.Run(() => { DriveApiService googleApiDrive = new DriveApiService(); var data = googleApiDrive.FileSharePermission(id, permissionValue, userRule); return data; })); }
public Task Delete(BE_TxRegistroDocumento entidad) { return(Task.Run(() => { DriveApiService googleApiDrive = new DriveApiService(); googleApiDrive.Remove(entidad.IdGoogleDrive); Delete(entidad, SP_DELETE); })); }
public async Task <BE_MemoryStream> GetDownloadFileGoogleDrive(BE_TxRegistroDocumento entidad) { DriveApiService googleApiDrive = new DriveApiService(); var data = await googleApiDrive.Download(entidad.IdGoogleDrive); return(data); }
public Task <IEnumerable <BE_GoogleDriveFiles> > GetGoogleDriveFilesPorId(BE_GoogleDriveFiles entidad) { return(Task.Run(() => { DriveApiService apiService = new DriveApiService(); var lista = apiService.GetFolderChildren(entidad.IdGoogleDrive); return lista; })); }
public Task <BE_ResultadoTransaccion> Update(BE_TxRegistroDocumento entidad) { return(Task.Run(() => { BE_ResultadoTransaccion vResultadoTransaccion = new BE_ResultadoTransaccion(); vResultadoTransaccion.ResultadoCodigo = 1; try { DriveApiService driveApiService = new DriveApiService(); var resp = driveApiService.MoveFile(entidad.IdGoogleDrive, entidad.IdGoogleDriveFolder); if (resp.Result == 0) { vResultadoTransaccion.ResultadoCodigo = -1; vResultadoTransaccion.ResultadoDescripcion = "Ocurrio un error al mover archivo en el google drive"; return vResultadoTransaccion; } } catch (Exception ex) { vResultadoTransaccion.ResultadoCodigo = -1; vResultadoTransaccion.ResultadoDescripcion = ex.Message.ToString(); return vResultadoTransaccion; } try { entidad.IdGoogleDrive = null; entidad.IdGoogleDriveFolder = null; Update(entidad, SP_UPDATESTATUS); } catch (Exception ex) { vResultadoTransaccion.ResultadoCodigo = -1; vResultadoTransaccion.ResultadoDescripcion = ex.Message.ToString(); return vResultadoTransaccion; } return vResultadoTransaccion; })); }
//public async Task<BE_File> GetDownloadFileGoogleDriveBase64(BE_TxRegistroDocumento entidad) //{ // DriveApiService googleApiDrive = new DriveApiService(); // var data = await googleApiDrive.Download(entidad.IdGoogleDrive); // byte[] bytes; // bytes = data.FileMemoryStream.ToArray(); // string base64 = Convert.ToBase64String(bytes); // return new BE_File { // FileBase64 = base64, // Name = data.NameFile, // Type = data.TypeFile // }; //} public async Task <BE_File> GetDownloadFileGoogleDriveSave(BE_TxRegistroDocumento entidad) { DriveApiService googleApiDrive = new DriveApiService(); var data = await googleApiDrive.Download(entidad.IdGoogleDrive); byte[] bytes; bytes = data.FileMemoryStream.ToArray(); var nombreAleatorio = GenerarCodigo(); /* * Desarrollo \\\\SERVIDOR95\\Users\\InvetsaNet\\Documents\\Auditoria\\INCUBA-FrontEnd\\src\\assets\\file-pdf\\ * Produccion \\\\SERVIDOR96\\Users\\adminauditoria\\Documents\\Auditoria\\Invetsa\\assets\\file-pdf\\ */ using (FileStream fileStream = new FileStream("\\\\SERVIDOR96\\Users\\adminauditoria\\Documents\\Auditoria\\fileExtranet\\" + nombreAleatorio + ".pdf", FileMode.Create)) { // Write the data to the file, byte by byte. for (int i = 0; i < bytes.Length; i++) { fileStream.WriteByte(bytes[i]); } // Set the stream position to the beginning of the file. fileStream.Seek(0, SeekOrigin.Begin); } return(new BE_File { Name = data.NameFile, NameAleatorio = nombreAleatorio, Type = data.TypeFile }); }
public async Task <BE_ResultadoTransaccion> Create(BE_TxRegistroDocumento entidad, IList <IFormFile> lista_anexo, bool generaNombre = true) { BE_ResultadoTransaccion vResultadoTransaccion = new BE_ResultadoTransaccion(); vResultadoTransaccion.ResultadoCodigo = 1; try { using (SqlConnection conn = new SqlConnection(context.DevuelveConnectionSQL())) { using (CommittableTransaction transaction = new CommittableTransaction()) { await conn.OpenAsync(); conn.EnlistTransaction(transaction); if (lista_anexo.Count > 0) { string extension = string.Empty; string nombre_archivo = string.Empty; Google.Apis.Drive.v3.Data.File fileGoogleDrive = new Google.Apis.Drive.v3.Data.File(); var _anio = DateTime.Now.Year; var _mes = DateTime.Now.Month; DateTimeFormatInfo dateTimeFormatInfo = CultureInfo.CurrentCulture.DateTimeFormat; string nombreMes = dateTimeFormatInfo.GetMonthName(_mes); entidad.Ano = _anio; entidad.Mes = _mes; try { DriveApiService googleApiDrive = new DriveApiService(); // Validamos si existe Id de folder en Google Drive string IdFolderGoogleDrive = string.Empty; var IdFolderEmpresaGoogleDrive = googleApiDrive.CreateFolder(entidad.DescripcionEmpresa); using (SqlCommand cmd = new SqlCommand(SP_GOOGLE_DRIVE_EMPRESA_MERGE, conn)) { cmd.Parameters.Clear(); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@CodigoEmpresa", entidad.CodigoEmpresa)); cmd.Parameters.Add(new SqlParameter("@IdGoogleDrive", IdFolderEmpresaGoogleDrive)); cmd.Parameters.Add(new SqlParameter("@RegUsuario", entidad.RegUsuario)); cmd.Parameters.Add(new SqlParameter("@RegEstacion", entidad.RegEstacion)); await cmd.ExecuteNonQueryAsync(); } IdFolderGoogleDrive = GetIdDriveFolder(new BE_TxRegistroDocumentoFolder { IdSubTipoExplotacion = entidad.IdSubTipoExplotacion, CodigoEmpresa = entidad.CodigoEmpresa, CodigoPlanta = entidad.CodigoPlanta, Ano = entidad.Ano, Mes = entidad.Mes }); if (string.IsNullOrEmpty(IdFolderGoogleDrive)) { IdFolderGoogleDrive = googleApiDrive.GenerateDirectory(entidad.DescripcionEmpresa, entidad.DescripcionPlanta, entidad.DescripcionTipoExplotacion, entidad.DescripcionSubTipoExplotacion, entidad.Ano.ToString(), nombreMes); using (SqlCommand cmd = new SqlCommand(SP_GOOGLE_DRIVE_INSERT, conn)) { cmd.Parameters.Clear(); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@IdSubTipoExplotacion", entidad.IdSubTipoExplotacion)); cmd.Parameters.Add(new SqlParameter("@CodigoEmpresa", entidad.CodigoEmpresa)); cmd.Parameters.Add(new SqlParameter("@CodigoPlanta", entidad.CodigoPlanta)); cmd.Parameters.Add(new SqlParameter("@IdGoogleDrive", IdFolderGoogleDrive)); cmd.Parameters.Add(new SqlParameter("@RegUsuario", entidad.RegUsuario)); cmd.Parameters.Add(new SqlParameter("@RegEstacion", entidad.RegEstacion)); await cmd.ExecuteNonQueryAsync(); } } if (entidad.FlgCerrado == null) { var IdFolderPendienteCierreGoogleDrive = googleApiDrive.CreateFolder("PENDIENTE CIERRE"); IdFolderGoogleDrive = IdFolderPendienteCierreGoogleDrive; } using (SqlCommand cmd = new SqlCommand(SP_INSERT, conn)) { foreach (IFormFile _lista in lista_anexo) { extension = _lista.FileName.Split('.').Last(); nombre_archivo = string.Empty; nombre_archivo = _lista.FileName.Replace("." + extension, string.Empty); cmd.Parameters.Clear(); cmd.CommandType = System.Data.CommandType.StoredProcedure; SqlParameter oParam = new SqlParameter("@IdDocumento", entidad.IdDocumento); oParam.SqlDbType = SqlDbType.Int; oParam.Direction = ParameterDirection.Output; cmd.Parameters.Add(oParam); cmd.Parameters.Add(new SqlParameter("@IdSubTipoExplotacion", entidad.IdSubTipoExplotacion)); cmd.Parameters.Add(new SqlParameter("@CodigoEmpresa", entidad.CodigoEmpresa)); cmd.Parameters.Add(new SqlParameter("@DescripcionEmpresa", entidad.DescripcionEmpresa)); cmd.Parameters.Add(new SqlParameter("@CodigoPlanta", entidad.CodigoPlanta)); cmd.Parameters.Add(new SqlParameter("@GeneraNombre", generaNombre)); cmd.Parameters.Add(new SqlParameter("@NombreOriginal", nombre_archivo)); SqlParameter oParamNombreArchivo = new SqlParameter("@NombreArchivo", SqlDbType.VarChar, 300) { Direction = ParameterDirection.Output }; cmd.Parameters.Add(oParamNombreArchivo); SqlParameter oParamCadenaEmail = new SqlParameter("@CadenaEmail", SqlDbType.VarChar, 300) { Direction = ParameterDirection.Output }; cmd.Parameters.Add(oParamCadenaEmail); cmd.Parameters.Add(new SqlParameter("@TipoArchivo", _lista.ContentType)); cmd.Parameters.Add(new SqlParameter("@ExtencionArchivo", extension)); cmd.Parameters.Add(new SqlParameter("@FlgCerrado", entidad.FlgCerrado)); cmd.Parameters.Add(new SqlParameter("@IdUsuarioCierre", entidad.IdUsuarioCierre)); cmd.Parameters.Add(new SqlParameter("@FecCerrado", entidad.FecCerrado)); cmd.Parameters.Add(new SqlParameter("@IdDocumentoReferencial", entidad.IdDocumentoReferencial)); cmd.Parameters.Add(new SqlParameter("@RegUsuario", entidad.RegUsuario)); cmd.Parameters.Add(new SqlParameter("@RegEstacion", entidad.RegEstacion)); await cmd.ExecuteNonQueryAsync(); entidad.IdDocumento = (int)cmd.Parameters["@IdDocumento"].Value; entidad.NombreArchivo = (string)oParamNombreArchivo.Value; var cadenaEmail = (string)oParamCadenaEmail.Value; nombre_archivo = entidad.NombreArchivo + "." + extension.ToString(); fileGoogleDrive = await googleApiDrive.Upload(_lista, IdFolderGoogleDrive, entidad.NombreArchivo); if (!string.IsNullOrEmpty(fileGoogleDrive.Id)) { using (SqlCommand cmdIdGoogle = new SqlCommand(SP_UPDATE, conn)) { cmdIdGoogle.Parameters.Clear(); cmdIdGoogle.CommandType = System.Data.CommandType.StoredProcedure; cmdIdGoogle.Parameters.Add(new SqlParameter("@IdDocumento", entidad.IdDocumento)); cmdIdGoogle.Parameters.Add(new SqlParameter("@IdGoogleDrive", fileGoogleDrive.Id)); cmdIdGoogle.Parameters.Add(new SqlParameter("@RegUsuario", entidad.RegUsuario)); cmdIdGoogle.Parameters.Add(new SqlParameter("@RegEstacion", entidad.RegEstacion)); await cmdIdGoogle.ExecuteNonQueryAsync(); } } if (entidad.FlgCerrado == null) { try { if (!string.IsNullOrEmpty(cadenaEmail)) { EmailSenderRepository emailSenderRepository = new EmailSenderRepository(context); var mensaje = string.Format("Buen día, <br> <br> Se realizo la carga de un nuevo archivo a la extranet N° {0}, Favor su aprobación", entidad.IdDocumento); var link = string.Format(" <br> <br><a href=\"https://auditoria.invetsa.com/Invetsa/\">Ingresar a la Aplicación</a>"); await emailSenderRepository.SendEmailAsync(cadenaEmail, "Correo Automatico - Registro de Documento - Extranet", mensaje + " " + link); } } catch (Exception ex) { vResultadoTransaccion.ResultadoCodigo = -1; vResultadoTransaccion.ResultadoDescripcion = ex.Message.ToString(); return(vResultadoTransaccion); } } } } transaction.Commit(); } catch (System.Exception ex) { vResultadoTransaccion.ResultadoCodigo = -1; vResultadoTransaccion.ResultadoDescripcion = ex.Message.ToString(); transaction.Rollback(); } } } } } catch (System.Exception ex) { vResultadoTransaccion.ResultadoCodigo = -1; vResultadoTransaccion.ResultadoDescripcion = ex.Message.ToString(); } return(vResultadoTransaccion); }