using CompanyManagment.App.Contracts.RollCallService; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using _0_Framework.Application; using Company.Domain.RollCallServiceAgg; using AccountManagement.Domain.AccountAgg; using Microsoft.Identity.Client; namespace CompanyManagment.Application; public class RollCallServiceApplication : IRollCallServiceApplication { private readonly IRollCallServiceRepository _rollCallServiceRepository; public RollCallServiceApplication(IRollCallServiceRepository rollCallServiceRepository) { _rollCallServiceRepository = rollCallServiceRepository; } public OperationResult Create(CreateRollCallService command) { var opration = new OperationResult(); if (_rollCallServiceRepository.Exists(x => x.WorkshopId == command.WorkshopId && x.AccountId == command.AccountId && x.IsActiveString == "true")) return opration.Failed("برای این کارگاه قبلا سرویس فعال شده است"); //var start = DateTime.Now //var create = new RollCallService(command.ServiceType, start,) var create = new RollCallService( command.ServiceType, command.StartService = DateTime.Now, command.EndService, command.WorkshopId, command.AccountId, command.MaxPersonValid, command.Amount, command.Duration ); _rollCallServiceRepository.Create(create); //افزودن سرویس فیش حقوقی غیر رسمی وی آی پی از سمت ادمین if(command.HasCustomizeCheckoutService == "true") create.AddOrRemoveCoustomizeCheckoutServiceVip("true", create.EndService,create.StartService); _rollCallServiceRepository.SaveChanges(); return opration.Succcedded(); } public OperationResult Upgrade(EditRollCallService command) { throw new NotImplementedException(); } public OperationResult StopVipService(long serviceId) { var op = new OperationResult(); var vipService = _rollCallServiceRepository.Get(serviceId); if (vipService == null) return op.Failed("خطایی رخ داده است"); bool hasCusromizecheckoutServiceBefor = vipService.HasCustomizeCheckoutService == "true"; vipService.StopVipService(hasCusromizecheckoutServiceBefor); _rollCallServiceRepository.SaveChanges(); return op.Succcedded(); } public OperationResult AddCustomizeCheckoutServiceVip(long serviceId) { var op = new OperationResult(); var vipService = _rollCallServiceRepository.Get(serviceId); if (vipService == null) return op.Failed("خطایی رخ داده است"); vipService.AddOrRemoveCoustomizeCheckoutServiceVip("true",vipService.EndService,DateTime.Now); _rollCallServiceRepository.SaveChanges(); return op.Succcedded(); } public EditRollCallService GetDetails(long id) { return _rollCallServiceRepository.GetDetails(id); } public RollCallServiceViewModel GetActiveServiceByWorkshopId(long workshopId) { return _rollCallServiceRepository.GetActiveServiceByWorkshopId(workshopId); } public List GetAllServiceByWorkshopId(long workshopId) { return _rollCallServiceRepository.GetAllServiceByWorkshopId(workshopId); } public List GetActiveServiceByAccountId(long accountId) { return _rollCallServiceRepository.GetActiveServiceByAccountId(accountId); } public List GetAllServiceByAccountId(long accountId) { return _rollCallServiceRepository.GetAllServiceByAccountId(accountId); } public bool IsExistActiveServiceByWorkshopId(long workshopId) { return _rollCallServiceRepository.IsExistActiveServiceByWorkshopId(workshopId); } }