Files
Berufsschule_HAM/src/Models/AssetsModel.cs

73 lines
2.3 KiB
C#

namespace Berufsschule_HAM.Models;
using System.Text.Json;
using System.Text.Json.Serialization;
using Berufsschule_HAM.Exceptions;
public class AssetModel
{
[JsonPropertyName("Cn")]
public required string Cn { get; set; }
[JsonPropertyName("SerialNumber")]
public string? SerialNumber { get; set; }
[JsonPropertyName("Description")]
public AssetDescription? Description { get; set; }
[JsonPropertyName("Location")]
public string? Location { get; set; }
[JsonPropertyName("Owner")]
public string? Owner { get; set; }
[JsonPropertyName("Name")]
public string? Name { get; set; }
public AssetModel(Dictionary<string, string> ldapData)
{
Cn = ldapData.GetValueOrDefault("cn") ?? throw new AssetModelConfigurationException();
SerialNumber = ldapData.GetValueOrDefault("serialNumber");
Location = ldapData.GetValueOrDefault("l");
Owner = ldapData.GetValueOrDefault("owner");
Name = ldapData.GetValueOrDefault("name");
string? descriptionValue = ldapData.GetValueOrDefault("description");
if (descriptionValue is null)
{
Description = new();
}
else
{
Description = JsonSerializer.Deserialize<AssetDescription>(descriptionValue) ?? new();
}
}
}
public class AssetDescription
{
[JsonPropertyName("Type")]
public string? Type { get; set; }
[JsonPropertyName("Make")]
public string? Make { get; set; }
[JsonPropertyName("Model")]
public string? Model { get; set; }
[JsonPropertyName("Attributes")]
public Dictionary<string, string>? Attributes { get; set; }
[JsonPropertyName("Purchase")]
public AssetPurchase? Purchase { get; set; }
}
public class AssetPurchase
{
[JsonPropertyName("PurchaseDate")]
public string? PurchaseDate { get; set; }
[JsonPropertyName("PurchaseValue")]
public string? PurchaseValue { get; set; }
[JsonPropertyName("PurchaseAt")]
public string? PurchasedAt { get; set; }
[JsonPropertyName("PurchaseBy")]
public string? PurchasedBy { get; set; }
}
public class AssetsTableViewModel
{
public string? UserUID { get; set; }
public required string AssetCn { get; set; }
public string? AssetName { get; set; }
public string? LocationName { get; set; }
}