Files
Backend-Api/CompanyManagment.Application/ClassificationSchemeApplication.cs
2025-10-08 17:41:23 +03:30

127 lines
5.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using _0_Framework.Application;
using Company.Domain.ClassificationSchemeAgg;
using CompanyManagment.App.Contracts.ClassificationScheme;
namespace CompanyManagment.Application;
public class ClassificationSchemeApplication : IClassificationSchemeApplication
{
private readonly IClassificationSchemeRepository _classificationSchemeRepository;
private readonly IClassificationGroupRepository _classificationGroupRepository;
public ClassificationSchemeApplication(IClassificationSchemeRepository classificationSchemeRepository, IClassificationGroupRepository classificationGroupRepository)
{
_classificationSchemeRepository = classificationSchemeRepository;
_classificationGroupRepository = classificationGroupRepository;
}
public Task<ClassificationSchemePartialModel> ClassificationSchemePartialModel(long workshopId)
{
return _classificationSchemeRepository.ClassificationSchemePartialModel(workshopId);
}
public async Task<OperationResult> CreateClassificationScheme(CreateClassificationScheme command)
{
var op = new OperationResult();
try
{
command.ExecutionDateGr = command.ExecutionDateFa.ToGeorgianDateTime();
command.IncludingDateGr = command.IncludingDateFa.ToGeorgianDateTime();
}
catch (Exception e)
{
return op.Failed("تاریخ به درستی وارد نشده است");
}
#region Validation
#endregion
//ایجاد طرح
var create = new ClassificationScheme(command.IncludingDateGr, command.ExecutionDateGr,
command.DesignerFullName, command.DesignerPhone, command.WorkshopId, command.TypeOfCoefficient);
_classificationSchemeRepository.Create(create);
await _classificationSchemeRepository.SaveChangesAsync();
//ایجاد گروه های طرح
var groups = new List<ClassificationGroup>()
{
new ClassificationGroup("1",command.WorkshopId,create.id),
new ClassificationGroup("2",command.WorkshopId,create.id),
new ClassificationGroup("3",command.WorkshopId,create.id),
new ClassificationGroup("4",command.WorkshopId,create.id),
new ClassificationGroup("5",command.WorkshopId,create.id),
new ClassificationGroup("6",command.WorkshopId,create.id),
new ClassificationGroup("7",command.WorkshopId,create.id),
new ClassificationGroup("8",command.WorkshopId,create.id),
new ClassificationGroup("9",command.WorkshopId,create.id),
new ClassificationGroup("10",command.WorkshopId,create.id),
new ClassificationGroup("11",command.WorkshopId,create.id),
new ClassificationGroup("12",command.WorkshopId,create.id),
new ClassificationGroup("13",command.WorkshopId,create.id),
new ClassificationGroup("14",command.WorkshopId,create.id),
new ClassificationGroup("15",command.WorkshopId,create.id),
new ClassificationGroup("16",command.WorkshopId,create.id),
new ClassificationGroup("17",command.WorkshopId,create.id),
new ClassificationGroup("18",command.WorkshopId,create.id),
new ClassificationGroup("19",command.WorkshopId,create.id),
new ClassificationGroup("20",command.WorkshopId,create.id),
};
await _classificationGroupRepository.CreateGroups(groups);
return op.Succcedded();
}
public Task<EditClassificationScheme> GetClassificationScheme(long id)
{
return _classificationSchemeRepository.GetClassificationScheme(id);
}
public async Task<OperationResult> EditClassificationScheme(EditClassificationScheme command)
{
var op = new OperationResult();
try
{
command.ExecutionDateGr = command.ExecutionDateFa.ToGeorgianDateTime();
command.IncludingDateGr = command.IncludingDateFa.ToGeorgianDateTime();
}
catch (Exception e)
{
return op.Failed("تاریخ به درستی وارد نشده است");
}
#region Validation
#endregion
var scheme = _classificationSchemeRepository.Get(command.Id);
if (scheme == null)
return op.Failed("رکورد مورد نظر وجود ندارد");
scheme.Edit(command.IncludingDateGr,command.ExecutionDateGr,command.DesignerFullName,command.DesignerPhone,command.TypeOfCoefficient);
await _classificationSchemeRepository.SaveChangesAsync();
return op.Succcedded();
}
public async Task<List<ClassificationGroupAndJobModel>> GetGroupAndJobs(long schemeId)
{
return await _classificationGroupRepository.GetGroupAndJobs(schemeId);
}
public Task<OperationResult> CreateGroupJobs(ClassificationGroupAndJobModel command)
{
throw new System.NotImplementedException();
}
public Task<OperationResult> CreateGroupSalaryAndCoefficient(CreateClassificationGroupSalaryAndRialCoefficient command)
{
throw new System.NotImplementedException();
}
}