kreta/Kreta.WebApi/Ellenorzo/Kreta.Ellenorzo.Domain/VN/UniqueIdentifier/TanevRendjeUid.cs
2024-03-13 00:33:46 +01:00

34 lines
1.1 KiB
C#

using System.Collections.Generic;
using Kreta.Ellenorzo.Domain.VN.Interfaces;
using Kreta.Ellenorzo.Domain.VN.Logic;
namespace Kreta.Ellenorzo.Domain.VN.UniqueIdentifier
{
public class TanevRendjeUid : IReadonlyUidRaw, IEqualityComparer<TanevRendjeUid>
{
public TanevRendjeUid(int id, int? osztalyCsoportId)
{
Id = id;
OsztalyCsoportId = osztalyCsoportId;
UidRaw = UidLogic.Concat(id, osztalyCsoportId);
}
public TanevRendjeUid(string uidRaw)
{
var compositeKeyElements = UidLogic.GetCompositeKeyElements(uidRaw);
Id = int.Parse(compositeKeyElements[0]);
OsztalyCsoportId = int.TryParse(compositeKeyElements[1], out var result) ? (int?)result : null;
UidRaw = uidRaw;
}
public int Id { get; private set; }
public int? OsztalyCsoportId { get; private set; }
public string UidRaw { get; private set; }
public bool Equals(TanevRendjeUid x, TanevRendjeUid y) => x == y || x.UidRaw == y.UidRaw;
public int GetHashCode(TanevRendjeUid obj) => obj.UidRaw.GetHashCode();
}
}