using System; using System.Collections.Generic; using System.Linq; using System.Web; using NzbDrone.Services.Service.Repository; using Services.PetaPoco; namespace NzbDrone.Services.Service.Providers { public class SceneMappingProvider { private readonly IDatabase _database; public SceneMappingProvider(IDatabase database) { _database = database; } public IList AllLive() { return _database.Fetch(); } public IList AllPending() { return _database.Fetch(); } public void Insert(SceneMapping sceneMapping) { _database.Insert(sceneMapping); } public void Insert(PendingSceneMapping pendingSceneMapping) { _database.Insert(pendingSceneMapping); } public void Update(PendingSceneMapping pendingSceneMapping) { _database.Update(pendingSceneMapping); } public PendingSceneMapping GetPending(int mappingId) { return _database.SingleOrDefault("WHERE MappingId = @mappingId", new{ mappingId }); } public void DeleteLive(int mappingId) { _database.Delete(mappingId); } public void DeletePending(int mappingId) { _database.Delete(mappingId); } public bool Promote(int mappingId) { try { var pendingItem = GetPending(mappingId); var mapping = new SceneMapping { CleanTitle = pendingItem.CleanTitle, Id = pendingItem.Id, Title = pendingItem.Title }; Insert(mapping); DeletePending(mappingId); } catch (Exception ex) { return false; } return true; } public bool PromoteAll() { try { var pendingItems = _database.Fetch(); foreach (var pendingItem in pendingItems) { Promote(pendingItem.MappingId); } } catch (Exception ex) { return false; } return true; } } }