1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-14 11:23:42 +02:00
Sonarr/NzbDrone.Api/QualityType/QualityTypeModule.cs
2013-02-26 19:19:47 -08:00

51 lines
1.5 KiB
C#

using System.Collections.Generic;
using System.Linq;
using AutoMapper;
using Nancy;
using NzbDrone.Api.Extensions;
using NzbDrone.Api.QualityProfiles;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Qualities;
namespace NzbDrone.Api.QualityType
{
public class QualityTypeModule : NzbDroneApiModule
{
private readonly QualitySizeService _qualityTypeProvider;
public QualityTypeModule(QualitySizeService qualityTypeProvider)
: base("/QualityTypes")
{
_qualityTypeProvider = qualityTypeProvider;
Get["/"] = x => GetQualityType();
Get["/{id}"] = x => GetQualityType(x.Id);
Put["/"] = x => PutQualityType();
}
private Response PutQualityType()
{
var model = Request.Body.FromJson<QualityTypeModel>();
var type = Mapper.Map<QualityTypeModel, QualitySize>(model);
_qualityTypeProvider.Update(type);
return model.AsResponse();
}
private Response GetQualityType(int id)
{
var type = _qualityTypeProvider.Get(id);
return Mapper.Map<QualitySize, QualityTypeModel>(type).AsResponse();
}
private Response GetQualityType()
{
var types = _qualityTypeProvider.All().Where(qualityType => qualityType.QualityId != 0 && qualityType.QualityId != 10).ToList();
var responseModel = Mapper.Map<List<QualitySize>, List<QualityTypeModel>>(types);
return responseModel.AsResponse();
}
}
}