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;
     }
 }
 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;
     }
 }
 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;
     }
 }