145 lines
4.3 KiB
C#
145 lines
4.3 KiB
C#
using System.Text.Json.Serialization;
|
||
|
||
namespace CORP_MAUI.Models;
|
||
|
||
/// <summary>
|
||
/// Модель документа
|
||
/// </summary>
|
||
public class Document
|
||
{
|
||
[JsonPropertyName("id")]
|
||
public int Id { get; set; }
|
||
|
||
[JsonPropertyName("title")]
|
||
public string Title { get; set; } = string.Empty;
|
||
|
||
[JsonPropertyName("description")]
|
||
public string Description { get; set; } = string.Empty;
|
||
|
||
[JsonPropertyName("uploaded_by")]
|
||
public User? UploadedBy { get; set; }
|
||
|
||
[JsonPropertyName("uploaded_at")]
|
||
public DateTime UploadedAt { get; set; }
|
||
|
||
[JsonPropertyName("sent_to_all")]
|
||
public bool SentToAll { get; set; }
|
||
|
||
[JsonPropertyName("departments")]
|
||
public List<object>? Departments { get; set; }
|
||
|
||
[JsonPropertyName("recipients")]
|
||
public List<object>? Recipients { get; set; }
|
||
|
||
[JsonPropertyName("file_url")]
|
||
public string FileUrl { get; set; } = string.Empty;
|
||
|
||
[JsonPropertyName("is_acknowledged")]
|
||
public bool IsAcknowledged { get; set; }
|
||
|
||
// Вычисляемые свойства для отображения
|
||
|
||
/// <summary>
|
||
/// Имя загрузившего документ
|
||
/// </summary>
|
||
[JsonIgnore]
|
||
public string UploaderName => UploadedBy?.FullName ?? "Неизвестный";
|
||
|
||
/// <summary>
|
||
/// URL аватара загрузившего
|
||
/// </summary>
|
||
[JsonIgnore]
|
||
public string UploaderAvatarUrl => UploadedBy?.Avatar ?? UploadedBy?.AvatarUrl ?? string.Empty;
|
||
|
||
/// <summary>
|
||
/// Форматированная дата загрузки
|
||
/// </summary>
|
||
[JsonIgnore]
|
||
public string DisplayUploadedAt => UploadedAt.ToString("dd.MM.yyyy HH:mm");
|
||
|
||
/// <summary>
|
||
/// Расширение файла (для иконки)
|
||
/// </summary>
|
||
[JsonIgnore]
|
||
public string FileExtension
|
||
{
|
||
get
|
||
{
|
||
if (string.IsNullOrEmpty(FileUrl)) return string.Empty;
|
||
try
|
||
{
|
||
// Декодируем URL и получаем расширение
|
||
string decodedUrl = Uri.UnescapeDataString(FileUrl);
|
||
int lastDot = decodedUrl.LastIndexOf('.');
|
||
if (lastDot > 0 && lastDot < decodedUrl.Length - 1)
|
||
{
|
||
return decodedUrl.Substring(lastDot + 1).ToLower();
|
||
}
|
||
}
|
||
catch
|
||
{
|
||
// Игнорируем ошибки декодирования
|
||
}
|
||
return string.Empty;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Иконка типа документа (эмодзи)
|
||
/// </summary>
|
||
[JsonIgnore]
|
||
public string FileIcon
|
||
{
|
||
get
|
||
{
|
||
return FileExtension switch
|
||
{
|
||
"pdf" => "📕",
|
||
"doc" or "docx" => "📘",
|
||
"xls" or "xlsx" => "📗",
|
||
"ppt" or "pptx" => "📙",
|
||
"txt" => "📄",
|
||
"jpg" or "jpeg" or "png" or "gif" or "webp" => "🖼️",
|
||
"zip" or "rar" or "7z" => "📦",
|
||
_ => "📄"
|
||
};
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Цвет статуса ознакомления
|
||
/// </summary>
|
||
[JsonIgnore]
|
||
public Color AcknowledgedColor => IsAcknowledged
|
||
? Color.FromArgb("#28A745") // Зеленый
|
||
: Color.FromArgb("#FFC107"); // Желтый
|
||
|
||
/// <summary>
|
||
/// Текст статуса ознакомления
|
||
/// </summary>
|
||
[JsonIgnore]
|
||
public string AcknowledgedText => IsAcknowledged ? "Ознакомлен" : "Не ознакомлен";
|
||
|
||
/// <summary>
|
||
/// Иконка статуса ознакомления
|
||
/// </summary>
|
||
[JsonIgnore]
|
||
public string AcknowledgedIcon => IsAcknowledged ? "✅" : "⏳";
|
||
|
||
/// <summary>
|
||
/// Короткое описание файла
|
||
/// </summary>
|
||
[JsonIgnore]
|
||
public string ShortDescription
|
||
{
|
||
get
|
||
{
|
||
if (!string.IsNullOrEmpty(Description))
|
||
{
|
||
return Description.Length > 100 ? Description.Substring(0, 100) + "..." : Description;
|
||
}
|
||
return SentToAll ? "Для всех сотрудников" : "Персональный документ";
|
||
}
|
||
}
|
||
}
|