LANCommander/LANCommander.Server.Data/Models/PlaySession.cs

39 lines
1,019 B
C#
Raw Normal View History

2023-11-17 02:28:46 -06:00
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
2024-08-04 18:44:33 -05:00
namespace LANCommander.Server.Data.Models
2023-11-17 02:28:46 -06:00
{
[Table("PlaySessions")]
public class PlaySession : BaseModel
{
public Guid? GameId { get; set; }
2023-11-17 02:28:46 -06:00
[JsonIgnore]
[ForeignKey(nameof(GameId))]
[InverseProperty("PlaySessions")]
2024-11-27 01:51:47 -06:00
public Game? Game { get; set; }
2023-11-17 02:28:46 -06:00
public Guid UserId { get; set; }
[ForeignKey(nameof(UserId))]
[InverseProperty("PlaySessions")]
2024-11-27 01:51:47 -06:00
public User? User { get; set; }
2023-11-17 02:28:46 -06:00
[Display(Name = "Start")]
public DateTime? Start { get; set; }
[Display(Name = "End")]
public DateTime? End { get; set; }
2024-11-27 01:51:47 -06:00
public TimeSpan? Duration
{
get
{
if (!Start.HasValue) return null;
if (!End.HasValue) return null;
return End.Value.Subtract(Start.Value);
}
}
2023-11-17 02:28:46 -06:00
}
}