using CompanyManagment.App.Contracts.EmployeeComputeOptions; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using _0_Framework.Application; using Company.Domain.EmployeeComputeOptionsAgg; using Company.Domain.EmployeeAgg; namespace CompanyManagment.Application; public class EmployeeComputeOptionsApplication : IEmployeeComputeOptionsApplication { private readonly IEmployeeComputeOptionsRepository _employeeComputeOptionsRepository; public EmployeeComputeOptionsApplication(IEmployeeComputeOptionsRepository employeeComputeOptionsRepository) { _employeeComputeOptionsRepository = employeeComputeOptionsRepository; } public OperationResult Create(CreateEmployeeComputeOptions command) { var opration = new OperationResult(); if (command.CreateContract && command.ContractTerm != "1" && command.CutContractEndOfYear == IsActive.None) return opration.Failed("لطفا تعیین کنید که قراداد منتهی به پایان سال یاشد یا نباشد"); if (command.ContractTerm == "1") command.CutContractEndOfYear = IsActive.None; try { if (_employeeComputeOptionsRepository.Exists(x => x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId)) { var query = GetEmployeeOptions(command.WorkshopId, command.EmployeeId); var editOptions = _employeeComputeOptionsRepository.Get(query.Id); editOptions.Edit(command.ComputeOptions, command.BonusesOptions, command.YearsOptions, command.CreateContract, command.SignContract, command.CreateCheckout, command.SignCheckout, command.ContractTerm, command.CutContractEndOfYear); _employeeComputeOptionsRepository.SaveChanges(); return opration.Succcedded(); } else { var createOptions = new EmployeeComputeOptions(command.WorkshopId, command.EmployeeId, command.ComputeOptions, command.BonusesOptions, command.YearsOptions, command.CreateContract, command.SignContract, command.CreateCheckout, command.SignCheckout, command.ContractTerm, command.CutContractEndOfYear); _employeeComputeOptionsRepository.Create(createOptions); _employeeComputeOptionsRepository.SaveChanges(); return opration.Succcedded(); } } catch (Exception a) { return opration.Failed("ثبت با خطا مواجه شد"); } } public EmployeeComputeOptionsViewModel GetEmployeeOptions(long workshopId, long employeeId) { return _employeeComputeOptionsRepository.GetEmployeeOptions(workshopId, employeeId); } public List GetAllByWorkshopId(long workshopId) { return _employeeComputeOptionsRepository.GetAllByWorkshopId(workshopId); } }