Added Assets update CRUD element

This commit is contained in:
2025-10-03 23:07:55 +02:00
parent a803218982
commit b262a73d9d
6 changed files with 139 additions and 16 deletions

View File

@@ -1,10 +0,0 @@
namespace Berufsschule_HAM.Models;
public class Asset
{
public required string Dn { get; set; } // Full LDAP DN (readonly in many cases)
public required string CommonName { get; set; } // cn (display name)
public required string SerialNumber { get; set; } // serialNumber
public required string Description { get; set; } // description (notes)
public required string Location { get; set; } // l (location)
public required string Owner { get; set; } // owner (uid of owner)
}

46
src/Models/AssetsModel.cs Normal file
View File

@@ -0,0 +1,46 @@
namespace Berufsschule_HAM.Models;
using System.Text.Json;
using Berufsschule_HAM.Exceptions;
public class AssetModel
{
public required string Cn { get; set; }
public string? SerialNumber { get; set; }
public AssetDescription? Description { get; set; }
public string? Location { get; set; }
public string? Owner { get; set; }
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
{
public string? Type { get; set; }
public AssetPurchase? Purchase { get; set; }
}
public class AssetPurchase
{
public string? PurchaseDate { get; set; }
public string? PurchaseValue { get; set; }
public string? PurchasedAt { get; set; }
public string? PurchasedBy { get; set; }
}

View File

@@ -0,0 +1,12 @@
namespace Berufsschule_HAM.Models;
public class AssetsModifyRequestModel
{
public required string Cn { get; set; }
public string? NewCn { get; set; } = null;
public AssetDescription? Description { get; set; } = null;
public string? Location { get; set; } = null;
public string? Name { get; set; } = null;
public string? Owner { get; set; } = null;
public string? SerialNumber { get; set; } = null;
}