Add HeadTitle and Notifications properties to Law model and update related mappings
This commit is contained in:
@@ -2,6 +2,8 @@ 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
|
||||
{
|
||||
@@ -12,13 +14,26 @@ namespace Company.Domain.LawAgg
|
||||
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 Law(string title, LawType lawType)
|
||||
[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 )
|
||||
{
|
||||
Title = title;
|
||||
IsActive = true;
|
||||
Items = new List<LawItem>();
|
||||
Type = lawType;
|
||||
Notifications = notifications ?? new List<string>();
|
||||
HeadTitle = headTitle;
|
||||
}
|
||||
|
||||
public void Edit(string title)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace CompanyManagment.App.Contracts.Law
|
||||
{
|
||||
@@ -11,6 +12,8 @@ namespace CompanyManagment.App.Contracts.Law
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public List<LawItemViewModel> Items { get; set; }
|
||||
public LawType Type { get; set; }
|
||||
public string HeadTitle { get; set; }
|
||||
public List<string> Notifications { get; set; }
|
||||
}
|
||||
|
||||
public class LawItemViewModel
|
||||
@@ -25,6 +28,8 @@ namespace CompanyManagment.App.Contracts.Law
|
||||
public string Title { get; set; }
|
||||
public List<LawItemViewModel> Items { get; set; }
|
||||
public LawType Type { get; set; }
|
||||
public string HeadTitle { get; set; }
|
||||
public List<string> Notifications { get; set; }
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +40,8 @@ namespace CompanyManagment.App.Contracts.Law
|
||||
public string Title { get; set; }
|
||||
public List<LawItemViewModel> Items { get; set; }
|
||||
public LawType Type { get; set; }
|
||||
public string HeadTitle { get; set; }
|
||||
public List<string> Notifications { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,12 +25,12 @@ public class LawApplication : ILawApplication
|
||||
return operation.Failed("این قانون قبلا ثبت شده است");
|
||||
}
|
||||
|
||||
var law = new Law(command.Title, command.Type);
|
||||
var law = new Law(command.Title, command.Type, command.Notifications, command.HeadTitle);
|
||||
if (command.Items == null || command.Items.Count == 0)
|
||||
{
|
||||
return operation.Failed("باید حداقل یک بند برای قانون باید ثبت شود");
|
||||
}
|
||||
|
||||
|
||||
var orderNumber = 1;
|
||||
foreach (var item in command.Items)
|
||||
{
|
||||
@@ -88,7 +88,7 @@ public class LawApplication : ILawApplication
|
||||
if (existingLaw == null)
|
||||
{
|
||||
// If law doesn't exist, create a new one
|
||||
var law = new Law(command.Title, command.Type);
|
||||
var law = new Law(command.Title, command.Type,command.Notifications, command.HeadTitle);
|
||||
|
||||
var orderNumber = 1;
|
||||
foreach (var item in command.Items)
|
||||
@@ -154,7 +154,7 @@ public class LawApplication : ILawApplication
|
||||
if (law == null)
|
||||
{
|
||||
// If law doesn't exist, create a new active one with default values
|
||||
var newLaw = new Law(GetDefaultTitleForLawType(type), type);
|
||||
var newLaw = new Law(GetDefaultTitleForLawType(type), type, new List<string>(), "");
|
||||
newLaw.Activate();
|
||||
_lawRepository.Create(newLaw);
|
||||
_lawRepository.SaveChanges();
|
||||
|
||||
@@ -25,6 +25,11 @@ namespace CompanyManagment.EFCore.Mapping
|
||||
navigationBuilder.Property(x => x.Details).IsRequired();
|
||||
navigationBuilder.Property(x => x.OrderNumber).IsRequired();
|
||||
});
|
||||
builder.Property(x => x.NotificationsJson)
|
||||
.HasColumnName("Notifications")
|
||||
.HasMaxLength(3000); // Set max length to 1000, adjust as needed
|
||||
|
||||
builder.Property(x => x.HeadTitle).HasMaxLength(200);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
10591
CompanyManagment.EFCore/Migrations/20250918070424_Add Head Title And Notification.Designer.cs
generated
Normal file
10591
CompanyManagment.EFCore/Migrations/20250918070424_Add Head Title And Notification.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,40 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace CompanyManagment.EFCore.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddHeadTitleAndNotification : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "HeadTitle",
|
||||
table: "Law",
|
||||
type: "nvarchar(200)",
|
||||
maxLength: 200,
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "Notifications",
|
||||
table: "Law",
|
||||
type: "nvarchar(3000)",
|
||||
maxLength: 3000,
|
||||
nullable: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "HeadTitle",
|
||||
table: "Law");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Notifications",
|
||||
table: "Law");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3866,9 +3866,18 @@ namespace CompanyManagment.EFCore.Migrations
|
||||
b.Property<DateTime>("CreationDate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("HeadTitle")
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("NotificationsJson")
|
||||
.HasMaxLength(3000)
|
||||
.HasColumnType("nvarchar(3000)")
|
||||
.HasColumnName("Notifications");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(255)
|
||||
|
||||
@@ -36,6 +36,9 @@ public class LawRepository:RepositoryBase<long,Law>,ILawRepository
|
||||
Title = x.Title,
|
||||
IsActive = x.IsActive,
|
||||
CreatedAt = x.CreationDate,
|
||||
HeadTitle = x.HeadTitle,
|
||||
Notifications = x.Notifications,
|
||||
Type = x.Type,
|
||||
Items = x.Items.OrderBy(i => i.OrderNumber).Select(i => new LawItemViewModel
|
||||
{
|
||||
Header = i.Header,
|
||||
|
||||
Reference in New Issue
Block a user