1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2024-12-27 18:17:13 +00:00
Lidarr/NzbDrone.Api/QualityProfiles/QualityProfileService.cs
2013-01-02 17:09:13 -08:00

62 lines
No EOL
1.7 KiB
C#

using System.Collections.Generic;
using System.Linq;
using AutoMapper;
using NzbDrone.Api.Filters;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository.Quality;
using ServiceStack.ServiceInterface;
namespace NzbDrone.Api.QualityProfiles
{
[ValidApiRequest]
public class QualityProfileService : RestServiceBase<QualityProfileModel>
{
private readonly QualityProvider _qualityProvider;
public QualityProfileService(QualityProvider qualityProvider)
{
_qualityProvider = qualityProvider;
}
public QualityProfileService()
{
}
public override object OnGet(QualityProfileModel request)
{
if (request.Id == 0)
{
var profiles = _qualityProvider.All();
return Mapper.Map<List<QualityProfile>, List<QualityProfileModel>>(profiles);
}
var profile = _qualityProvider.Get(request.Id);
return Mapper.Map<QualityProfile, QualityProfileModel>(profile);
}
//Create
public override object OnPost(QualityProfileModel request)
{
var profile = Mapper.Map<QualityProfileModel, QualityProfile>(request);
request.Id = _qualityProvider.Add(profile);
return request;
}
//Update
public override object OnPut(QualityProfileModel request)
{
var profile = Mapper.Map<QualityProfileModel, QualityProfile>(request);
_qualityProvider.Update(profile);
return request;
}
public override object OnDelete(QualityProfileModel request)
{
_qualityProvider.Delete(request.Id);
return request.Id.ToString();
}
}
}