jellyfin/Jellyfin.Data/Entities/AccessSchedule.cs

91 lines
3 KiB
C#
Raw Normal View History

2020-05-15 23:24:01 +02:00
using System;
using System.ComponentModel.DataAnnotations;
2020-05-13 04:10:35 +02:00
using System.ComponentModel.DataAnnotations.Schema;
2020-05-15 23:24:01 +02:00
using System.Text.Json.Serialization;
2020-05-13 04:10:35 +02:00
using Jellyfin.Data.Enums;
namespace Jellyfin.Data.Entities
{
2020-05-23 02:20:18 +02:00
/// <summary>
/// An entity representing a user's access schedule.
/// </summary>
2020-05-13 04:10:35 +02:00
public class AccessSchedule
{
/// <summary>
/// Initializes a new instance of the <see cref="AccessSchedule"/> class.
/// </summary>
/// <param name="dayOfWeek">The day of the week.</param>
/// <param name="startHour">The start hour.</param>
/// <param name="endHour">The end hour.</param>
2020-05-23 02:20:18 +02:00
/// <param name="userId">The associated user's id.</param>
2020-05-15 23:24:01 +02:00
public AccessSchedule(DynamicDayOfWeek dayOfWeek, double startHour, double endHour, Guid userId)
2020-05-13 04:10:35 +02:00
{
2020-05-15 23:24:01 +02:00
UserId = userId;
2020-05-13 04:10:35 +02:00
DayOfWeek = dayOfWeek;
StartHour = startHour;
EndHour = endHour;
}
/// <summary>
2020-05-23 02:20:18 +02:00
/// Initializes a new instance of the <see cref="AccessSchedule"/> class.
/// Default constructor. Protected due to required properties, but present because EF needs it.
2020-05-13 04:10:35 +02:00
/// </summary>
2020-05-23 02:20:18 +02:00
protected AccessSchedule()
2020-05-13 04:10:35 +02:00
{
}
2020-05-23 02:20:18 +02:00
/// <summary>
/// Gets or sets the id of this instance.
/// </summary>
/// <remarks>
/// Identity, Indexed, Required.
/// </remarks>
2020-05-15 23:24:01 +02:00
[JsonIgnore]
2020-05-13 04:10:35 +02:00
[Key]
[Required]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
2020-05-23 02:20:18 +02:00
public int Id { get; protected set; }
2020-05-15 23:24:01 +02:00
2020-05-23 02:20:18 +02:00
/// <summary>
/// Gets or sets the id of the associated user.
/// </summary>
2020-05-15 23:24:01 +02:00
[Required]
[ForeignKey("Id")]
2020-05-23 02:20:18 +02:00
public Guid UserId { get; protected set; }
2020-05-13 04:10:35 +02:00
/// <summary>
/// Gets or sets the day of week.
/// </summary>
/// <value>The day of week.</value>
[Required]
public DynamicDayOfWeek DayOfWeek { get; set; }
/// <summary>
/// Gets or sets the start hour.
/// </summary>
/// <value>The start hour.</value>
[Required]
public double StartHour { get; set; }
/// <summary>
/// Gets or sets the end hour.
/// </summary>
/// <value>The end hour.</value>
[Required]
public double EndHour { get; set; }
2020-05-23 02:20:18 +02:00
/// <summary>
/// Static create function (for use in LINQ queries, etc.)
/// </summary>
/// <param name="dayOfWeek">The day of the week.</param>
/// <param name="startHour">The start hour.</param>
/// <param name="endHour">The end hour.</param>
/// <param name="userId">The associated user's id.</param>
/// <returns>The newly created instance.</returns>
public static AccessSchedule Create(DynamicDayOfWeek dayOfWeek, double startHour, double endHour, Guid userId)
{
return new AccessSchedule(dayOfWeek, startHour, endHour, userId);
}
2020-05-13 04:10:35 +02:00
}
}