50 lines
1.2 KiB
C#
50 lines
1.2 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using MileageTraker.Web.Utility;
|
|
|
|
namespace MileageTraker.Web.Models
|
|
{
|
|
public enum MileageLogType
|
|
{
|
|
[Display(Name = "Non-Commuting",ShortName = "Non-Comm")]
|
|
NonCommuting = 1,
|
|
[Display(Name = "Commuting", ShortName = "Comm")]
|
|
Commuting = 2,
|
|
[Display(Name = "Gas Purchase", ShortName = "Gas")]
|
|
GasPurchase = 3
|
|
}
|
|
|
|
[ComplexType]
|
|
public class MileageLogTypeWrapper
|
|
{
|
|
[NotMapped]
|
|
public MileageLogType Enum { get; set; }
|
|
|
|
public int Value
|
|
{
|
|
get { return (int)Enum; }
|
|
set { Enum = (MileageLogType)value; }
|
|
}
|
|
|
|
public static implicit operator MileageLogType(MileageLogTypeWrapper w)
|
|
{
|
|
return w == null ? default(MileageLogType) : w.Enum;
|
|
}
|
|
|
|
public static implicit operator MileageLogTypeWrapper(MileageLogType c)
|
|
{
|
|
return new MileageLogTypeWrapper { Enum = c };
|
|
}
|
|
|
|
public static implicit operator MileageLogTypeWrapper(string s)
|
|
{
|
|
var ml = (MileageLogType) typeof(MileageLogType).ParseWithDisplayNames(s);
|
|
return new MileageLogTypeWrapper {Enum = ml};
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return Enum.GetDisplayName();
|
|
}
|
|
}
|
|
} |