Ejemplo n.º 1
0
        /// <summary>
        /// Metodo que se conecta a la BD para insertar un registro
        /// </summary>
        /// <param name="Entity"></param>
        /// <returns></returns>
        public bool Insertar(INGRESO_UBICACION Entity, bool Excarcelacion, bool Traslado, int?IdAduana, bool?Entrada = false)
        {
            try
            {
                Entity.ID_CONSEC = ObtenerConsecutivo <int>(Entity.ID_CENTRO, Entity.ID_ANIO, Entity.ID_IMPUTADO, Entity.ID_INGRESO);
                using (TransactionScope transaccion = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions()
                {
                    IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted
                }))
                {
                    Context.INGRESO_UBICACION.Add(Entity);

                    if (Excarcelacion)
                    {
                        var excarcelacion = Context.EXCARCELACION.Where(w => w.ID_CENTRO == Entity.ID_CENTRO && w.ID_ANIO == Entity.ID_ANIO && w.ID_IMPUTADO == Entity.ID_IMPUTADO && w.ID_INGRESO == Entity.ID_INGRESO && w.ID_ESTATUS == "AU").FirstOrDefault();
                        if (excarcelacion != null)
                        {
                            excarcelacion.ID_ESTATUS           = "EP";
                            Context.Entry(excarcelacion).State = EntityState.Modified;
                        }
                    }
                    else if (Traslado)
                    {
                        if (Traslado)
                        {
                            var traslado = Context.TRASLADO_DETALLE.Where(w => w.ID_CENTRO == Entity.ID_CENTRO && w.ID_ANIO == Entity.ID_ANIO && w.ID_IMPUTADO == Entity.ID_IMPUTADO && w.ID_INGRESO == Entity.ID_INGRESO && w.ID_ESTATUS == "PR").FirstOrDefault();
                            if (traslado != null)
                            {
                                traslado.ID_ESTATUS           = "EP";
                                Context.Entry(traslado).State = EntityState.Modified;
                            }
                        }
                    }
                    else if (IdAduana != null)
                    {
                        var i = new ADUANA_INGRESO();
                        i.ID_ADUANA          = IdAduana.Value;
                        i.ID_CENTRO          = Entity.ID_CENTRO;
                        i.ID_ANIO            = Entity.ID_ANIO;
                        i.ID_IMPUTADO        = Entity.ID_IMPUTADO;
                        i.ID_INGRESO         = Entity.ID_INGRESO;
                        i.INTERNO_NOTIFICADO = "S";
                        Context.ADUANA_INGRESO.Attach(i);
                        Context.Entry(i).Property(x => x.INTERNO_NOTIFICADO).IsModified = true;
                    }
                    Context.SaveChanges();
                    transaccion.Complete();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.Message + " " + (ex.InnerException != null ? ex.InnerException.InnerException.Message : ""));
            }
        }
Ejemplo n.º 2
0
 public bool InsertarNuevaUbicacion(INGRESO_UBICACION Entity, EXCARCELACION EntityExc = null, TRASLADO_DETALLE EntityTra = null, ADUANA_INGRESO EntityAduana_Ingreso = null)
 {
     try
     {
         using (TransactionScope transaccion = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions()
         {
             IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted
         }))
         {
             Entity.ID_CONSEC = ObtenerConsecutivo <int>(Entity.ID_CENTRO, Entity.ID_ANIO, Entity.ID_IMPUTADO, Entity.ID_INGRESO);
             Context.INGRESO_UBICACION.Add(Entity);
             if (EntityExc != null)
             {
                 Context.EXCARCELACION.Attach(EntityExc);
                 Context.Entry(EntityExc).Property(x => x.ID_ESTATUS).IsModified = true;
             }
             else if (EntityTra != null)
             {
                 Context.TRASLADO_DETALLE.Attach(EntityTra);
                 Context.Entry(EntityTra).Property(x => x.ID_ESTATUS).IsModified = true;
             }
             else if (EntityAduana_Ingreso != null)
             {
                 Context.ADUANA_INGRESO.Attach(EntityAduana_Ingreso);
                 Context.Entry(EntityAduana_Ingreso).Property(x => x.INTERNO_NOTIFICADO).IsModified = true;
             }
             Context.SaveChanges();
             transaccion.Complete();
             return(true);
         }
     }
     catch (Exception ex)
     {
         throw new ApplicationException(ex.Message + " " + (ex.InnerException != null ? ex.InnerException.InnerException.Message : ""));
     }
 }