sonarr-repo-only/NzbDrone.Api/QualityProfiles/QualityProfileService.cs

62 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;
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;
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-12-05 16:34:43 +00:00
//Create
public override object OnPost(QualityProfileModel request)
2012-11-04 01:39:29 +00:00
{
2012-12-05 16:34:43 +00:00
var profile = Mapper.Map<QualityProfileModel, QualityProfile>(request);
2012-12-11 04:39:35 +00:00
request.Id = _qualityProvider.Add(profile);
2012-12-05 16:34:43 +00:00
return request;
2012-11-04 01:39:29 +00:00
}
2012-12-05 16:34:43 +00:00
//Update
public override object OnPut(QualityProfileModel request)
2012-11-04 01:39:29 +00:00
{
2012-12-05 16:34:43 +00:00
var profile = Mapper.Map<QualityProfileModel, QualityProfile>(request);
2012-12-03 03:08:26 +00:00
_qualityProvider.Update(profile);
2012-11-04 01:39:29 +00:00
2012-12-05 16:34:43 +00:00
return request;
2012-11-04 01:39:29 +00:00
}
2012-12-05 16:34:43 +00:00
public override object OnDelete(QualityProfileModel request)
2012-11-04 01:39:29 +00:00
{
2012-12-05 16:34:43 +00:00
_qualityProvider.Delete(request.Id);
2012-11-04 01:39:29 +00:00
2012-12-05 16:34:43 +00:00
return request.Id.ToString();
2012-11-04 01:39:29 +00:00
}
2012-11-02 07:35:49 +00:00
}
}