public bool FinalizarTraslado(TRASLADO Traslado, INGRESO Ingreso, TRASLADO_DETALLE Traslado_Detalle) { try { using (TransactionScope transaccion = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions() { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted })) { var ListaTrasladoInternos = new cTrasladoDetalle().ObtenerTrasladoInternos(Traslado.ID_TRASLADO, Traslado.ID_CENTRO).AsEnumerable(); foreach (var Interno in ListaTrasladoInternos) { var cama = new CAMA() { ID_CENTRO = Interno.INGRESO.CAMA.ID_CENTRO, ID_EDIFICIO = Interno.INGRESO.CAMA.ID_EDIFICIO, ID_SECTOR = Interno.INGRESO.CAMA.ID_SECTOR, ID_CELDA = Interno.INGRESO.CAMA.ID_CELDA, ID_CAMA = Interno.INGRESO.CAMA.ID_CAMA, ESTATUS = "S" }; Context.CAMA.Attach(cama); Context.Entry(cama).Property(x => x.ESTATUS).IsModified = true; } Context.TRASLADO.Attach(Traslado); Context.Entry(Traslado).Property(x => x.ID_ESTATUS).IsModified = true; Context.Entry(Traslado).Property(x => x.RESPONSABLE).IsModified = Traslado.RESPONSABLE != null; Context.INGRESO.Attach(Ingreso); Context.Entry(Ingreso).Property(x => x.ID_ESTATUS_ADMINISTRATIVO).IsModified = true; Context.TRASLADO_DETALLE.Attach(Traslado_Detalle); Context.Entry(Traslado_Detalle).Property(x => x.ID_ESTATUS).IsModified = true; Context.Entry(Traslado_Detalle).Property(x => x.EGRESO_FEC).IsModified = true; Context.Entry(Traslado_Detalle).Property(x => x.ID_ESTATUS_ADMINISTRATIVO).IsModified = true; Context.Entry(Traslado_Detalle).Property(x => x.ID_INCIDENCIA_TRASLADO).IsModified = true; Context.Entry(Traslado_Detalle).Property(x => x.INCIDENCIA_OBSERVACION).IsModified = true; Context.SaveChanges(); transaccion.Complete(); return(true); } } catch (Exception ex) { throw new ApplicationException(ex.Message); } }
public bool Insertar(INGRESO_UBICACION_ANT Entidad, INGRESO Ingreso, CAMA CamaNueva, CAMA CamaVieja) { try { using (TransactionScope transaccion = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions() { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted })) { Entidad.ID_CONSEC = GetIDProceso <short>("INGRESO_UBICACION_ANT", "ID_CONSEC", string.Format("ID_CENTRO = {0} AND ID_ANIO = {1} AND ID_IMPUTADO = {2} AND ID_INGRESO = {3}", Entidad.ID_CENTRO, Entidad.ID_ANIO, Entidad.ID_IMPUTADO, Entidad.ID_INGRESO)); Context.INGRESO_UBICACION_ANT.Add(Entidad); #region Ingreso if (Ingreso != null) { Context.INGRESO.Attach(Ingreso); Context.Entry(Ingreso).Property(x => x.ID_UB_EDIFICIO).IsModified = true; Context.Entry(Ingreso).Property(x => x.ID_UB_SECTOR).IsModified = true; Context.Entry(Ingreso).Property(x => x.ID_UB_CELDA).IsModified = true; Context.Entry(Ingreso).Property(x => x.ID_UB_CAMA).IsModified = true; } #endregion #region Cama Nueva if (CamaNueva != null) { /* * ID_CAMA * ID_CELDA * ID_SECTOR * ID_EDIFICIO * ID_CENTRO */ var cn = Context.CAMA.Where(w => w.ID_CENTRO == CamaNueva.ID_CENTRO && w.ID_EDIFICIO == CamaNueva.ID_EDIFICIO && w.ID_SECTOR == CamaNueva.ID_SECTOR && w.ID_CELDA == CamaNueva.ID_CELDA && w.ID_CAMA == CamaNueva.ID_CAMA).FirstOrDefault(); if (cn != null) { cn.ESTATUS = CamaNueva.ESTATUS; Context.Entry(cn).State = EntityState.Modified; } //Context.CAMA.Attach(CamaNueva); //Context.Entry(CamaNueva).Property(x => x.ESTATUS).IsModified = true; } #endregion #region Cama Vieja if (CamaVieja != null) { var cv = Context.CAMA.Where(w => w.ID_CENTRO == CamaVieja.ID_CENTRO && w.ID_EDIFICIO == CamaVieja.ID_EDIFICIO && w.ID_SECTOR == CamaVieja.ID_SECTOR && w.ID_CELDA == CamaVieja.ID_CELDA && w.ID_CAMA == CamaVieja.ID_CAMA).FirstOrDefault(); if (cv != null) { cv.ESTATUS = CamaVieja.ESTATUS; Context.Entry(cv).State = EntityState.Modified; } //Context.CAMA.Attach(CamaVieja); //Context.Entry(CamaVieja).Property(x => x.ESTATUS).IsModified = true; } #endregion Context.SaveChanges(); transaccion.Complete(); return(true); } //Entidad.ID_CONSEC = GetIDProceso<short>("INGRESO_UBICACION_ANT", "ID_CONSEC", string.Format("ID_CENTRO = {0} AND ID_ANIO = {1} AND ID_IMPUTADO = {2} AND ID_INGRESO = {3}", Entidad.ID_CENTRO, Entidad.ID_ANIO, Entidad.ID_IMPUTADO, Entidad.ID_INGRESO)); //if (Insert(Entidad)) // return true; //return false; } catch (Exception ex) { throw new ApplicationException(ex.Message); } return(false); }