2012-02-05 09:34:36 +03:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Web;
|
|
|
|
using NzbDrone.Services.Service.Repository;
|
2012-02-18 01:04:22 +03:00
|
|
|
using Services.PetaPoco;
|
2012-02-05 09:34:36 +03:00
|
|
|
|
|
|
|
namespace NzbDrone.Services.Service.Providers
|
|
|
|
{
|
|
|
|
public class SceneMappingProvider
|
|
|
|
{
|
|
|
|
private readonly IDatabase _database;
|
|
|
|
|
|
|
|
public SceneMappingProvider(IDatabase database)
|
|
|
|
{
|
|
|
|
_database = database;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IList<SceneMapping> AllLive()
|
|
|
|
{
|
|
|
|
return _database.Fetch<SceneMapping>();
|
|
|
|
}
|
|
|
|
|
|
|
|
public IList<PendingSceneMapping> AllPending()
|
|
|
|
{
|
|
|
|
return _database.Fetch<PendingSceneMapping>();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Insert(SceneMapping sceneMapping)
|
|
|
|
{
|
|
|
|
_database.Insert(sceneMapping);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Insert(PendingSceneMapping pendingSceneMapping)
|
|
|
|
{
|
|
|
|
_database.Insert(pendingSceneMapping);
|
|
|
|
}
|
|
|
|
|
2012-02-27 04:45:07 +03:00
|
|
|
public void Update(PendingSceneMapping pendingSceneMapping)
|
2012-02-05 09:34:36 +03:00
|
|
|
{
|
2012-02-27 04:45:07 +03:00
|
|
|
_database.Update(pendingSceneMapping);
|
2012-02-05 09:34:36 +03:00
|
|
|
}
|
|
|
|
|
2012-02-27 04:45:07 +03:00
|
|
|
public PendingSceneMapping GetPending(int mappingId)
|
2012-02-05 09:34:36 +03:00
|
|
|
{
|
2012-02-27 04:45:07 +03:00
|
|
|
return _database.SingleOrDefault<PendingSceneMapping>("WHERE MappingId = @mappingId", new{ mappingId });
|
2012-02-05 09:34:36 +03:00
|
|
|
}
|
|
|
|
|
2012-02-27 04:45:07 +03:00
|
|
|
public void DeleteLive(int mappingId)
|
|
|
|
{
|
|
|
|
_database.Delete<SceneMapping>(mappingId);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void DeletePending(int mappingId)
|
|
|
|
{
|
|
|
|
_database.Delete<PendingSceneMapping>(mappingId);
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool Promote(int mappingId)
|
2012-02-05 09:34:36 +03:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2012-02-27 04:45:07 +03:00
|
|
|
var pendingItem = GetPending(mappingId);
|
2012-02-05 09:34:36 +03:00
|
|
|
|
|
|
|
var mapping = new SceneMapping
|
|
|
|
{
|
|
|
|
CleanTitle = pendingItem.CleanTitle,
|
|
|
|
Id = pendingItem.Id,
|
|
|
|
Title = pendingItem.Title
|
|
|
|
};
|
|
|
|
|
2012-02-27 04:45:07 +03:00
|
|
|
Insert(mapping);
|
|
|
|
DeletePending(mappingId);
|
2012-02-05 09:34:36 +03:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool PromoteAll()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var pendingItems = _database.Fetch<PendingSceneMapping>();
|
|
|
|
|
|
|
|
foreach (var pendingItem in pendingItems)
|
|
|
|
{
|
2012-02-27 04:45:07 +03:00
|
|
|
Promote(pendingItem.MappingId);
|
2012-02-05 09:34:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|