1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-31 16:02:29 +01:00
Sonarr/NzbDrone.Core/Qualities/QualitySizeService.cs

70 lines
2.0 KiB
C#
Raw Normal View History

using System.Collections.Generic;
2013-02-27 04:19:22 +01:00
using System.Linq;
using NLog;
using NzbDrone.Common.Messaging;
2013-02-27 04:19:22 +01:00
using NzbDrone.Core.Lifecycle;
namespace NzbDrone.Core.Qualities
{
public interface IQualitySizeService
{
void Update(QualitySize qualitySize);
void UpdateAll(List<QualitySize> qualitySizes);
List<QualitySize> All();
QualitySize Get(int qualityId);
}
public class QualitySizeService : IQualitySizeService, IHandle<ApplicationStartedEvent>
2013-02-27 04:19:22 +01:00
{
private readonly IQualitySizeRepository _qualitySizeRepository;
private readonly Logger _logger;
public QualitySizeService(IQualitySizeRepository qualitySizeRepository, Logger logger)
{
_qualitySizeRepository = qualitySizeRepository;
_logger = logger;
}
public virtual void Update(QualitySize qualitySize)
{
_qualitySizeRepository.Update(qualitySize);
}
public virtual void UpdateAll(List<QualitySize> qualitySizes)
{
_qualitySizeRepository.UpdateMany(qualitySizes);
}
public virtual List<QualitySize> All()
{
return _qualitySizeRepository.All().ToList();
}
public virtual QualitySize Get(int qualityId)
{
return _qualitySizeRepository.GetByQualityId(qualityId);
}
public void Handle(ApplicationStartedEvent message)
2013-02-27 04:19:22 +01:00
{
var existing = All();
2013-02-27 04:19:22 +01:00
_logger.Debug("Setting up default quality sizes");
foreach (var quality in Quality.All())
2013-02-27 04:19:22 +01:00
{
if (!existing.Any(s => s.QualityId == quality.Id))
{
2013-02-27 04:19:22 +01:00
_qualitySizeRepository.Insert(new QualitySize
{
QualityId = quality.Id,
Name = quality.Name,
MinSize = 0,
MaxSize = 100
});
}
2013-02-27 04:19:22 +01:00
}
}
}
}