108 lines
4.3 KiB
C#
108 lines
4.3 KiB
C#
using System;
|
|
using _0_Framework.Application;
|
|
using Company.Domain.FinancialTransactionAgg;
|
|
using CompanyManagment.App.Contracts.FinancilTransaction;
|
|
|
|
namespace CompanyManagment.Application;
|
|
|
|
public class FinancialTransactionApplication : IFinancialTransactionApplication
|
|
{
|
|
private readonly IFinancialTransactionRepository _financialTransactionRepository;
|
|
|
|
public FinancialTransactionApplication(IFinancialTransactionRepository financialTransactionRepository)
|
|
{
|
|
_financialTransactionRepository = financialTransactionRepository;
|
|
}
|
|
|
|
public OperationResult Create(CreateFinancialTransaction command)
|
|
{
|
|
var op = new OperationResult();
|
|
var now = DateTime.Now;
|
|
var check = _financialTransactionRepository.Exists(x => x.CreationDate.Date == now.Date && x.CreationDate.Hour == now.Hour && x.CreationDate.Minute == now.Minute && x.CreationDate.Second == now.Second &&
|
|
x.FinancialStatementId == command.FinancialStatementId
|
|
&& x.Creditor == command.Creditor &&
|
|
x.Deptor == command.Deptor &&
|
|
x.TypeOfTransaction == command.TypeOfTransaction &&
|
|
x.DescriptionOption == x.DescriptionOption &&
|
|
x.Description == command.Description);
|
|
if (!check)
|
|
{
|
|
var transaction = new FinancialTransaction(command.FinancialStatementId, command.TdateGr, command.TdateFa,
|
|
command.Description,
|
|
command.TypeOfTransaction, command.DescriptionOption, command.Deptor, command.Creditor, 0);
|
|
_financialTransactionRepository.Create(transaction);
|
|
_financialTransactionRepository.SaveChanges();
|
|
return op.Succcedded();
|
|
}
|
|
else
|
|
{
|
|
return op.Failed("تکراری است");
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
public OperationResult Edit(EditFinancialTransaction command)
|
|
{
|
|
var op = new OperationResult();
|
|
var transactionEdit = _financialTransactionRepository.Get(command.Id);
|
|
if (transactionEdit == null)
|
|
return op.Failed("رکورد مورد نظر وجود ندارد");
|
|
|
|
double creditor = 0;
|
|
double debtor = 0;
|
|
if (command.TypeOfTransaction == "debt" && string.IsNullOrWhiteSpace(command.DeptorString))
|
|
return op.Failed("فیلد بدهکار خالیاست");
|
|
if (command.TypeOfTransaction == "credit" && string.IsNullOrWhiteSpace(command.CreditorString))
|
|
return op.Failed("فیلد بستانکار خالی است");
|
|
if (string.IsNullOrWhiteSpace(command.TdateFa))
|
|
return op.Failed("فیلد تاریخ خالی است");
|
|
|
|
if (command.TypeOfTransaction == "credit")
|
|
{
|
|
debtor = 0;
|
|
creditor = command.CreditorString.MoneyToDouble();
|
|
|
|
}
|
|
else if (command.TypeOfTransaction == "debt")
|
|
{
|
|
creditor = 0;
|
|
debtor = command.DeptorString.MoneyToDouble();
|
|
|
|
}
|
|
|
|
var tDateGr = command.TdateFa.ToGeorgianDateTime();
|
|
transactionEdit.Edit(tDateGr, command.TdateFa,command.Description,command.TypeOfTransaction, command.DescriptionOption, debtor, creditor, 0,false);
|
|
_financialTransactionRepository.SaveChanges();
|
|
return op.Succcedded();
|
|
}
|
|
|
|
public EditFinancialTransaction GetDetails(long id)
|
|
{
|
|
return _financialTransactionRepository.GetDetails(id);
|
|
}
|
|
|
|
public OperationResult RemoveFinancialTransaction(long id)
|
|
{
|
|
var op = new OperationResult();
|
|
|
|
_financialTransactionRepository.RemoveFinancialTransaction(id);
|
|
return op.Succcedded();
|
|
}
|
|
|
|
public OperationResult RemoveBlocked(long id)
|
|
{
|
|
var opration = new OperationResult();
|
|
var bloced = _financialTransactionRepository.Get(id);
|
|
if (bloced == null)
|
|
return opration.Failed("رکورد مورد نظر یافت نشد");
|
|
|
|
bloced.RemoveBloked();
|
|
|
|
|
|
_financialTransactionRepository.SaveChanges();
|
|
opration.IsSuccedded = true;
|
|
return opration.Succcedded();
|
|
}
|
|
} |