Radarr/NzbDrone.Core/RootFolders/RootFolderRepository.cs

75 lines
1.7 KiB
C#
Raw Normal View History

2013-02-04 04:18:59 +00:00
using System.Collections.Generic;
2013-02-04 06:27:58 +00:00
using Eloquera.Client;
2013-02-04 04:18:59 +00:00
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Repository;
using System.Linq;
namespace NzbDrone.Core.RootFolders
{
2013-02-04 06:27:58 +00:00
public abstract class BaseModel
2013-02-04 04:18:59 +00:00
{
2013-02-04 06:27:58 +00:00
[ID]
public int Id;
}
public interface IBasicRepository<TModel>
{
List<TModel> All();
TModel Get(int rootFolderId);
TModel Add(TModel rootFolder);
2013-02-04 04:18:59 +00:00
void Delete(int rootFolderId);
}
2013-02-04 06:27:58 +00:00
public abstract class BasicRepository<TModel> : IBasicRepository<TModel> where TModel : BaseModel, new()
2013-02-04 04:18:59 +00:00
{
2013-02-04 06:27:58 +00:00
public BasicRepository(EloqueraDb eloqueraDb)
2013-02-04 04:18:59 +00:00
{
2013-02-04 06:27:58 +00:00
EloqueraDb = eloqueraDb;
2013-02-04 04:18:59 +00:00
}
2013-02-04 06:27:58 +00:00
protected EloqueraDb EloqueraDb { get; private set; }
public List<TModel> All()
2013-02-04 04:18:59 +00:00
{
2013-02-04 06:27:58 +00:00
return EloqueraDb.AsQueryable<TModel>().ToList();
2013-02-04 04:18:59 +00:00
}
2013-02-04 06:27:58 +00:00
public TModel Get(int rootFolderId)
2013-02-04 04:18:59 +00:00
{
2013-02-04 06:27:58 +00:00
return EloqueraDb.AsQueryable<TModel>().Single(c => c.Id == rootFolderId);
2013-02-04 04:18:59 +00:00
}
2013-02-04 06:27:58 +00:00
public TModel Add(TModel rootFolder)
2013-02-04 04:18:59 +00:00
{
2013-02-04 06:27:58 +00:00
return EloqueraDb.Insert(rootFolder);
2013-02-04 04:18:59 +00:00
}
public void Delete(int rootFolderId)
{
2013-02-04 06:27:58 +00:00
var itemToDelete = Get(rootFolderId);
EloqueraDb.Delete(itemToDelete);
}
}
public interface IRootFolderRepository : IBasicRepository<RootDir>
{
}
//This way we only need to implement none_custom methods for repos, like custom queries etc... rest is done automagically.
public class RootFolderRepository : BasicRepository<RootDir>, IRootFolderRepository
{
public RootFolderRepository(EloqueraDb eloqueraDb)
: base(eloqueraDb)
{
2013-02-04 04:18:59 +00:00
}
}
}