Пример #1
0
        /// <summary>
        /// Actualizar la información del objeto que se mande
        /// </summary>
        /// <param name="entityToUpdate">Objeto a Actualizar</param>
        public virtual bool Update(List <TEntity> entityToUpdate)
        {
            //using (var transaction = new TransactionScope())
            //{
            try
            {
                foreach (var item in entityToUpdate)
                {
                    DbSet.Attach(item);
                    context.Entry(item).State = EntityState.Modified;
                }

                if (!context.SaveChanges().Equals(0))
                {
                    //transaction.Complete();
                    //transaction.Dispose();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.Message);
            }
            //transaction.Dispose();
            return(false);
            //}
        }
Пример #2
0
        public void CrearGrupoRollback(short idgrupo)
        {
            try
            {
                var context = new SSPEntidades();
                context.Conexion();

                if (context.GRUPO_ASISTENCIA.Where(w => w.ID_GRUPO == idgrupo).Any())
                {
                    foreach (var entity in context.GRUPO_ASISTENCIA.Where(w => w.ID_GRUPO == idgrupo))
                    {
                        context.Set <GRUPO_ASISTENCIA>().Attach(entity);
                        context.Entry(entity).State = EntityState.Deleted;
                    }
                    context.SaveChanges();
                }
                if (context.GRUPO_HORARIO.Where(w => w.ID_GRUPO == idgrupo).Any())
                {
                    foreach (var entity in context.GRUPO_HORARIO.Where(w => w.ID_GRUPO == idgrupo))
                    {
                        context.Set <GRUPO_HORARIO>().Attach(entity);
                        context.Entry(entity).State = EntityState.Deleted;
                    }
                    context.SaveChanges();
                }
                if (context.GRUPO_PARTICIPANTE.Where(w => w.ID_GRUPO == idgrupo).Any())
                {
                    foreach (var entity in context.GRUPO_PARTICIPANTE.Where(w => w.ID_GRUPO == idgrupo))
                    {
                        entity.ID_GRUPO = new Nullable <short>();
                        entity.ESTATUS  = 1;

                        context.Set <GRUPO_PARTICIPANTE>().Attach(entity);
                        context.Entry(entity).State = EntityState.Modified;
                    }
                    context.SaveChanges();
                }
                if (context.GRUPO.Where(w => w.ID_GRUPO == idgrupo).Any())
                {
                    var entity = context.GRUPO.Where(w => w.ID_GRUPO == idgrupo).FirstOrDefault();
                    context.Set <GRUPO>().Attach(entity);
                    context.Entry(entity).State = EntityState.Deleted;
                    context.SaveChanges();
                }

                /*
                 * delete from ssp.grupo_asistencia;
                 * delete from ssp.grupo_horario;
                 * update ssp.grupo_participante set id_grupo = null, estatus = 1;
                 * delete from ssp.grupo;*/
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #3
0
 /// <summary>
 /// Actualizar la información del objeto que se mande, se necesita todos los parametros
 /// </summary>
 /// <param name="entityToUpdate">Objeto a Actualizar</param>
 public virtual bool Update(TEntity entityToUpdate)
 {
     //using (var transaction = new TransactionScope())
     //{
     try
     {
         SSPEntidades contexto = new SSPEntidades();
         contexto.Conexion();
         contexto.Entry(entityToUpdate).State = EntityState.Modified;
         if (!contexto.SaveChanges().Equals(0))
         {
             //transaction.Complete();
             //transaction.Dispose();
             return(true);
         }
     }
     catch (DbEntityValidationException dbEx)
     {
         foreach (var validationErrors in dbEx.EntityValidationErrors)
         {
             foreach (var validationError in validationErrors.ValidationErrors)
             {
                 System.Console.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
             }
         }
     }
     //transaction.Dispose();
     return(false);
     //}
 }