using System; using System.Collections.Generic; using System.Threading.Tasks; using _0_Framework.Application; using Company.Domain.InstitutionPlanAgg; using CompanyManagment.App.Contracts.InstitutionPlan; using CompanyManagment.App.Contracts.TemporaryClientRegistration; namespace CompanyManagment.Application; public class InstitutionPlanApplication : IInstitutionPlanApplication { private readonly IPlanPercentageRepository _planPercentageRepository; public InstitutionPlanApplication(IPlanPercentageRepository planPercentageRepository) { _planPercentageRepository = planPercentageRepository; } public OperationResult CreateInstitutionPlanPercentage(CreateInstitutionPlanPercentage command) { var op = new OperationResult(); if (string.IsNullOrWhiteSpace(command.ContractAndCheckoutInPersonPercentStr) || command.ContractAndCheckoutInPersonPercentStr == "0" || string.IsNullOrWhiteSpace(command.ContractAndCheckoutPercentStr) || (command.ContractAndCheckoutPercentStr == "0" || string.IsNullOrWhiteSpace(command.CustomizeCheckoutPercentStr) || command.CustomizeCheckoutPercentStr == "0" || string.IsNullOrWhiteSpace(command.InsuranceInPersonPercentStr) || command.InsuranceInPersonPercentStr == "0" || string.IsNullOrWhiteSpace(command.InsurancePercentStr) || command.InsurancePercentStr == "0" || string.IsNullOrWhiteSpace(command.RollCallPercentStr) || command.RollCallPercentStr == "0")) return op.Failed("هیچ یک از فیلدها نمیتوانند صفر باشند"); int contractAndCheckoutInPersonPercent = 0; int contractAndCheckoutPercent = 0; int customizeCheckoutPercent = 0; int insuranceInPersonPercent = 0; int insurancePercent = 0; int rollCallPercent = 0; try { contractAndCheckoutInPersonPercent = Convert.ToInt32(command.ContractAndCheckoutInPersonPercentStr); contractAndCheckoutPercent = Convert.ToInt32(command.ContractAndCheckoutPercentStr); customizeCheckoutPercent = Convert.ToInt32(command.CustomizeCheckoutPercentStr); insuranceInPersonPercent = Convert.ToInt32(command.InsuranceInPersonPercentStr); insurancePercent = Convert.ToInt32(command.InsurancePercentStr); rollCallPercent = Convert.ToInt32(command.RollCallPercentStr); } catch (Exception e) { return op.Failed("لطفا عدد معتبر وارد کنید"); } var firstPlan = _planPercentageRepository.GetByFirst(); if (firstPlan != null) { var planPercentage = _planPercentageRepository.Get(firstPlan.Id); planPercentage.Edit(contractAndCheckoutPercent, insurancePercent, rollCallPercent, customizeCheckoutPercent, contractAndCheckoutInPersonPercent, insuranceInPersonPercent); _planPercentageRepository.SaveChanges(); } else { var create = new PlanPercentage(contractAndCheckoutPercent, insurancePercent, rollCallPercent, customizeCheckoutPercent, contractAndCheckoutInPersonPercent, insuranceInPersonPercent); _planPercentageRepository.Create(create); _planPercentageRepository.SaveChanges(); } return op.Succcedded(); } public List GetInstitutionPlanList(int pageIndex, int countPeron) { return _planPercentageRepository.GetInstitutionPlanList(pageIndex, countPeron); } public EditInstitutionPlanPercentage GetByFirst() { return _planPercentageRepository.GetByFirst(); } public InstitutionPlanViewModel GetInstitutionPlanForWorkshop(WorkshopTempViewModel command) { return _planPercentageRepository.GetInstitutionPlanForWorkshop(command); } #region ForApi public async Task GetCreateModalData() { return await _planPercentageRepository.GetCreateModalData(); } public async Task CreateInstitutionPlanPercentage(CreateServiceAmountDto command) { var op = new OperationResult(); if (string.IsNullOrWhiteSpace(command.ContractAndCheckoutInPersonPercentStr) || command.ContractAndCheckoutInPersonPercentStr == "0" || string.IsNullOrWhiteSpace(command.ContractAndCheckoutPercentStr) || (command.ContractAndCheckoutPercentStr == "0" || string.IsNullOrWhiteSpace(command.CustomizeCheckoutPercentStr) || command.CustomizeCheckoutPercentStr == "0" || string.IsNullOrWhiteSpace(command.InsuranceInPersonPercentStr) || command.InsuranceInPersonPercentStr == "0" || string.IsNullOrWhiteSpace(command.InsurancePercentStr) || command.InsurancePercentStr == "0" || string.IsNullOrWhiteSpace(command.RollCallPercentStr) || command.RollCallPercentStr == "0")) return op.Failed("هیچ یک از فیلدها نمیتوانند صفر باشند"); int contractAndCheckoutInPersonPercent = 0; int contractAndCheckoutPercent = 0; int customizeCheckoutPercent = 0; int insuranceInPersonPercent = 0; int insurancePercent = 0; int rollCallPercent = 0; try { contractAndCheckoutInPersonPercent = Convert.ToInt32(command.ContractAndCheckoutInPersonPercentStr); contractAndCheckoutPercent = Convert.ToInt32(command.ContractAndCheckoutPercentStr); customizeCheckoutPercent = Convert.ToInt32(command.CustomizeCheckoutPercentStr); insuranceInPersonPercent = Convert.ToInt32(command.InsuranceInPersonPercentStr); insurancePercent = Convert.ToInt32(command.InsurancePercentStr); rollCallPercent = Convert.ToInt32(command.RollCallPercentStr); } catch (Exception e) { return op.Failed("لطفا عدد معتبر وارد کنید"); } var firstPlan =await _planPercentageRepository.GetCreateModalData(); if (firstPlan != null) { var planPercentage = _planPercentageRepository.Get(firstPlan.Id); planPercentage.Edit(contractAndCheckoutPercent, insurancePercent, rollCallPercent, customizeCheckoutPercent, contractAndCheckoutInPersonPercent, insuranceInPersonPercent); _planPercentageRepository.SaveChanges(); } else { var create = new PlanPercentage(contractAndCheckoutPercent, insurancePercent, rollCallPercent, customizeCheckoutPercent, contractAndCheckoutInPersonPercent, insuranceInPersonPercent); await _planPercentageRepository.CreateAsync(create); await _planPercentageRepository.SaveChangesAsync(); } return op.Succcedded(); } public async Task> GetList(InstitutionPlanSearchModel searchModel) { return await _planPercentageRepository.GetList(searchModel); } #endregion }