예제 #1
0
        public async Task <IActionResult> ActivateAgreement(int id, [FromBody] ActivateAgreementDto activateAgreementDto)
        {
            var agreementFromRepo = await this._agreementRepo.GetSingle(id);

            if (agreementFromRepo == null)
            {
                return(BadRequest());
            }

            if (await this._customerRepo.GetSingle(activateAgreementDto.CustomerId) == null)
            {
                return(BadRequest());
            }

            agreementFromRepo.Status          = 3;
            agreementFromRepo.IsLoanActivated = true;
            agreementFromRepo.LeftToPay       = agreementFromRepo.LoanAmount;

            await _agreementRepo.Update(agreementFromRepo);

            //Create transaction


            var tr = new Transaction
            {
                AgreementId       = id,
                AmountPaid        = agreementFromRepo.LoanAmount,
                TransactionTypeId = 1
            };

            var result = await _transactionRepo.Create(tr);


            // End

            var agreementDto = _mapper.Map <AgreementDto>(agreementFromRepo);

            return(Ok(agreementDto));
        }
예제 #2
0
        public async Task <IActionResult> ApplyAgreement(int id, [FromBody] ActivateAgreementDto activateAgreementDto)
        {
            var agreementFromRepo = await this._agreementRepo.GetSingle(id);

            if (agreementFromRepo == null)
            {
                return(BadRequest());
            }

            if (await this._customerRepo.GetSingle(activateAgreementDto.CustomerId) == null)
            {
                return(BadRequest());
            }

            agreementFromRepo.Status          = 2;
            agreementFromRepo.IsLoanActivated = false;
            agreementFromRepo.LeftToPay       = agreementFromRepo.LoanAmount;

            await _agreementRepo.Update(agreementFromRepo);

            var agreementDto = _mapper.Map <AgreementDto>(agreementFromRepo);

            return(Ok(agreementDto));
        }