Refactor Law model to use LawType enum and update repository methods for asynchronous operations
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
using _0_Framework.Domain;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using CompanyManagment.App.Contracts.Law;
|
||||
|
||||
namespace Company.Domain.LawAgg
|
||||
{
|
||||
public interface ILawRepository : IRepository<long, Law>
|
||||
{
|
||||
Law GetWithItems(long id);
|
||||
List<Law> GetActive();
|
||||
Task<Law> GetWithItems(long id);
|
||||
Task<List<Law>> GetActive();
|
||||
Task<LawViewModel> GetByType(LawType type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,17 +7,19 @@ 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 string LawType { get; private set; }
|
||||
public LawType Type { get; private set; }
|
||||
|
||||
public Law(string title, string lawType)
|
||||
public Law(string title, LawType lawType)
|
||||
{
|
||||
Title = title;
|
||||
IsActive = true;
|
||||
Items = new List<LawItem>();
|
||||
Type = lawType;
|
||||
}
|
||||
|
||||
public void Edit(string title)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using _0_Framework.Application;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CompanyManagment.App.Contracts.Law
|
||||
{
|
||||
@@ -11,6 +12,16 @@ namespace CompanyManagment.App.Contracts.Law
|
||||
OperationResult Deactivate(long id);
|
||||
EditLaw GetDetails(long id);
|
||||
List<LawViewModel> GetList();
|
||||
Task<LawViewModel> GetLawWithItems(long id);
|
||||
|
||||
Task<LawViewModel> GetLawByType(LawType type);
|
||||
|
||||
}
|
||||
public enum LawType
|
||||
{
|
||||
/// <summary>
|
||||
/// ثبت نام
|
||||
/// </summary>
|
||||
Register
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace CompanyManagment.App.Contracts.Law
|
||||
{
|
||||
public string Title { get; set; }
|
||||
public List<LawItemViewModel> Items { get; set; }
|
||||
public string Type { get; set; }
|
||||
public LawType Type { get; set; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using Company.Domain.LawAgg;
|
||||
using CompanyManagment.App.Contracts.Law;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CompanyManagment.Application
|
||||
{
|
||||
@@ -18,7 +19,7 @@ namespace CompanyManagment.Application
|
||||
public OperationResult Create(CreateLaw command)
|
||||
{
|
||||
var operation = new OperationResult();
|
||||
if (_lawRepository.Exists(x=>x.LawType == command.Type))
|
||||
if (_lawRepository.Exists(x=>x.Type == command.Type))
|
||||
{
|
||||
return operation.Failed("این قانون قبلا ثبت شده است");
|
||||
}
|
||||
@@ -109,9 +110,9 @@ namespace CompanyManagment.Application
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public LawViewModel GetLawWithItems(long id)
|
||||
public async Task<LawViewModel> GetLawWithItems(long id)
|
||||
{
|
||||
var law = _lawRepository.GetWithItems(id);
|
||||
var law =await _lawRepository.GetWithItems(id);
|
||||
return new LawViewModel
|
||||
{
|
||||
Id = law.id,
|
||||
@@ -126,5 +127,10 @@ namespace CompanyManagment.Application
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<LawViewModel> GetLawByType(LawType type)
|
||||
{
|
||||
return await _lawRepository.GetByType(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace CompanyManagment.EFCore.Mapping
|
||||
|
||||
builder.Property(x => x.Title).HasMaxLength(255).IsRequired();
|
||||
builder.Property(x => x.IsActive).IsRequired();
|
||||
builder.Property(x => x.LawType).HasMaxLength(50);
|
||||
builder.Property(x => x.Type).HasConversion<string>().HasMaxLength(50);
|
||||
|
||||
builder.OwnsMany(x => x.Items, navigationBuilder =>
|
||||
{
|
||||
|
||||
10565
CompanyManagment.EFCore/Migrations/20250907124211_add law type.Designer.cs
generated
Normal file
10565
CompanyManagment.EFCore/Migrations/20250907124211_add law type.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,41 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace CompanyManagment.EFCore.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class addlawtype : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "LawType",
|
||||
table: "Law");
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "Type",
|
||||
table: "Law",
|
||||
type: "nvarchar(50)",
|
||||
maxLength: 50,
|
||||
nullable: false,
|
||||
defaultValue: "");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Type",
|
||||
table: "Law");
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "LawType",
|
||||
table: "Law",
|
||||
type: "nvarchar(50)",
|
||||
maxLength: 50,
|
||||
nullable: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3864,15 +3864,16 @@ namespace CompanyManagment.EFCore.Migrations
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("LawType")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("nvarchar(50)");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("nvarchar(255)");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("nvarchar(50)");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.ToTable("Law", (string)null);
|
||||
|
||||
46
CompanyManagment.EFCore/Repository/LawRepository.cs
Normal file
46
CompanyManagment.EFCore/Repository/LawRepository.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using _0_Framework.InfraStructure;
|
||||
using Company.Domain.LawAgg;
|
||||
using CompanyManagment.App.Contracts.Law;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace CompanyManagment.EFCore.Repository;
|
||||
|
||||
public class LawRepository:RepositoryBase<long,Law>,ILawRepository
|
||||
{
|
||||
private readonly CompanyContext _context;
|
||||
public LawRepository(CompanyContext context) : base(context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<Law> GetWithItems(long id)
|
||||
{
|
||||
return await _context.Laws.Include(x => x.Items).FirstOrDefaultAsync(x => x.id == id);
|
||||
}
|
||||
|
||||
public async Task<List<Law>> GetActive()
|
||||
{
|
||||
return await _context.Laws.Where(x => x.IsActive).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<LawViewModel> GetByType(LawType type)
|
||||
{
|
||||
return await _context.Laws.Where(x => x.Type == type && x.IsActive)
|
||||
.Select(x => new LawViewModel
|
||||
{
|
||||
Id = x.id,
|
||||
Title = x.Title,
|
||||
IsActive = x.IsActive,
|
||||
CreatedAt = x.CreationDate,
|
||||
Items = x.Items.Select(i => new LawItemViewModel
|
||||
{
|
||||
Header = i.Header,
|
||||
Details = i.Details,
|
||||
OrderNumber = i.OrderNumber
|
||||
}).OrderBy(i => i.OrderNumber).ToList()
|
||||
}).FirstOrDefaultAsync();
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,6 @@ using Company.Domain.FileEmployerAgg;
|
||||
using Company.Domain.FileState;
|
||||
using Company.Domain.FileTiming;
|
||||
using Company.Domain.FileTitle;
|
||||
|
||||
using Company.Domain.HolidayAgg;
|
||||
using Company.Domain.HolidayItemAgg;
|
||||
using Company.Domain.JobAgg;
|
||||
@@ -219,6 +218,8 @@ using CompanyManagment.App.Contracts.PaymentInstrument;
|
||||
using CompanyManagment.App.Contracts.PaymentTransaction;
|
||||
using CompanyManagment.App.Contracts.AuthorizedPerson;
|
||||
using Company.Domain.AuthorizedPersonAgg;
|
||||
using Company.Domain.LawAgg;
|
||||
using CompanyManagment.App.Contracts.Law;
|
||||
using CompanyManagment.EFCore.Repository;
|
||||
|
||||
namespace PersonalContractingParty.Config;
|
||||
@@ -412,11 +413,13 @@ public class PersonalBootstrapper
|
||||
|
||||
services.AddTransient<IRollCallEmployeeStatusRepository, RollCallEmployeeStatusRepository>();
|
||||
services.AddTransient<IRollCallEmployeeStatusApplication, RollCallEmployeeStatusApplication>();
|
||||
|
||||
#region Mahan
|
||||
|
||||
services.AddTransient<ICustomizeWorkshopSettingsApplication, CustomizeWorkshopSettingsApplication>();
|
||||
services.AddTransient<ICustomizeWorkshopSettingsRepository, CustomizeWorkshopSettingsRepository>();
|
||||
services.AddTransient<ICustomizeWorkshopEmployeeSettingsRepository, CustomizeWorkshopEmployeeSettingsRepository>();
|
||||
services
|
||||
.AddTransient<ICustomizeWorkshopEmployeeSettingsRepository, CustomizeWorkshopEmployeeSettingsRepository>();
|
||||
services.AddTransient<ICustomizeWorkshopGroupSettingsRepository, CustomizeWorkshopGroupSettingsRepository>();
|
||||
|
||||
|
||||
@@ -464,14 +467,18 @@ public class PersonalBootstrapper
|
||||
services.AddTransient<IPaymentInstrumentApplication, PaymentInstrumentApplication>();
|
||||
services.AddTransient<IPaymentInstrumentGroupRepository, PaymentInstrumentGroupRepository>();
|
||||
|
||||
services.AddTransient<ILawApplication,LawApplication>();
|
||||
services.AddTransient<ILawRepository,LawRepository>();
|
||||
#endregion
|
||||
|
||||
#region Pooya
|
||||
|
||||
services.AddTransient<IEmployeeDocumentsApplication, EmployeeDocumentsApplication>();
|
||||
services.AddTransient<IEmployeeDocumentsRepository, EmployeeDocumentsRepository>();
|
||||
services.AddTransient<IEmployeeDocumentItemRepository, EmployeeDocumentItemRepository>();
|
||||
services.AddTransient<IEmployeeDocumentsAdminSelectionRepository, EmployeeDocumentsAdminSelectionRepository>();
|
||||
services.AddTransient<IEmployeeDocumentsAdminSelectionApplication, EmployeeDocumentsAdminSelectionApplication>();
|
||||
services
|
||||
.AddTransient<IEmployeeDocumentsAdminSelectionApplication, EmployeeDocumentsAdminSelectionApplication>();
|
||||
|
||||
services.AddTransient<ICustomizeCheckoutRepository, CustomizeCheckoutRepository>();
|
||||
services.AddTransient<ICustomizeCheckoutApplication, CustomizeCheckoutApplication>();
|
||||
@@ -486,6 +493,7 @@ public class PersonalBootstrapper
|
||||
|
||||
services.AddTransient<IEmployeeBankInformationRepository, EmployeeBankInformationRepository>();
|
||||
services.AddTransient<IEmployeeBankInformationApplication, EmployeeBankInformationApplication>();
|
||||
|
||||
#endregion
|
||||
|
||||
#region TemporaryClientRegisteration
|
||||
@@ -499,16 +507,17 @@ public class PersonalBootstrapper
|
||||
services.AddTransient<IInstitutionContractTempRepository, InstitutionContractTempRepository>();
|
||||
|
||||
#endregion
|
||||
|
||||
services.AddTransient<IRollCallDomainService, RollCallDomainService>();
|
||||
|
||||
|
||||
|
||||
services.AddTransient<IPlanPercentageRepository, PlanPercentageRepository>();
|
||||
services.AddTransient<IInstitutionPlanApplication, InstitutionPlanApplication>();
|
||||
//=========End Of Main====================================
|
||||
//=========End Of Main====================================
|
||||
|
||||
//---File Project------------------------------------
|
||||
//---File Project------------------------------------
|
||||
|
||||
services.AddTransient<IBoardApplication, BoardApplication>();
|
||||
services.AddTransient<IBoardApplication, BoardApplication>();
|
||||
services.AddTransient<IBoardRepository, BoardRepository>();
|
||||
|
||||
services.AddTransient<IFileApplication, FileApplication>();
|
||||
@@ -587,4 +596,4 @@ public class PersonalBootstrapper
|
||||
|
||||
services.AddDbContext<CompanyContext>(x => x.UseSqlServer(connectionString));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user