diff --git a/src/NzbDrone.Core/DataAugmentation/Xem/XemService.cs b/src/NzbDrone.Core/DataAugmentation/Xem/XemService.cs index b7165a7f0..fc0146c7b 100644 --- a/src/NzbDrone.Core/DataAugmentation/Xem/XemService.cs +++ b/src/NzbDrone.Core/DataAugmentation/Xem/XemService.cs @@ -1,6 +1,5 @@ using System; using System.Linq; -using System.Web.UI.WebControls; using NLog; using NzbDrone.Common.Cache; using NzbDrone.Core.Messaging.Events; diff --git a/src/NzbDrone.Core/Datastore/BasicRepository.cs b/src/NzbDrone.Core/Datastore/BasicRepository.cs index f4125c0f2..6f6ed553e 100644 --- a/src/NzbDrone.Core/Datastore/BasicRepository.cs +++ b/src/NzbDrone.Core/Datastore/BasicRepository.cs @@ -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 models) { - foreach (var model in models) + using (var unitOfWork = new UnitOfWork(() => DataMapper)) { - Insert(model); + unitOfWork.BeginTransaction(); + + foreach (var model in models) + { + unitOfWork.DB.Insert(model); + } + + unitOfWork.Commit(); } } public void UpdateMany(IList models) { - foreach (var model in models) + using (var unitOfWork = new UnitOfWork(() => DataMapper)) { - Update(model); + unitOfWork.BeginTransaction(); + + foreach (var model in models) + { + 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 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 ids) { - ids.ToList().ForEach(Delete); + using (var unitOfWork = new UnitOfWork(() => DataMapper)) + { + unitOfWork.BeginTransaction(); + + foreach (var id in ids) + { + var localId = id; + + unitOfWork.DB.Delete(c => c.Id == localId); + } + + unitOfWork.Commit(); + } } public void Purge()