/// <summary> /// Método que remplaza el archivo de un registro existente /// </summary> /// <param name="id_version"></param> /// <param name="archivo"></param> /// <returns></returns> public int RemplazarArchivoExistente(int id_version, string pathFile) { try { using (var Conexion = new EntitiesControlDocumentos()) { //Obtenemos el registro con el id de la version TBL_ARCHIVO Arc = Conexion.TBL_ARCHIVO.Where(x => x.ID_VERSION == id_version).FirstOrDefault(); //asignamos el archivo Arc.ARCHIVO = new byte[0]; Arc.PATH_FILE = pathFile; //modificamos el registro asignando el nuevo archivo Conexion.Entry(Arc).State = EntityState.Modified; //guardamos cambios return(Conexion.SaveChanges()); } } catch (Exception) { return(0); } }
/// <summary> /// Método par insertar un registro en la tabla TBL_archivo. /// </summary> /// <param name="id_archivo"></param> /// <param name="id_version"></param> /// <param name="archivo"></param> /// <param name="ext"></param> /// <returns>Retorna cero si hay error.</returns> public int UpdateArchivo(int id_archivo, int id_version, string pathFile, string ext, string nombre) { try { //Se establece la conexión a la base de datos. using (var Conexion = new EntitiesControlDocumentos()) { //creación del objeto tipo TBL_archivo. TBL_ARCHIVO obj = Conexion.TBL_ARCHIVO.Where(x => x.ID_ARCHIVO == id_archivo).FirstOrDefault(); //Asignamos los parámetros recibidos a cada uno de los valores de los objetos. obj.ID_VERSION = id_version; obj.ARCHIVO = new byte[0]; obj.EXT = ext; obj.NOMBRE_ARCHIVO = nombre; obj.PATH_FILE = pathFile; //Se cambia el estado de registro a modificado. Conexion.Entry(obj).State = EntityState.Modified; //Se guardan los cambios y se retorna el número de registros afectados. return(Conexion.SaveChanges()); } } catch (Exception) { //Si encuentra error devuelve cero. return(0); } }
/// <summary> /// Método para eliminar un documento con sello electronico /// cuando se modifique su estado a pendiente por corregir /// </summary> /// <param name="id_version"></param> /// <returns></returns> public int ElimiarDocumentoSellado(int id_version) { try { using (var Conexion = new EntitiesControlDocumentos()) { TBL_ARCHIVO archivo = Conexion.TBL_ARCHIVO.Where(x => x.ID_VERSION == id_version).FirstOrDefault(); Conexion.Entry(archivo).State = EntityState.Deleted; return(Conexion.SaveChanges()); } } catch (Exception) { return(0); } }
public int sustituteFileByPath(int idArchivo, string path) { try { using (var Conexion = new EntitiesControlDocumentos()) { byte[] blanco = new byte[0]; TBL_ARCHIVO archivo = Conexion.TBL_ARCHIVO.Where(x => x.ID_ARCHIVO == idArchivo).FirstOrDefault(); archivo.ARCHIVO = new byte[0]; archivo.PATH_FILE = path; Conexion.Entry(archivo).State = EntityState.Modified; return(Conexion.SaveChanges()); } } catch (Exception) { throw; } }
/// <summary> /// Método para eliminar un registro de la tabla. /// </summary> /// <param name="id_archivo"></param> /// <returns>Si hay algún error, retorna cero.</returns> public int DeleteArchivo(int id_archivo) { try { // Se inicializa la conexión a la base de datos. using (var Conexion = new EntitiesControlDocumentos()) { //Se obtiene el objeto que se va a eliminar. TBL_ARCHIVO archivo = Conexion.TBL_ARCHIVO.Where(x => x.ID_ARCHIVO == id_archivo).FirstOrDefault(); //Se estable el estado de registro a eliminado. Conexion.Entry(archivo).State = EntityState.Deleted; //Se guardan los cambios y retorna el número de registros afectados. return(Conexion.SaveChanges()); } } catch (Exception) { //Si hay error, regresa 0. return(0); } }