Files
parr_api/PARR.DAL/Models/Unit/Unit.cs

96 lines
3.1 KiB
C#
Raw 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 Microsoft.EntityFrameworkCore;
using PARR.DAL.Context;
using PARR.DAL.Models.Base;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace PARR.DAL.Models.Unit
{
[Table("Units", Schema = DataContextSettings.Unit)]
[Comment("Таблица с ЭК")]
[Index(nameof(Name), IsUnique = true)]
public class Unit : IBase
{
[Key]
public Guid Id { get; set; }
public DateTimeOffset DateCreated { get; set; }
[NotMapped]
public DateTimeOffset? DateModified { get; set; }
/// <summary>
/// ЭК
/// </summary>
public required string Name { get; set; }
public DateTimeOffset? LastLogon { get; set; }
[NotMapped]
public BaseFields? BaseFields
{
get
{
if (UnitValues.Any())
{
var result = new BaseFields();
result.IP = UnitValues.FirstOrDefault(t => t.Field?.AihitName == "IP_АДРЕС")?.Value?.Value;
result.ResponseArea = UnitValues.FirstOrDefault(t => t.Field?.AihitName == "ЗО_РГ")?.Value?.Value;
result.WorkGroup = UnitValues.FirstOrDefault(t => t.Field?.AihitName == "РАБОЧАЯ_ГР_ОТВ_ЗАК")?.Value?.Value;
result.Status = UnitValues.FirstOrDefault(t => t.Field?.AihitName == "СТАТУС")?.Value?.Value;
result.NotUnique = UnitValues.FirstOrDefault(t => t.Field?.AihitName == "НЕУНИКАЛЬНЫЙ_ЭК")?.Value?.Value;
return result;
}
return null;
}
}
public ICollection<UnitInField> UnitFields { get; set; } = new HashSet<UnitInField>();
public ICollection<UnitInValue> UnitValues { get; set; } = new HashSet<UnitInValue>();
/// <summary>
/// Получить всех родителей
/// </summary>
[InverseProperty(nameof(UnitInUnit.ChildUnit))]
public ICollection<UnitInUnit> ParentUnits { get; set; } = new HashSet<UnitInUnit>();
/// <summary>
/// Получить детей
/// </summary>
[InverseProperty(nameof(UnitInUnit.ParentUnit))]
public ICollection<UnitInUnit> ChildUnits { get; set; } = new HashSet<UnitInUnit>();
/// <summary>
/// Связь с шаблонами. Один ко многим
/// </summary>
public ICollection<Template> Templates { get; set; } = new HashSet<Template>();
/// <summary>
/// К одному шаблону привязано несколько ЭК(Груповой тип работы). Многие ко многим
/// </summary>
public ICollection<UnitsInTemplate> TemplatesInUnit { get; set; } = new HashSet<UnitsInTemplate>();
}
public class BaseFields
{
public string? IP { get; set; }
public string? ResponseArea { get; set; }
public string? WorkGroup { get; set; }
public string? Status { get; set; }
public string? NotUnique { get; set; }
}
}