public async Task <long> AddAsync(T entity) { if (entity == null) { RepositoryExceptions.Add(new ArgumentNullException($"{nameof(AddAsync)} entity must not be null")); } try { await Entities.AddAsync(entity); if (await context.SaveChangesAsync() > 0) { return(GetKey(entity)); } } catch (Exception ex) { RepositoryExceptions.Add(new Exception($"{nameof(entity)} could not be saved: {ex.Message}")); } return(0); }
public Task <int> SaveChangesAsync() { Task <int> changes; try { changes = _context.SaveChangesAsync(); _transaction.Commit(); } catch { _transaction.Rollback(); throw; } finally { _transaction = _context.Database.BeginTransaction(); } return(changes); }