2024-09-04 16:48:04 -05:00
|
|
|
|
using LANCommander.SDK.Enums;
|
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2023-01-07 20:54:24 -06:00
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
2023-01-12 01:25:32 -06:00
|
|
|
|
using System.Text.Json.Serialization;
|
2023-01-07 20:54:24 -06:00
|
|
|
|
|
2024-08-04 18:44:33 -05:00
|
|
|
|
namespace LANCommander.Server.Data.Models
|
2023-01-07 20:54:24 -06:00
|
|
|
|
{
|
|
|
|
|
|
[Table("Keys")]
|
|
|
|
|
|
public class Key : BaseModel
|
|
|
|
|
|
{
|
|
|
|
|
|
[MaxLength(255)]
|
|
|
|
|
|
public string Value { get; set; }
|
2023-03-20 20:55:29 -05:00
|
|
|
|
public Guid GameId { get; set; }
|
2023-01-12 01:25:32 -06:00
|
|
|
|
[JsonIgnore]
|
2023-03-20 20:55:29 -05:00
|
|
|
|
[ForeignKey(nameof(GameId))]
|
|
|
|
|
|
[InverseProperty("Keys")]
|
2024-11-27 01:51:47 -06:00
|
|
|
|
public Game Game { get; set; }
|
2023-01-07 20:54:24 -06:00
|
|
|
|
public KeyAllocationMethod AllocationMethod { get; set; }
|
|
|
|
|
|
[MaxLength(17)]
|
|
|
|
|
|
public string? ClaimedByMacAddress { get; set; }
|
|
|
|
|
|
[MaxLength(15)]
|
|
|
|
|
|
public string? ClaimedByIpv4Address { get; set; }
|
|
|
|
|
|
[MaxLength(255)]
|
|
|
|
|
|
public string? ClaimedByComputerName { get; set; }
|
2024-11-27 01:51:47 -06:00
|
|
|
|
public User? ClaimedByUser { get; set; }
|
2023-01-07 20:54:24 -06:00
|
|
|
|
public DateTime? ClaimedOn { get; set; }
|
2023-03-02 18:50:24 -06:00
|
|
|
|
|
|
|
|
|
|
public bool IsAllocated()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (AllocationMethod == KeyAllocationMethod.MacAddress && !String.IsNullOrWhiteSpace(ClaimedByMacAddress))
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
if (AllocationMethod == KeyAllocationMethod.UserAccount && ClaimedByUser != null)
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2023-01-07 20:54:24 -06:00
|
|
|
|
}
|
|
|
|
|
|
}
|