Beispiel #1
0
        public static async Task Execute
        (
            CreateLoanAgreementInfo model,
            ILoanAgreementAggregateRepository loanAgreementRepo,
            IFinancierAggregateRepository financierRepo,
            IUnitOfWork unitOfWork
        )
        {
            if (await loanAgreementRepo.Exists(model.Id))
            {
                throw new InvalidOperationException($"This loan agreement already exists!");
            }

            string    errMsg    = $"Unable to create loan agreement info, a financier with id {model.FinancierId} could not be found!";
            Financier financier = await financierRepo.GetByIdAsync(model.FinancierId) ?? throw new InvalidOperationException(errMsg);

            LoanAgreement loanAgreement = new LoanAgreement
                                          (
                new EconomicEvent(model.Id, EventType.CashReceiptFromLoanAgreement),
                FinancierId.Create(financier.Id),
                LoanAmount.Create(model.LoanAmount),
                InterestRate.Create(model.InterestRate),
                LoanDate.Create(model.LoanDate),
                MaturityDate.Create(model.MaturityDate),
                PaymentsPerYear.Create(model.PaymentsPerYear),
                model.UserId
                                          );

            await loanAgreementRepo.AddAsync(loanAgreement);

            await unitOfWork.Commit();
        }
Beispiel #2
0
 public LoanAgreementAggregateCommandHandler
 (
     IFinancierAggregateRepository financierRepo,
     ILoanAgreementAggregateRepository loanAgreementRepo,
     IUnitOfWork unitOfWork
 )
 {
     _financierRepo     = financierRepo;
     _loanAgreementRepo = loanAgreementRepo;
     _unitOfWork        = unitOfWork;
 }
        public static async Task Execute
        (
            DeleteLoanAgreementInfo model,
            ILoanAgreementAggregateRepository loanAgreementRepo,
            IUnitOfWork unitOfWork
        )
        {
            string        errMsg        = $"Unable to delete loan agreement info, a loan agreement with LoanId '{model.Id}' could not be found!";
            LoanAgreement loanAgreement = await loanAgreementRepo.GetByIdAsync(model.Id) ?? throw new InvalidOperationException(errMsg);

            loanAgreementRepo.Delete(loanAgreement);
            await unitOfWork.Commit();
        }
Beispiel #4
0
        public static async Task Execute
        (
            EditLoanAgreementInfo model,
            ILoanAgreementAggregateRepository loanAgreementRepo,
            IUnitOfWork unitOfWork
        )
        {
            string        errMsg        = $"Unable to locate loan agreement with LoanId '{model.Id}'!";
            LoanAgreement loanAgreement = await loanAgreementRepo.GetByIdAsync(model.Id) ?? throw new InvalidOperationException(errMsg);

            loanAgreement.UpdateLoanAmount(LoanAmount.Create(model.LoanAmount));
            loanAgreement.UpdateInterestRate(InterestRate.Create(model.InterestRate));
            loanAgreement.UpdateLoanDate(LoanDate.Create(model.LoanDate));
            loanAgreement.UpdateMaturityDate(MaturityDate.Create(model.MaturityDate));
            loanAgreement.UpdatePaymentsPerYear(PaymentsPerYear.Create(model.PaymentsPerYear));
            loanAgreement.UpdateUserId(model.UserId);
            loanAgreement.UpdateLastModifiedDate();

            await unitOfWork.Commit();
        }
Beispiel #5
0
 public LoanAgreementAggregateRepoTests()
 {
     TestDataInitialization.InitializeData(_dbContext);
     _unitOfWork        = new AppUnitOfWork(_dbContext);
     _loanAgreementRepo = new LoanAgreementAggregateRepository(_dbContext);
 }