Radarr/NzbDrone.Services.Api/DailySeries/DailySeriesRepository.cs

58 lines
1.9 KiB
C#
Raw Normal View History

2013-01-29 01:07:18 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MongoDB.Driver;
using MongoDB.Driver.Builders;
namespace NzbDrone.Services.Api.DailySeries
{
public class DailySeriesRepository
2013-01-29 01:07:18 +00:00
{
private readonly MongoDatabase _mongoDb;
public DailySeriesRepository(MongoDatabase mongoDb)
2013-01-29 01:07:18 +00:00
{
_mongoDb = mongoDb;
}
public DailySeriesRepository()
2013-01-29 01:07:18 +00:00
{
}
public List<DailySeriesModel> All()
{
return _mongoDb.GetCollection<DailySeriesModel>(DailySeriesModel.CollectionName).FindAll().ToList();
}
public List<DailySeriesModel> Public()
{
var query = Query<DailySeriesModel>.EQ(d => d.Public, true);
return _mongoDb.GetCollection<DailySeriesModel>(DailySeriesModel.CollectionName).Find(query).ToList();
}
2013-02-01 04:18:11 +00:00
public DailySeriesModel Find(int seriesId)
2013-01-29 01:07:18 +00:00
{
var query = Query<DailySeriesModel>.EQ(d => d.Id, seriesId);
2013-02-01 04:18:11 +00:00
return _mongoDb.GetCollection<DailySeriesModel>(DailySeriesModel.CollectionName).FindOne(query);
2013-01-29 01:07:18 +00:00
}
public void Insert(DailySeriesModel dailySeries)
{
_mongoDb.GetCollection<DailySeriesModel>(DailySeriesModel.CollectionName).Insert(dailySeries);
}
public void Delete(int seriesId)
{
var query = Query<DailySeriesModel>.EQ(d => d.Id, seriesId);
_mongoDb.GetCollection<DailySeriesModel>(DailySeriesModel.CollectionName).Remove(query);
}
public void TogglePublic(int seriesId, bool status)
{
var query = Query<DailySeriesModel>.EQ(d => d.Id, seriesId);
var update = Update<DailySeriesModel>.Set(d => d.Public, status);
_mongoDb.GetCollection<DailySeriesModel>(DailySeriesModel.CollectionName).Update(query, update);
}
2013-01-29 01:07:18 +00:00
}
}