Exemple #1
0
 public virtual void Delete(TEntity t, bool?forzarDelete = null)
 {
     if (Context.Entry(t).State == EntityState.Detached)
     {
         DbSet.Attach(t);
     }
     if (forzarDelete != null)
     {
         if (forzarDelete.Value)
         {
             DbSet.Remove(t);
         }
     }
     else
     {
         if (UtilRepo.HasMember(t, "Habilitado"))
         {
             this.Disabled(t);
         }
         else
         {
             DbSet.Remove(t);
         }
     }
 }
Exemple #2
0
 public virtual void Update(TEntity t)
 {
     if (UtilRepo.HasMember(t, "TSModificado"))
     {
         DbSet.Attach(t);
         Context.Entry(t).Member("TSModificado").CurrentValue = DateTime.Now;
         Context.Entry(t).State = EntityState.Modified;
     }
     else
     {
         DbSet.Attach(t);
         Context.Entry(t).State = EntityState.Modified;
     }
 }
Exemple #3
0
 //Esta función desabilita un registro dado
 public virtual void Disabled(TEntity TEntity)
 {
     if (UtilRepo.HasMember(TEntity, "TSEliminado"))
     {
         DbSet.Attach(TEntity);
         Context.Entry(TEntity).Member("Habilitado").CurrentValue  = false;
         Context.Entry(TEntity).Member("TSEliminado").CurrentValue = DateTime.Now;
         Context.Entry(TEntity).State = EntityState.Modified;
     }
     else
     {
         DbSet.Attach(TEntity);
         Context.Entry(TEntity).Member("Habilitado").CurrentValue = false;
         Context.Entry(TEntity).State = EntityState.Modified;
     }
 }
Exemple #4
0
 public virtual TEntity Create(TEntity t)
 {
     try
     {
         if (UtilRepo.HasMember(t, "Habilitado"))
         {
             if (UtilRepo.HasMember(t, "TSCreate"))
             {
                 Context.Entry(t).Member("TSCreate").CurrentValue   = DateTime.Now;
                 Context.Entry(t).Member("Habilitado").CurrentValue = true;
             }
             else
             {
                 Context.Entry(t).Member("Habilitado").CurrentValue = true;
             }
         }
         var newEntry = DbSet.Add(t);
         return(newEntry.Entity);
     }
     catch
     {
         return(null);
     }
 }