88 lines
2.8 KiB
C#
88 lines
2.8 KiB
C#
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; }
|
||
|
||
public DateTimeOffset? DateModified { get; set; }
|
||
|
||
/// <summary>
|
||
/// ЭК
|
||
/// </summary>
|
||
public required string Name { get; set; }
|
||
|
||
//статус ЭК
|
||
|
||
// todo: добавить еще поля??? (которые есть у всех ЭК)
|
||
|
||
|
||
[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>();
|
||
|
||
public ICollection<Template> Templates { get; set; } = new HashSet<Template>();
|
||
}
|
||
|
||
|
||
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; }
|
||
}
|
||
}
|