AccessSchedule.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. using System.ComponentModel.DataAnnotations;
  3. using System.ComponentModel.DataAnnotations.Schema;
  4. using System.Text.Json.Serialization;
  5. using System.Xml.Serialization;
  6. using Jellyfin.Data.Enums;
  7. namespace Jellyfin.Data.Entities
  8. {
  9. /// <summary>
  10. /// An entity representing a user's access schedule.
  11. /// </summary>
  12. public class AccessSchedule
  13. {
  14. /// <summary>
  15. /// Initializes a new instance of the <see cref="AccessSchedule"/> class.
  16. /// </summary>
  17. /// <param name="dayOfWeek">The day of the week.</param>
  18. /// <param name="startHour">The start hour.</param>
  19. /// <param name="endHour">The end hour.</param>
  20. /// <param name="userId">The associated user's id.</param>
  21. public AccessSchedule(DynamicDayOfWeek dayOfWeek, double startHour, double endHour, Guid userId)
  22. {
  23. UserId = userId;
  24. DayOfWeek = dayOfWeek;
  25. StartHour = startHour;
  26. EndHour = endHour;
  27. }
  28. /// <summary>
  29. /// Initializes a new instance of the <see cref="AccessSchedule"/> class.
  30. /// Default constructor. Protected due to required properties, but present because EF needs it.
  31. /// </summary>
  32. protected AccessSchedule()
  33. {
  34. }
  35. /// <summary>
  36. /// Gets or sets the id of this instance.
  37. /// </summary>
  38. /// <remarks>
  39. /// Identity, Indexed, Required.
  40. /// </remarks>
  41. [XmlIgnore]
  42. [Key]
  43. [Required]
  44. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  45. public int Id { get; protected set; }
  46. /// <summary>
  47. /// Gets or sets the id of the associated user.
  48. /// </summary>
  49. [XmlIgnore]
  50. [Required]
  51. public Guid UserId { get; protected set; }
  52. /// <summary>
  53. /// Gets or sets the day of week.
  54. /// </summary>
  55. /// <value>The day of week.</value>
  56. [Required]
  57. public DynamicDayOfWeek DayOfWeek { get; set; }
  58. /// <summary>
  59. /// Gets or sets the start hour.
  60. /// </summary>
  61. /// <value>The start hour.</value>
  62. [Required]
  63. public double StartHour { get; set; }
  64. /// <summary>
  65. /// Gets or sets the end hour.
  66. /// </summary>
  67. /// <value>The end hour.</value>
  68. [Required]
  69. public double EndHour { get; set; }
  70. /// <summary>
  71. /// Static create function (for use in LINQ queries, etc.)
  72. /// </summary>
  73. /// <param name="dayOfWeek">The day of the week.</param>
  74. /// <param name="startHour">The start hour.</param>
  75. /// <param name="endHour">The end hour.</param>
  76. /// <param name="userId">The associated user's id.</param>
  77. /// <returns>The newly created instance.</returns>
  78. public static AccessSchedule Create(DynamicDayOfWeek dayOfWeek, double startHour, double endHour, Guid userId)
  79. {
  80. return new AccessSchedule(dayOfWeek, startHour, endHour, userId);
  81. }
  82. }
  83. }