Files
Backend-Api/CompanyManagment.Application/PaymentToEmployeeApplication.cs
2024-07-05 21:36:15 +03:30

100 lines
4.0 KiB
C#

using Company.Domain.PaymentToEmployeeAgg;
using CompanyManagment.App.Contracts.PaymentToEmployee;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using _0_Framework.Application;
using Company.Domain.WorkingHoursTempAgg;
using CompanyManagment.App.Contracts.WorkingHoursTempItem;
using Company.Domain.EmployeeAgg;
using Company.Domain.PaymentToEmployeeItemAgg;
namespace CompanyManagment.Application;
public class PaymentToEmployeeApplication : IPaymentToEmployeeApplication
{
private readonly IPaymentToEmployeeRepository _paymentToEmployeeRepository;
private readonly IPaymentToEmployeeItemRepository _paymentToEmployeeItemRepository;
public PaymentToEmployeeApplication(IPaymentToEmployeeRepository paymentToEmployeeRepository, IPaymentToEmployeeItemRepository paymentToEmployeeItemRepository)
{
_paymentToEmployeeRepository = paymentToEmployeeRepository;
_paymentToEmployeeItemRepository = paymentToEmployeeItemRepository;
}
public OperationResult Create(CreatePaymentToEmployee command)
{
var opration = new OperationResult();
long paymentId = 0;
var createNew = new PaymentToEmployee(command.EmployeeId, command.WorkshopId, command.Month, command.Year);
var checkExist = _paymentToEmployeeRepository.Exists(x =>
x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.Month == command.Month && x.Year == command.Year);
if (!checkExist)
{
_paymentToEmployeeRepository.Create(createNew);
_paymentToEmployeeRepository.SaveChanges();
paymentId = createNew.id;
}
else
{
paymentId = _paymentToEmployeeRepository.GetByYearAndMonthAndWorkshopAndEmployee(command.Year, command.Month, command.WorkshopId, command.EmployeeId).Id;
}
//_paymentToEmployeeRepository.Create(createNew);
//_paymentToEmployeeRepository.SaveChanges();
//check exist item
//if isExist { return opration.Failed("وجود")
if (paymentId == 0)
{
return opration.Failed("یه مشکلی در پرداخت به وجود آمده است.");
}
var create = new PaymentToEmployeeItem(
command.EmployeeId,
command.WorkshopId,
paymentId,
command.CreatePaymentToEmployeeItem.PaymentFa.MoneyToDouble(),
command.CreatePaymentToEmployeeItem.PayDateFa.ToGeorgianDateTime(),
command.CreatePaymentToEmployeeItem.PaymentMetod,
command.CreatePaymentToEmployeeItem.SourceBankName,
command.CreatePaymentToEmployeeItem.SourceBankAccountNumber,
command.CreatePaymentToEmployeeItem.TypeSourceBankNumber,
command.CreatePaymentToEmployeeItem.DestinationBankName,
command.CreatePaymentToEmployeeItem.DestinationBankAccountNumber,
command.CreatePaymentToEmployeeItem.TypeDestinationBankNumber,
command.CreatePaymentToEmployeeItem.BankCheckNumber,
command.CreatePaymentToEmployeeItem.CashDescription,
command.CreatePaymentToEmployeeItem.PaymentTitle
);
_paymentToEmployeeItemRepository.Create(create);
_paymentToEmployeeItemRepository.SaveChanges();
return opration.Succcedded();
}
public OperationResult Edit(EditPaymentToEmployee command)
{
throw new NotImplementedException();
}
public List<PaymentToEmployeeViewModel> searchClient(PaymentToEmployeeSearchModel searchModel)
{
return _paymentToEmployeeRepository.searchClient(searchModel);
}
public OperationResult RemovePaymentItem(long id)
{
var opration = new OperationResult();
_paymentToEmployeeRepository.RemovePaymentItem(id);
return opration.Succcedded();
}
public List<PaymentToEmployeePrintViewModel> PrintAll(PaymentToEmployeeSearchModel searchModel)
{
return _paymentToEmployeeRepository.PrintAll(searchModel);
}
}