예제 #1
0
 public void Commit()
 {
     try
     {
         _context.SaveChanges();
         if (hasTransaction)
         {
             _context.Database.CurrentTransaction.Commit();
         }
         hasTransaction = false;
     }
     catch (DbUpdateConcurrencyException concEx)
     {
         BStatus.Alert("A operação foi completada com erros por que o registro foi excluido por outro utilizador.");
     }
     catch (System.Data.Entity.Validation.DbEntityValidationException valEx)
     {
         BStatus.ErrorOnSave(_context.Set <T>().GetType().Name, valEx.EntityValidationErrors.First().ValidationErrors.First().ErrorMessage);
         throw;
     }
     catch (Exception ex)
     {
         BStatus.ErrorOnSave(_context.Set <T>().GetType().Name, ex.Message);
         throw;
     }
 }
예제 #2
0
 public void Update(T entity)
 {
     try
     {
         _context.Entry <T>(entity).State = EntityState.Modified;
     }
     catch (System.Data.Entity.Validation.DbEntityValidationException valEx)
     {
         BStatus.ErrorOnSave(_context.Set <T>().GetType().Name, valEx.Message);
         throw;
     }
     catch (Exception ex)
     {
         BStatus.ErrorOnSave(entity.GetType().Name, ex.Message);
         throw;
     }
 }
예제 #3
0
 public void Remove(T entity)
 {
     try
     {
         _context.Set <T>().Remove(entity);
     }
     catch (System.Data.Entity.Validation.DbEntityValidationException valEx)
     {
         BStatus.ErrorOnSave(_context.Set <T>().GetType().Name, valEx.Message);
         throw;
     }
     catch (Exception ex)
     {
         BStatus.ErrorOnRemove(entity.GetType().Name, ex.Message);
         throw;
     }
 }