[#34] Second step of not using Bio as Attribute

This commit is contained in:
2024-02-20 16:36:12 +01:00
parent 049927f90c
commit c82e8de724
9 changed files with 140 additions and 77 deletions

View File

@ -7,18 +7,18 @@ using System.Text.Json.Nodes;
namespace Elwig.Helpers.Billing {
public class EditBillingData : BillingData {
protected readonly IEnumerable<string> Vaributes;
protected readonly IEnumerable<RawVaribute> Vaributes;
public EditBillingData(JsonObject data, IEnumerable<string> vaributes) :
public EditBillingData(JsonObject data, IEnumerable<RawVaribute> vaributes) :
base(data) {
Vaributes = vaributes;
}
public static EditBillingData FromJson(string json, IEnumerable<string> vaributes) {
public static EditBillingData FromJson(string json, IEnumerable<RawVaribute> vaributes) {
return new(ParseJson(json), vaributes);
}
private (Dictionary<int, Curve>, Dictionary<int, List<string>>) GetGraphEntries(JsonNode root) {
private (Dictionary<int, Curve>, Dictionary<int, List<RawVaribute>>) GetGraphEntries(JsonNode root) {
Dictionary<int, List<string>> dict1 = [];
Dictionary<decimal, List<string>> dict2 = [];
if (root is JsonObject paymentObj) {
@ -55,7 +55,7 @@ namespace Elwig.Helpers.Billing {
curves[i + virtOffset] = new Curve(CurveMode.Oe, new() { { 73, idx } }, null);
}
Dictionary<int, List<string>> dict3 = curves.ToDictionary(c => c.Key, _ => new List<string>());
Dictionary<int, List<RawVaribute>> dict3 = curves.ToDictionary(c => c.Key, _ => new List<RawVaribute>());
foreach (var (selector, value) in GetSelection(root, Vaributes)) {
int? idx = null;
if (value.TryGetValue<decimal>(out var val)) {
@ -73,13 +73,14 @@ namespace Elwig.Helpers.Billing {
private static List<GraphEntry> CreateGraphEntries(
AppDbContext ctx, int precision,
Dictionary<int, Curve> curves,
Dictionary<int, List<string>> entries
Dictionary<int, List<RawVaribute>> entries
) {
var vars = ctx.WineVarieties.ToDictionary(v => v.SortId, v => v);
var attrs = ctx.WineAttributes.ToDictionary(a => a.AttrId, a => a);
var cults = ctx.WineCultivations.ToDictionary(c => c.CultId, c => c);
return entries
.Select(e => new GraphEntry(e.Key, precision, curves[e.Key], e.Value
.Select(s => new Varibute(vars[s[..2]], s.Length > 2 ? attrs[s[2..]] : null))
.Select(s => new Varibute(s, vars, attrs, cults))
.ToList()))
.ToList();
}