117 lines
3.2 KiB
C#
117 lines
3.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using _0_Framework.Domain;
|
|
using CompanyManagment.App.Contracts.Law;
|
|
using System.Text.Json;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
namespace Company.Domain.LawAgg
|
|
{
|
|
public class Law : EntityBase
|
|
{
|
|
private Law(){}
|
|
public string Title { get; private set; }
|
|
public bool IsActive { get; private set; }
|
|
public List<LawItem> Items { get; private set; }
|
|
public LawType Type { get; private set; }
|
|
public string HeadTitle { get; private set; }
|
|
public string NotificationsJson { get; private set; }
|
|
public int Version { get; private set; }
|
|
|
|
[NotMapped]
|
|
public List<string> Notifications
|
|
{
|
|
get => string.IsNullOrEmpty(NotificationsJson)
|
|
? new List<string>()
|
|
: JsonSerializer.Deserialize<List<string>>(NotificationsJson);
|
|
set => NotificationsJson = JsonSerializer.Serialize(value);
|
|
}
|
|
|
|
public Law(string title, LawType lawType, List<string> notifications, string headTitle, int version = 1)
|
|
{
|
|
Title = title;
|
|
IsActive = true; // آخرین نسخه فعال است
|
|
Items = new List<LawItem>();
|
|
Type = lawType;
|
|
Notifications = notifications ?? new List<string>();
|
|
HeadTitle = headTitle;
|
|
Version = version;
|
|
}
|
|
|
|
public void Edit(string title)
|
|
{
|
|
Title = title;
|
|
}
|
|
|
|
public void AddItem(string header, string details, int orderNumber)
|
|
{
|
|
Items.Add(new LawItem(header, details, orderNumber));
|
|
}
|
|
|
|
public void SetItem(List<LawItem> items)
|
|
{
|
|
Items = items ?? new List<LawItem>();
|
|
}
|
|
public void RemoveItem(int orderNumber)
|
|
{
|
|
var item = Items.Find(x => x.OrderNumber == orderNumber);
|
|
if (item != null)
|
|
Items.Remove(item);
|
|
}
|
|
|
|
public void Activate()
|
|
{
|
|
IsActive = true;
|
|
}
|
|
|
|
public void Deactivate()
|
|
{
|
|
IsActive = false;
|
|
}
|
|
|
|
public void SetAsLatestVersion()
|
|
{
|
|
IsActive = true;
|
|
}
|
|
|
|
public void SetAsOldVersion()
|
|
{
|
|
IsActive = false;
|
|
}
|
|
|
|
public Law CreateNewVersion(string title, List<string> notifications, string headTitle, List<LawItem> items)
|
|
{
|
|
var newVersion = new Law(
|
|
title,
|
|
this.Type,
|
|
notifications,
|
|
headTitle,
|
|
this.Version + 1
|
|
);
|
|
|
|
newVersion.SetItem(items);
|
|
newVersion.SetAsLatestVersion();
|
|
|
|
return newVersion;
|
|
}
|
|
}
|
|
|
|
public class LawItem
|
|
{
|
|
public long Id { get; set; }
|
|
public string Header { get; private set; }
|
|
public string Details { get; private set; }
|
|
public int OrderNumber { get; private set; }
|
|
public long LawId { get; set; }
|
|
|
|
protected LawItem() { }
|
|
|
|
public LawItem(string header, string details, int orderNumber)
|
|
{
|
|
Header = header;
|
|
Details = details;
|
|
OrderNumber = orderNumber;
|
|
}
|
|
}
|
|
}
|