Sonarr/NzbDrone.Api/QualityProfiles/QualityProfileService.cs

64 lines
1.7 KiB
C#
Raw Normal View History

2012-11-04 01:39:29 +00:00
using System.Collections.Generic;
using System.Linq;
using AutoMapper;
using Ninject;
2012-11-02 07:35:49 +00:00
using NzbDrone.Api.Filters;
using NzbDrone.Core.Providers;
2012-11-04 01:39:29 +00:00
using NzbDrone.Core.Repository.Quality;
2012-11-02 07:35:49 +00:00
using ServiceStack.ServiceInterface;
namespace NzbDrone.Api.QualityProfiles
2012-11-02 07:35:49 +00:00
{
[ValidApiRequest]
2012-11-04 01:39:29 +00:00
public class QualityProfileService : RestServiceBase<QualityProfileModel>
2012-11-02 07:35:49 +00:00
{
private readonly QualityProvider _qualityProvider;
[Inject]
public QualityProfileService(QualityProvider qualityProvider)
{
_qualityProvider = qualityProvider;
}
public QualityProfileService()
{
}
2012-11-04 01:39:29 +00:00
public override object OnGet(QualityProfileModel request)
2012-11-02 07:35:49 +00:00
{
if (request.Id == 0)
{
var profiles = _qualityProvider.All();
2012-12-03 03:08:26 +00:00
return Mapper.Map<List<QualityProfile>, List<QualityProfileModel>>(profiles);
}
var profile = _qualityProvider.Get(request.Id);
2012-12-03 03:08:26 +00:00
return Mapper.Map<QualityProfile, QualityProfileModel>(profile);
2012-11-02 07:35:49 +00:00
}
2012-11-04 01:39:29 +00:00
public override object OnPost(QualityProfileModel data)
{
2012-12-03 03:08:26 +00:00
//Create
2012-11-04 01:39:29 +00:00
var profile = Mapper.Map<QualityProfileModel, QualityProfile>(data);
2012-12-03 03:08:26 +00:00
_qualityProvider.Add(profile);
2012-11-04 01:39:29 +00:00
return data;
}
public override object OnPut(QualityProfileModel data)
{
2012-12-03 03:08:26 +00:00
//Update
2012-11-04 01:39:29 +00:00
var profile = Mapper.Map<QualityProfileModel, QualityProfile>(data);
2012-12-03 03:08:26 +00:00
_qualityProvider.Update(profile);
2012-11-04 01:39:29 +00:00
return data;
}
public override object OnDelete(QualityProfileModel data)
{
_qualityProvider.Delete(data.Id);
return "ok";
}
2012-11-02 07:35:49 +00:00
}
}