Files
Backend-Api/CompanyManagment.Application/AdminMonthlyOverviewApplication.cs
2025-05-25 21:19:31 +03:30

86 lines
3.0 KiB
C#

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<List<AdminMonthlyOverviewListViewModel>> GetWorkshopListByStatus(AdminMonthlyOverviewSearchModel searchModel)
{
return await _adminMonthlyOverviewRepository.GetWorkshopStatus(searchModel);
}
public async Task<AdminMonthlyOverViewCounterVm> GetCounter(int year, int month, long accountId)
{
return await _adminMonthlyOverviewRepository.GetCounter(year, month, accountId);
}
public async Task<OperationResult> 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<AdminMonthlyOverviewStatus>()
.Max();
if (monthlyOverview.Status >= maxValue)
{
return operation.Failed("مرحله بعدی انتخاب شده نامعتبر است");
}
monthlyOverview.Next();
await _adminMonthlyOverviewRepository.SaveChangesAsync();
return operation.Succcedded();
}
public async Task<OperationResult> 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<AdminMonthlyOverviewStatus>()
.Min();
if (monthlyOverview.Status <= minValue)
{
return operation.Failed("مرحله قبلی انتخاب شده نامعتبر است");
}
monthlyOverview.Back();
await _adminMonthlyOverviewRepository.SaveChangesAsync();
return operation.Succcedded();
}
}