コード例 #1
0
        public MemberReportedLoan UpdateLoan(int userId, MemberReportedLoan updatedLoan)
        {
            if (updatedLoan.Validate().Count > 0)
            {
                throw new System.ComponentModel.DataAnnotations.ValidationException();
            }

            //if the loan is type "UE" (Repayment Navigator) then delte the exisiting one and create a new loan, to make sure CreatedDate is updated.
            if (updatedLoan.LoanType == "UE")
            {
                RemoveLoan(updatedLoan.MemberId, updatedLoan.MemberReportedLoanId);
                return(CreateLoan(updatedLoan.MemberId, updatedLoan));
            }

            var existingLoan = _memberLoanRepository.Get(m => m.MemberReportedLoanId == updatedLoan.MemberReportedLoanId && m.MemberId == userId).FirstOrDefault();

            //set member and member id for the updated loan
            updatedLoan.ModifiedBy = existingLoan.ModifiedBy;
            updatedLoan.CreatedBy  = existingLoan.CreatedBy;

            if (existingLoan != null)
            {
                try
                {
                    if (updatedLoan.MonthlyPaymentAmount == null)
                    {
                        updatedLoan.MonthlyPaymentAmount = _loanCalc.calculateMonthlyPayment(updatedLoan);
                    }
                    updatedLoan.RecordSource = _recordSourceRepository.Get(rs => rs.RecordSourceId == updatedLoan.RecordSourceId).FirstOrDefault();
                    IUnitOfWork unitOfWork = new UnitOfWork <SALTEntities>(_dbContext);
                    _memberLoanRepository.Update(updatedLoan);
                    unitOfWork.Commit();
                }
                catch (Exception ex)
                {
                    _log.Error(ex.Message, ex);
                    throw;
                }
            }
            return(updatedLoan);
        }
コード例 #2
0
        public MemberReportedLoan CreateLoan(int userId, MemberReportedLoan loan)
        {
            if (loan.Validate().Count > 0)
            {
                throw new System.ComponentModel.DataAnnotations.ValidationException();
            }
            IUnitOfWork        unitOfWork = new UnitOfWork <SALTEntities>(_dbContext);
            MemberReportedLoan addedLoan  = InsertLoan(loan);

            try
            {
                unitOfWork.Commit();
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message, ex);
                throw;
            }

            return(addedLoan);
        }