コード例 #1
0
        public void Repay()
        {
            var tx = _connectionProvider.GetTransaction();

            try
            {
                foreach (var id in _view.SelectedLoanIds)
                {
                    var total      = _view.GetTotal(id);
                    var loan       = GetLoan(id);
                    var repaidLoan = loan.Copy();
                    DistributeTotal(repaidLoan, total);

                    var repaymentEvent = GetRepaymentEvent(loan, repaidLoan);
                    repaymentEvent = _loanRepository.SaveRepaymentEvent(repaymentEvent, tx);
                    if (_eventInterceptor != null)
                    {
                        _eventInterceptor.CallInterceptor(new Dictionary <string, object>
                        {
                            { "Loan", loan },
                            { "RepaymentEvent", repaymentEvent },
                            { "IDbTransaction", tx }
                        });
                    }
                    _loanRepository.ArchiveSchedule(loan.Id, repaymentEvent.Id, loan.Schedule, repaidLoan.Schedule, tx);

                    var closed = repaidLoan.Schedule.Last().Repaid;
                    if (closed)
                    {
                        var closeEvent = GetCloseEvent(repaidLoan);
                        _loanRepository.SaveCloseEvent(closeEvent, tx);
                        _loanRepository.SetLoanStatusToClosed(loan.Id, tx);
                        _loanRepository.UpdateBorrowerStatus(loan.Id, tx);
                    }
                }
                _villageBankRepository.SyncVillageBankStatus(_villageBankId, tx);
                tx.Commit();

                _view.Stop();
                _applicationController.Publish(new VillageBankRepayMessage(this, _villageBankId));
            }
            catch (Exception error)
            {
                tx.Rollback();
                MessageBox.Show(error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #2
0
        public void Repay()
        {
            var tx = _connectionProvider.GetTransaction();

            try
            {
                foreach (var id in _view.SelectedLoanIds)
                {
                    var total = _view.GetTotal(id);

                    var loan       = GetLoan(id);
                    var repaidLoan = loan.Copy();
                    DistributeTotal(repaidLoan, total);

                    var repaymentEvent = GetRepaymentEvent(loan, repaidLoan);
                    repaymentEvent.Comment       = _view.GetComment(id);
                    repaymentEvent.ReceiptNumber = _view.GetReceiptNumber(id);

                    repaymentEvent = _loanRepository.SaveRepaymentEvent(repaymentEvent, tx);
                    var interceptors = _applicationController.GetAllInstances <IEventInterceptor>();
                    foreach (var interceptor in interceptors)
                    {
                        var e = new CoreDomain.Events.RepaymentEvent
                        {
                            Id              = repaymentEvent.Id,
                            Code            = repaymentEvent.Code,
                            Principal       = repaymentEvent.Principal,
                            Interests       = repaymentEvent.Interest,
                            Penalties       = 0,
                            Comment         = repaymentEvent.Comment,
                            Doc1            = repaymentEvent.ReceiptNumber,
                            PaymentMethodId = repaymentEvent.PaymentMethodId,
                            PaymentMethod   = _view.SelectedPaymentMethod
                        };
                        interceptor.CallInterceptor(new Dictionary <string, object>
                        {
                            { "LoanId", loan.Id },
                            { "ClientId", loan.ClientId },
                            { "BranchId", loan.BranchId },
                            { "ProductId", loan.ProductId },
                            { "ProductCode", loan.ProductCode },
                            { "Event", e },
                            { "SqlTransaction", tx }
                        });
                    }
                    _loanRepository.ArchiveSchedule(loan.Id, repaymentEvent.Id, loan.Schedule, repaidLoan.Schedule, tx);

                    var closed = repaidLoan.Schedule.Last().Repaid;
                    if (closed)
                    {
                        var closeEvent = GetCloseEvent(repaidLoan);
                        _loanRepository.SaveCloseEvent(closeEvent, tx);
                        _loanRepository.SetLoanStatusToClosed(loan.Id, tx);
                        _loanRepository.UpdateBorrowerStatus(loan.Id, tx);
                    }
                }
                _villageBankRepository.SyncVillageBankStatus(_villageBankId, tx);
                tx.Commit();

                _view.Stop();
                _applicationController.Publish(new VillageBankRepayMessage(this, _villageBankId));
            }
            catch (Exception error)
            {
                tx.Rollback();
                MessageBox.Show(error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }