mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-29 02:57:15 +02:00
48 lines
1.1 KiB
C#
48 lines
1.1 KiB
C#
using System;
|
|
using Marr.Data.Converters;
|
|
using Marr.Data.Mapping;
|
|
using NzbDrone.Core.Qualities;
|
|
|
|
namespace NzbDrone.Core.Datastore.Converters
|
|
{
|
|
public class QualityIntConverter : IConverter
|
|
{
|
|
public object FromDB(ConverterContext context)
|
|
{
|
|
if (context.DbValue == DBNull.Value)
|
|
{
|
|
return Quality.Unknown;
|
|
}
|
|
|
|
var val = Convert.ToInt32(context.DbValue);
|
|
|
|
return (Quality)val;
|
|
}
|
|
|
|
public object FromDB(ColumnMap map, object dbValue)
|
|
{
|
|
return FromDB(new ConverterContext { ColumnMap = map, DbValue = dbValue });
|
|
}
|
|
|
|
public object ToDB(object clrValue)
|
|
{
|
|
if(clrValue == null) return 0;
|
|
|
|
if(clrValue as Quality == null)
|
|
{
|
|
throw new InvalidOperationException("Attempted to save a quality that isn't really a quality");
|
|
}
|
|
|
|
var quality = clrValue as Quality;
|
|
return (int)quality;
|
|
}
|
|
|
|
public Type DbType
|
|
{
|
|
get
|
|
{
|
|
return typeof(int);
|
|
}
|
|
}
|
|
}
|
|
} |