DD.WellWorkover.Cloud/AsbCloudApp/Data/NotificationDto.cs

110 lines
2.9 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.ComponentModel.DataAnnotations;
namespace AsbCloudApp.Data;
/// <summary>
/// DTO уведомления
/// </summary>
public class NotificationDto : IId
{
/// <summary>
/// Id уведомления
/// </summary>
[Required]
public int Id { get; set; }
/// <summary>
/// Id получателя уведомления
/// </summary>
[Required]
public int IdUser { get; set; }
/// <summary>
/// Id категории уведомления
/// </summary>
[Required]
public int IdNotificationCategory { get; set; }
/// <summary>
/// Заголовок уведомления
/// </summary>
[Required, StringLength(300, MinimumLength = 1, ErrorMessage = "Заголовок должен мыть не меньше 1-го знака и не больше 300")]
public string Title { get; set; } = null!;
/// <summary>
/// Сообщение уведомления
/// </summary>
[Required, StringLength(2048, MinimumLength = 1, ErrorMessage = "Заголовок должен мыть не меньше 1-го знака и не больше 2048")]
public string Message { get; set; } = null!;
/// <summary>
/// Дата регистрации уведомления
/// </summary>
[Required]
public DateTimeOffset RegistrationDate { get; set; }
/// <summary>
/// Дата отправки уведомления
/// </summary>
public DateTimeOffset? SentDate { get; set; }
/// <summary>
/// Дата прочтения уведомления
/// </summary>
public DateTimeOffset? ReadDate { get; set; }
/// <summary>
/// Состояние уведомления
/// 0 - Зарегистрировано,
/// 1 - Отправлено,
/// 2 - Прочитано
/// </summary>
[Required]
public int IdState
{
get
{
if (SentDate is not null && ReadDate is not null)
return 2;
if (SentDate is not null)
return 1;
return 0;
}
set
{
switch (value)
{
case 0:
SentDate = null;
ReadDate = null;
break;
case 1:
SentDate = DateTimeOffset.UtcNow;
ReadDate = null;
break;
case 2:
SentDate = DateTimeOffset.UtcNow;
ReadDate = DateTimeOffset.UtcNow;
break;
}
}
}
/// <summary>
/// Id типа доставки уведомления
/// 0 - SignalR
/// 1 - Email
/// </summary>
[Required]
[Range(0,1)]
public int IdTransportType { get; set; }
/// <summary>
/// DTO категории уведомления
/// </summary>
[Required]
public NotificationCategoryDto NotificationCategory { get; set; } = null!;
}