|
|
|
@ -2,6 +2,7 @@
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
using System.Security.Cryptography.X509Certificates;
|
|
|
|
|
using Marr.Data;
|
|
|
|
|
using Marr.Data.QGen;
|
|
|
|
|
using NzbDrone.Core.Datastore.Events;
|
|
|
|
@ -142,23 +143,44 @@ namespace NzbDrone.Core.Datastore
|
|
|
|
|
|
|
|
|
|
public void InsertMany(IList<TModel> models)
|
|
|
|
|
{
|
|
|
|
|
using (var unitOfWork = new UnitOfWork(() => DataMapper))
|
|
|
|
|
{
|
|
|
|
|
unitOfWork.BeginTransaction();
|
|
|
|
|
|
|
|
|
|
foreach (var model in models)
|
|
|
|
|
{
|
|
|
|
|
Insert(model);
|
|
|
|
|
unitOfWork.DB.Insert(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unitOfWork.Commit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateMany(IList<TModel> models)
|
|
|
|
|
{
|
|
|
|
|
using (var unitOfWork = new UnitOfWork(() => DataMapper))
|
|
|
|
|
{
|
|
|
|
|
unitOfWork.BeginTransaction();
|
|
|
|
|
|
|
|
|
|
foreach (var model in models)
|
|
|
|
|
{
|
|
|
|
|
Update(model);
|
|
|
|
|
var localModel = model;
|
|
|
|
|
|
|
|
|
|
if (model.Id == 0)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Can't update model with ID 0");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unitOfWork.DB.Update(model, c => c.Id == localModel.Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unitOfWork.Commit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DeleteMany(List<TModel> models)
|
|
|
|
|
{
|
|
|
|
|
models.ForEach(Delete);
|
|
|
|
|
DeleteMany(models.Select(m => m.Id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TModel Upsert(TModel model)
|
|
|
|
@ -179,7 +201,19 @@ namespace NzbDrone.Core.Datastore
|
|
|
|
|
|
|
|
|
|
public void DeleteMany(IEnumerable<int> ids)
|
|
|
|
|
{
|
|
|
|
|
ids.ToList().ForEach(Delete);
|
|
|
|
|
using (var unitOfWork = new UnitOfWork(() => DataMapper))
|
|
|
|
|
{
|
|
|
|
|
unitOfWork.BeginTransaction();
|
|
|
|
|
|
|
|
|
|
foreach (var id in ids)
|
|
|
|
|
{
|
|
|
|
|
var localId = id;
|
|
|
|
|
|
|
|
|
|
unitOfWork.DB.Delete<TModel>(c => c.Id == localId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unitOfWork.Commit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Purge()
|
|
|
|
|