using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using _0_Framework.Application; using Company.Domain.AdminMonthlyOverviewAgg; using CompanyManagment.App.Contracts.AdminMonthlyOverview; namespace CompanyManagment.Application; public class AdminMonthlyOverviewApplication:IAdminMonthlyOverviewApplication { private readonly IAdminMonthlyOverviewRepository _adminMonthlyOverviewRepository; public AdminMonthlyOverviewApplication(IAdminMonthlyOverviewRepository adminMonthlyOverviewRepository) { _adminMonthlyOverviewRepository = adminMonthlyOverviewRepository; } public async Task> GetWorkshopListByStatus(AdminMonthlyOverviewSearchModel searchModel) { return await _adminMonthlyOverviewRepository.GetWorkshopStatus(searchModel); } public async Task GetCounter(int year, int month, long accountId) { return await _adminMonthlyOverviewRepository.GetCounter(year, month, accountId); } public async Task Next(long id) { var operation= new OperationResult(); var monthlyOverview = _adminMonthlyOverviewRepository.Get(id); if (monthlyOverview == null) { return operation.Failed("آیتم موردنظر یافت نشد"); } if (monthlyOverview.Status== AdminMonthlyOverviewStatus.CreateDocuments) { return operation.Failed("شما نمیتوانید تا زمانی که قرارداد و تصفیه را تنظیم نکردید به مرحله بعد بروید"); } var maxValue = Enum.GetValues(typeof(AdminMonthlyOverviewStatus)) .Cast() .Max(); if (monthlyOverview.Status >= maxValue) { return operation.Failed("مرحله بعدی انتخاب شده نامعتبر است"); } monthlyOverview.Next(); await _adminMonthlyOverviewRepository.SaveChangesAsync(); return operation.Succcedded(); } public async Task Back(long id) { var operation = new OperationResult(); var monthlyOverview = _adminMonthlyOverviewRepository.Get(id); if (monthlyOverview == null) { return operation.Failed("آیتم موردنظر یافت نشد"); } if (monthlyOverview.Status == AdminMonthlyOverviewStatus.CreateDocuments+1) { return operation.Failed("شما امکان برگشت به مرحله قبل را ندارید"); } var minValue = Enum.GetValues(typeof(AdminMonthlyOverviewStatus)) .Cast() .Min(); if (monthlyOverview.Status <= minValue) { return operation.Failed("مرحله قبلی انتخاب شده نامعتبر است"); } monthlyOverview.Back(); await _adminMonthlyOverviewRepository.SaveChangesAsync(); return operation.Succcedded(); } }