Use the database execution strategy around the manual transactions

pull/4016/head
tidusjar 4 years ago
parent 15b71d108e
commit 078b30eba4

@ -57,7 +57,9 @@ namespace Ombi.Store.Context
public void Seed()
{
var strat = Database.CreateExecutionStrategy();
strat.Execute(() =>
{
using (var tran = Database.BeginTransaction())
{
// Make sure we have the API User
@ -75,6 +77,7 @@ namespace Ombi.Store.Context
tran.Commit();
}
}
});
//Check if templates exist
var templates = NotificationTemplates.ToList();
@ -217,12 +220,14 @@ namespace Ombi.Store.Context
if (needToSave)
{
strat.Execute(() =>
{
using (var tran = Database.BeginTransaction())
{
SaveChanges();
tran.Commit();
}
});
}
}
}

@ -28,6 +28,9 @@ namespace Ombi.Store.Context
public void Seed()
{
var strat = Database.CreateExecutionStrategy();
strat.Execute(() =>
{
using (var tran = Database.BeginTransaction())
{
@ -67,6 +70,7 @@ namespace Ombi.Store.Context
}
tran.Commit();
}
});
}
}
}

@ -25,27 +25,21 @@ namespace Ombi.Store.Repository
{
//_cache.Remove(GetName(entity.SettingsName));
using (var tran = Db.Database.BeginTransaction())
{
var settings = Db.Settings.Add(entity);
Db.SaveChanges();
tran.Commit();
return settings.Entity;
}
}
public async Task<GlobalSettings> InsertAsync(GlobalSettings entity)
{
using (var tran = Db.Database.BeginTransaction())
{
//_cache.Remove(GetName(entity.SettingsName));
var settings = await Db.Settings.AddAsync(entity);
await Db.SaveChangesAsync();
tran.Commit();
return settings.Entity;
}
}
@ -87,23 +81,15 @@ namespace Ombi.Store.Repository
{
//_cache.Remove(GetName(entity.SettingsName));
using (var tran = Db.Database.BeginTransaction())
{
Db.Settings.Remove(entity);
Db.SaveChanges();
tran.Commit();
}
}
public void Update(GlobalSettings entity)
{
using (var tran = Db.Database.BeginTransaction())
{
Db.Update(entity);
//_cache.Remove(GetName(entity.SettingsName));
Db.SaveChanges();
tran.Commit();
}
}
private string GetName(string entity)
@ -112,14 +98,9 @@ namespace Ombi.Store.Repository
}
private async Task<int> InternalSaveChanges()
{
using (var tran = Db.Database.BeginTransaction())
{
var r = await Db.SaveChangesAsync();
tran.Commit();
return r;
}
}
}
}
Loading…
Cancel
Save