Add Modifier model
This commit is contained in:
@ -94,5 +94,15 @@ namespace Elwig.Helpers {
|
||||
public static double OeToKmw(double oe) {
|
||||
return Math.Round((-4.54 + Math.Sqrt(4.54 * 4.54 - 4 * 0.022 * -oe)) / 2 * 0.022, 1);
|
||||
}
|
||||
|
||||
public static decimal DecFromDb(long value, byte precision) {
|
||||
bool neg = value < 0;
|
||||
if (neg) value = -value;
|
||||
return new decimal((int)(value & 0xFFFFFFFF), (int)((value >> 32) & 0x7FFFFFFF), 0, neg, precision);
|
||||
}
|
||||
|
||||
public static long DecToDb(decimal value, byte precision) {
|
||||
return (long)decimal.Round(value * precision, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Elwig.Helpers;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Elwig.Models {
|
||||
@ -14,9 +15,9 @@ namespace Elwig.Models {
|
||||
public string? Symbol { get; private set; }
|
||||
|
||||
[Column("one_euro")]
|
||||
public int? OneEuroValue { get; private set; }
|
||||
public long? OneEuroValue { get; private set; }
|
||||
|
||||
[NotMapped]
|
||||
public decimal? OneEuro => OneEuroValue / 1_000_000;
|
||||
public decimal? OneEuro => OneEuroValue != null ? Utils.DecFromDb((long)OneEuroValue, 6) : null;
|
||||
}
|
||||
}
|
||||
|
42
Elwig/Models/Modifier.cs
Normal file
42
Elwig/Models/Modifier.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Elwig.Models {
|
||||
[Table("modifier"), PrimaryKey("Year", "ModId")]
|
||||
public class Modifier {
|
||||
[Column("year")]
|
||||
public int Year { get; set; }
|
||||
|
||||
[Column("modid")]
|
||||
public string ModId { get; set; }
|
||||
|
||||
[Column("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column("abs")]
|
||||
public long? AbsValue { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public decimal? Abs {
|
||||
get {
|
||||
return AbsValue != null ? Season.DecFromDb((long)AbsValue) : null;
|
||||
}
|
||||
set {
|
||||
AbsValue = value != null ? Season.DecToDb((decimal)value) : null;
|
||||
}
|
||||
}
|
||||
|
||||
[Column("rel")]
|
||||
public double? Rel { get; set; }
|
||||
|
||||
[Column("standard")]
|
||||
public bool IsStandard { get; set; }
|
||||
|
||||
[Column("quick_select")]
|
||||
public bool IsQuickSelect { get; set; }
|
||||
|
||||
[ForeignKey("Year")]
|
||||
public virtual Season Season { get; private set; }
|
||||
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Elwig.Helpers;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Elwig.Models {
|
||||
@ -12,7 +14,7 @@ namespace Elwig.Models {
|
||||
public string CurrencyCode { get; set; }
|
||||
|
||||
[Column("precision")]
|
||||
public int Precision { get; set; }
|
||||
public byte Precision { get; set; }
|
||||
|
||||
[Column("start_date")]
|
||||
public string? StartDateString { get; set; }
|
||||
@ -42,5 +44,16 @@ namespace Elwig.Models {
|
||||
|
||||
[ForeignKey("CurrencyCode")]
|
||||
public virtual Currency Currency { get; private set; }
|
||||
|
||||
[InverseProperty("Season")]
|
||||
public virtual ISet<Modifier> Modifiers { get; private set; }
|
||||
|
||||
public decimal DecFromDb(long value) {
|
||||
return Utils.DecFromDb(value, Precision);
|
||||
}
|
||||
|
||||
public long DecToDb(decimal value) {
|
||||
return Utils.DecToDb(value, Precision);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user