コード例 #1
0
        }         // AppendOverridingResults

        public virtual void Save(
            AConnection oDB,
            ATrail oTrail,
            TrailPrimaryStatus primaryStatus   = TrailPrimaryStatus.Primary,
            TrailPrimaryStatus secondaryStatus = TrailPrimaryStatus.Verification
            )
        {
            ConnectionWrapper cw = null;

            try {
                cw = oDB.GetPersistent();
                cw.BeginTransaction();

                this.m_oLog.Debug("Transaction has been started, saving primary trail...");

                new SaveDecisionTrail(
                    this,
                    UniqueID,
                    (int)primaryStatus,
                    CashRequestID,
                    NLCashRequestID,
                    Tag,
                    oDB,
                    this.m_oLog
                    ).ExecuteNonQuery(cw);

                this.m_oLog.Debug("Saving primary trail done (pending transaction commit).");

                if (oTrail != null)
                {
                    this.m_oLog.Debug("Saving secondary trail...");

                    new SaveDecisionTrail(
                        oTrail,
                        UniqueID,
                        (int)secondaryStatus,
                        CashRequestID,
                        NLCashRequestID,
                        Tag,
                        oDB,
                        this.m_oLog
                        ).ExecuteNonQuery(cw);

                    this.m_oLog.Debug("Saving secondary trail done (pending transaction commit).");
                }                 // if

                cw.Commit();
                this.m_oLog.Debug("Decision trail has been saved, connection is closed.");
            } catch (Exception e) {
                if (cw != null)
                {
                    cw.Rollback();
                }

                this.m_oLog.Alert(e, "Failed to save decision trail.");
            }     // try
        }         // Save
コード例 #2
0
        }         // HasValidParameters

        public void Execute()
        {
            ConnectionWrapper cw = null;

            try {
                cw = DB.GetPersistent();

                cw.BeginTransaction();

                ExecuteNonQuery(cw);

                cw.Commit();
            } catch (Exception e) {
                Token = Guid.Empty;

                if (cw != null)
                {
                    cw.Rollback();
                }

                Log.Alert(e, "Failed to initialize password change token for user {0}.", UserID);
            }     // try
        }         // Execute
コード例 #3
0
        }         // Parse

        private ExperianLtd Save(ExperianLtd oMainTable)
        {
            if (oMainTable == null)
            {
                return(null);
            }

            Log.Info("Saving Experian company data into DB...");

            ConnectionWrapper oPersistent = DB.GetPersistent();

            oPersistent.BeginTransaction();

            if (!oMainTable.Save(DB, oPersistent))
            {
                oPersistent.Rollback();
                Log.Warn("Saving Experian company data into DB failed.");
                return(null);
            }             // if

            oPersistent.Commit();
            Log.Info("Saving Experian company data into DB complete.");
            return(oMainTable);
        }         // Save
コード例 #4
0
		/// <exception cref="NL_ExceptionInputDataInvalid">Condition. </exception>
		public override void Execute() {

			if (!CurrentValues.Instance.NewLoanRun) {
				NL_AddLog(LogType.Info, "NL disabled by configuration", null, null, null, null);
				return;
			}

			// invalid input
			if (!string.IsNullOrEmpty(Error)) {
				throw new NL_ExceptionInputDataInvalid(Error);
			}

			NL_AddLog(LogType.Info, "Started", this.strategyArgs, null, Error, null);

			// load loan
			NL_Loans loan = LoanDAL.GetLoan(Payment.LoanID);

			if (loan.LoanStatusID == (int)NLLoanStatuses.Pending) {
				// loan pending - can't to add payment
				Error = string.Format("Loan {0} in status 'Pending' yet, payment registering not allowed.", loan.LoanID);
				Log.Debug(Error);
				NL_AddLog(LogType.Info, "End", this.strategyArgs, null, Error, null);
				return;
			}

			if ((loan.LoanStatusID == (int)NLLoanStatuses.PaidOff || loan.LoanStatusID == (int)NLLoanStatuses.WriteOff) && loan.DateClosed!=null) {
				// loan closed - can't to add payment
				Error = string.Format("Loan {0} in status {1} since {2:d}, payment registering not allowed.", loan.LoanID, loan.LoanStatusID, loan.DateClosed);
				Log.Debug(Error);
				NL_AddLog(LogType.Info, "End", this.strategyArgs, null, Error, null);
				return;
			}
	
			ConnectionWrapper pconn = DB.GetPersistent();

			try {

				pconn.BeginTransaction();
	
				//  RESET PAID PRINCIPAL, INTEREST (SCHEDULE), FEES PAID on retroactive payment - in SP NL_ResetPaymentsPaidAmounts, called from NL_PaymentsSave.
				PaymentID = DB.ExecuteScalar<long>("NL_PaymentsSave", CommandSpecies.StoredProcedure, DB.CreateTableParameter<NL_Payments>("Tbl", Payment));
				Payment.PaymentID = PaymentID;

				if (Payment.PaypointTransactions.Count > 0) {

					NL_PaypointTransactions ppTransaction = Payment.PaypointTransactions.FirstOrDefault();

					if (ppTransaction == null) {
						Log.Info("Paypoint transaction not found. Payment \n{0}{1}", AStringable.PrintHeadersLine(typeof(NL_Payments)), Payment.ToStringAsTable());
						NL_AddLog(LogType.Info, "Paypoint transaction not found", this.strategyArgs, null, Error, null);
					} else {
						ppTransaction.PaymentID = Payment.PaymentID;
						ppTransaction.PaypointTransactionID = DB.ExecuteScalar<long>("NL_PaypointTransactionsSave", CommandSpecies.StoredProcedure, DB.CreateTableParameter<NL_PaypointTransactions>("Tbl", ppTransaction));
					}
				}

				pconn.Commit();

				NL_AddLog(LogType.Info, "End", this.strategyArgs, Payment, Error, null);

				// ReSharper disable once CatchAllClause
			} catch (Exception ex) {

				pconn.Rollback();

				Error = ex.Message;
				Log.Error("Failed to add new payment: {0}", Error);
				NL_AddLog(LogType.Error, "Strategy Faild - Rollback", Payment, Error, ex.ToString(), ex.StackTrace);

				return;
			}

			// recalculate state by calculator + save new state to DB
			UpdateLoanDBState reloadLoanDBState = new UpdateLoanDBState(CustomerID, Payment.LoanID, UserID);
			try {
				reloadLoanDBState.Execute();

				// ReSharper disable once CatchAllClause
			} catch (Exception ex) {
				Error = ex.Message;
				Log.Error("Failed on UpdateLoanDBState {0}", Error);
				NL_AddLog(LogType.Error, "Failed on UpdateLoanDBState", Payment, reloadLoanDBState.Error + "\n" + Error, ex.ToString(), ex.StackTrace);
			}

		}
コード例 #5
0
ファイル: InferenceSaver.cs プロジェクト: vijayamazon/ezbob
        }         // constructor

        public InferenceSaver Execute()
        {
            if (this.requestID <= 0)
            {
                throw new InferenceSaverWrongRequestIDAlert(this.requestID, Log);
            }

            if (this.response == null)
            {
                throw new InferenceSaverNoDataAlert(this.requestID, Log);
            }

            if (Executed)
            {
                Log.Alert(
                    "Inference saver({0}, '{1}') has already been executed.",
                    this.requestID,
                    this.response.ToShortString()
                    );
                return(this);
            }             // if

            Executed = true;

            Log.Debug(
                "Executing inference saver({0}, '{1}')...",
                this.requestID,
                this.response.ToShortString()
                );

            ConnectionWrapper con = DB.GetPersistent();

            con.BeginTransaction();

            try {
                new SaveRawResponse(this.requestID, this.response, DB, Log).ExecuteNonQuery(con);

                ResponseID = new SaveResponse(
                    this.requestID,
                    this.response,
                    this.bucketRepo,
                    this.timeoutSourceRepo,
                    DB,
                    Log
                    ).Execute(con);

                if (this.response.Parsed.HasInference())
                {
                    var map = new SortedDictionary <ModelNames, long>();

                    var saveMo = new SaveModelOutput(ResponseID, this.response, DB, Log);

                    if (saveMo.HasValidParameters())
                    {
                        saveMo.ForEachRowSafe(con, sr => {
                            long id         = sr["ModelOutputID"];
                            ModelNames name = (ModelNames)(int)(long)sr["ModelID"];

                            map[name] = id;
                        });

                        var saveEf = new SaveEncodingFailure(map, this.response, DB, Log);
                        if (saveEf.HasValidParameters())                         // invalid if e.g. no failures
                        {
                            saveEf.ExecuteNonQuery(con);
                        }

                        var saveMi = new SaveMissingColumn(map, this.response, DB, Log);
                        if (saveMi.HasValidParameters())                         // invalid if e.g. no missing columns
                        {
                            saveMi.ExecuteNonQuery(con);
                        }

                        var saveOr = new SaveOutputRatio(map, this.response, DB, Log);
                        if (saveOr.HasValidParameters())                         // invalid if e.g. no output ratio
                        {
                            saveOr.ExecuteNonQuery(con);
                        }

                        var saveW = new SaveWarning(map, this.response, DB, Log);
                        if (saveW.HasValidParameters())                         // invalid if e.g. no output ratio
                        {
                            saveW.ExecuteNonQuery(con);
                        }
                    }             // if
                }                 // if

                var saveEtl = new SaveEtlData(ResponseID, this.response, this.etlCodeRepo, DB, Log);
                if (saveEtl.HasValidParameters())                 // invalid if e.g. no ETL data
                {
                    saveEtl.Execute(con);
                }

                new SaveCustomerHistory(ResponseID, DB, Log).ExecuteNonQuery(con);

                con.Commit();
            } catch (Exception e) {
                con.Rollback();

                Log.Warn(
                    "Executing inference saver({0}, '{1}') failed because of exception: '{2}'.",
                    this.requestID,
                    this.response.ToShortString(),
                    e.Message
                    );

                throw;
            }             // try

            Log.Debug(
                "Executing inference saver({0}, '{1}') complete, response ID is {2}.",
                this.requestID,
                this.response.ToShortString(),
                ResponseID
                );

            return(this);
        }         // Execute
コード例 #6
0
ファイル: AddLoan.cs プロジェクト: vijayamazon/ezbob
		/**
			- loan
			- fees
			- history
			- schedules
			- broker comissions ? - update NLLoanID
			- fund transfer
			- pacnet transaction
			- agreements
			- loan options row
			*/
		public override void Execute() {

			if (!CurrentValues.Instance.NewLoanRun) {
				NL_AddLog(LogType.Info, "NL disabled by configuration", null, null, null, null);
				return;
			}

			NL_AddLog(LogType.Info, "Strategy Start", this.strategyArgs, Error, null, null);

			try {
				if (model.CustomerID == 0) {
					Error = NL_ExceptionCustomerNotFound.DefaultMessage;
					NL_AddLog(LogType.Error, "Strategy failed", this.strategyArgs, null, Error, null);
					return;
				}

				if (model.Loan == null) {
					Error = NL_ExceptionRequiredDataNotFound.Loan;
					NL_AddLog(LogType.Error, "Strategy failed", this.strategyArgs, null, Error, null);
					return;
				}

				if (model.Loan.OldLoanID == null) {
					Error = NL_ExceptionRequiredDataNotFound.OldLoan;
					NL_AddLog(LogType.Error, "Strategy failed", this.strategyArgs, null, Error, null);
					return;
				}

				var history = model.Loan.LastHistory();

				if (history == null) {
					Error = NL_ExceptionRequiredDataNotFound.LastHistory;
					NL_AddLog(LogType.Error, "Strategy failed", this.strategyArgs, null, Error, null);
					return;
				}

				if (history.Agreements == null || history.Agreements.Count == 0) {
					Error = string.Format("Expected input data not found (NL_Model initialized by: NLAgreementItem list). Customer {0}", model.CustomerID);
					NL_AddLog(LogType.Error, "Strategy failed", this.strategyArgs, null, Error, null);
					return;
				}

				if (string.IsNullOrEmpty(history.AgreementModel)) {
					Error = string.Format("Expected input data not found (NL_Model initialized by: AgreementModel in JSON). Customer {0}", model.CustomerID);
					NL_AddLog(LogType.Error, "Strategy failed", this.strategyArgs, null, Error, null);
					return;
				}

				BuildLoanFromOffer dataForLoan = new BuildLoanFromOffer(model);
				try {
					dataForLoan.Execute();
					// ReSharper disable once CatchAllClause
				} catch (Exception ex) {
					Log.Alert(ex.Message);
				}

				if (!string.IsNullOrEmpty(dataForLoan.Error)) {
					Error = dataForLoan.Error;
					NL_AddLog(LogType.DataExsistense, "Strategy failed - Failed to generate Schedule/fees", this.strategyArgs, null, Error, null);
					return;
				}

				model = dataForLoan.Result;

				// prevent to create the same loan (by refnum)
				if (!string.IsNullOrEmpty(model.Loan.Refnum) && !string.IsNullOrEmpty(dataForLoan.DataForLoan.ExistsRefnums) && dataForLoan.DataForLoan.ExistsRefnums.Contains(model.Loan.Refnum)) {
					Error = NL_ExceptionLoanExists.DefaultMessage;
					NL_AddLog(LogType.Info, "Strategy End", this.strategyArgs, null, Error, null);
					return;
				}

				// setup/distributed fees

				// for now: only one-time or "spreaded" setup fees supported
				// add full fees 2.0 support later

				var offerFees = model.Offer.OfferFees;

				// don't create LoanFees if OfferFees Percent == 0 or AbsoluteAmount == 0
				var setupFee = offerFees.FirstOrDefault(f => f.LoanFeeTypeID == (int)NLFeeTypes.SetupFee && (f.Percent > 0 || f.AbsoluteAmount > 0));
				var servicingFee = offerFees.FirstOrDefault(f => f.LoanFeeTypeID == (int)NLFeeTypes.ServicingFee && (f.Percent > 0 || f.AbsoluteAmount > 0)); // equal to "setup spreaded"
				decimal? brokerFeePercent = model.Offer.BrokerSetupFeePercent;
			 
				var feeCalculator = new SetupFeeCalculator(setupFee!=null ?setupFee.Percent: servicingFee.Percent, brokerFeePercent);
				SetupFeeCalculator.AbsoluteFeeAmount ff = feeCalculator.Calculate(history.Amount);
				decimal setupFeeAmount = ff.Total;
				model.BrokerComissions = ff.Broker;

				// send ot Calculator to distribute and attach to schedule planned dates
				history.DistributedFees = servicingFee == null ? 0: setupFeeAmount;
				
				ALoanCalculator nlCalculator = new LegacyLoanCalculator(model);
				// 2. Init Schedule and Fees
				try {
					// model should contain Schedule and Fees after this invocation
					nlCalculator.CreateSchedule(); // create primary dates/p/r/f distribution of schedules (P/n) and setup/servicing fees. 7 September - fully completed schedule + fee + amounts due, without payments.
				} catch (NoInitialDataException noDataException) {
					Error = noDataException.Message;
				} catch (InvalidInitialAmountException amountException) {
					Error = amountException.Message;
				} catch (InvalidInitialInterestRateException interestRateException) {
					Error = interestRateException.Message;
				} catch (InvalidInitialRepaymentCountException paymentsException) {
					Error = paymentsException.Message;
					// ReSharper disable once CatchAllClause
				} catch (Exception ex) {
					Error = string.Format("Failed to get calculator instance/Schedule. customer {0}, err: {1}", model.CustomerID, ex.Message);
					NL_AddLog(LogType.Error, "Strategy failed", this.strategyArgs, null, Error, ex.StackTrace);
					return;
				}

				//// prevent creation of same loan
				//if (!string.IsNullOrEmpty(Error)) {
				//	Log.Info("Failed to calculate Schedule. customer {0}, err: {1}", model.CustomerID, Error);
				//	NL_AddLog(LogType.Error, "Strategy " + string.Format("Failed to calculate Schedule. customer {0}, err: {1}", model.CustomerID, Error), this.strategyArgs, null, Error, null);
				//	return;
				//}

				history.OutstandingInterest = nlCalculator.Interest;

				List<NL_LoanSchedules> nlSchedule = new List<NL_LoanSchedules>();
				List<NL_LoanFees> nlFees = new List<NL_LoanFees>();
				List<NL_LoanAgreements> nlAgreements = new List<NL_LoanAgreements>();

				// get updated history filled with Schedule
				history = model.Loan.LastHistory();

				// copy to local schedules list
				history.Schedule.ForEach(s => nlSchedule.Add(s));

				if (nlSchedule.Count == 0) {
					Error += "Failed to generate Schedule/fees";
					NL_AddLog(LogType.Info, "Strategy failed", this.strategyArgs, null, Error, null);
					return;
				}

				// 3. complete NL_Loans object data
				model.Loan = dataForLoan.Result.Loan;
				model.Loan.CreationTime = nowTime;
				model.Loan.LoanStatusID = (int)NLLoanStatuses.Live;
				model.Loan.Position += 1;
				
				ConnectionWrapper pconn = DB.GetPersistent();

				try {

					pconn.BeginTransaction();

					// 4. save loan
					LoanID = DB.ExecuteScalar<long>(pconn, "NL_LoansSave", CommandSpecies.StoredProcedure, DB.CreateTableParameter("Tbl", model.Loan));
					model.Loan.LoanID = LoanID;

					//Log.Debug("NL_LoansSave: LoanID: {0}", this.LoanID);

					// 5. fees
					// copy to local fees list
					model.Loan.Fees.ForEach(f => nlFees.Add(f));

					foreach (NL_LoanFees f in nlFees) {
						f.CreatedTime = nowTime; // from calc-r
						f.AssignedByUserID = 1; //  from calc-r
						f.LoanID = LoanID;
					}

					// setup as fee
					if (setupFee != null) {
						Log.Debug("setupFeeAmount: {0}", setupFeeAmount);
						nlFees.Add(
							new NL_LoanFees() {
								LoanID = LoanID,
								Amount = setupFeeAmount,
								AssignTime = history.EventTime,
								Notes = "setup fee one-part",
								LoanFeeTypeID = (int)NLFeeTypes.SetupFee,
								CreatedTime = nowTime,
								AssignedByUserID = 1
							});
					}

					nlFees.ForEach(f => Log.Debug("Adding fees: {0}", f));

					// insert fees
					DB.ExecuteNonQuery(pconn, "NL_LoanFeesSave", CommandSpecies.StoredProcedure, DB.CreateTableParameter<NL_LoanFees>("Tbl", nlFees));

					model.Loan.Fees.Clear();
					model.Loan.Fees.AddRange(nlFees);

					// 7. history
					history.LoanID = LoanID;
					history.Description = "adding loan. oldID: " + model.Loan.OldLoanID;

					//Log.Debug("Adding history: {0}", history);

					history.LoanHistoryID = DB.ExecuteScalar<long>(pconn, "NL_LoanHistorySave", CommandSpecies.StoredProcedure, DB.CreateTableParameter("Tbl", history));

					//Log.Debug("NL_LoanHistorySave: LoanID: {0}, LoanHistoryID: {1}", model.Loan.LoanID, history.LoanHistoryID);

					// 8. loan agreements
					history.Agreements.ForEach(a => nlAgreements.Add(a));
					nlAgreements.ForEach(a => a.LoanHistoryID = history.LoanHistoryID);

					//nlAgreements.ForEach(a => Log.Debug("Adding agreement: {0}", a));

					DB.ExecuteNonQuery(pconn, "NL_LoanAgreementsSave", CommandSpecies.StoredProcedure, DB.CreateTableParameter<NL_LoanAgreements>("Tbl", nlAgreements));

					// 9. schedules 
					nlSchedule.ForEach(s => s.LoanHistoryID = history.LoanHistoryID);

					//nlSchedule.ForEach(s => Log.Debug("Adding schedule: {0}", s));

					DB.ExecuteNonQuery(pconn, "NL_LoanSchedulesSave", CommandSpecies.StoredProcedure, DB.CreateTableParameter<NL_LoanSchedules>("Tbl", nlSchedule));

					// 10. Fund Transfer 
					if (model.FundTransfer != null) {
						model.FundTransfer.LoanID = LoanID;
						model.FundTransfer.FundTransferID = DB.ExecuteScalar<long>(pconn, "NL_FundTransfersSave", CommandSpecies.StoredProcedure, DB.CreateTableParameter("Tbl", model.FundTransfer));
						//Log.Debug("NL_FundTransfersSave: LoanID: {0}, fundTransferID: {1}", this.LoanID, model.FundTransfer.FundTransferID);
					}

					// 11. save default loan options record
					model.Loan.LoanOptions.LoanOptionsID = DB.ExecuteScalar<long>(pconn, "NL_LoanOptionsSave",
					   CommandSpecies.StoredProcedure, DB.CreateTableParameter("Tbl", new NL_LoanOptions {
						   LoanID = LoanID,
						   UserID = 1, // default system user?
						   InsertDate = nowTime,
						   IsActive = true,
						   Notes = "default options"
					   }), new QueryParameter("@LoanID", LoanID)
					 );

					pconn.Commit();

					// ReSharper disable once CatchAllClause
				} catch (Exception ex) {

					pconn.Rollback();

					LoanID = 0;
					Error = ex.Message;
					Log.Error("Failed to add new loan: {0}", Error);

					SendMail("NL: loan rolled back", history, nlFees, nlSchedule, nlAgreements);

					NL_AddLog(LogType.Error, "Strategy failed - Failed to add new loan", this.strategyArgs, Error, ex.ToString(), ex.StackTrace);
					return;
				}

				// 7. Pacnet transaction
				try {
					if (model.FundTransfer != null && (model.FundTransfer.PacnetTransactions.Count > 0 && model.FundTransfer.FundTransferID > 0)) {

						var pacnetTransaction = model.FundTransfer.LastPacnetTransactions();
						pacnetTransaction.FundTransferID = model.FundTransfer.FundTransferID;
						pacnetTransaction.PacnetTransactionID = DB.ExecuteScalar<long>("NL_PacnetTransactionsSave", CommandSpecies.StoredProcedure, DB.CreateTableParameter("Tbl", pacnetTransaction));

						//Log.Debug("NL_PacnetTransactionsSave: LoanID: {0}, pacnetTransactionID: {1}", this.LoanID, pacnetTransaction.PacnetTransactionID);
					}
					// ReSharper disable once CatchAllClause
				} catch (Exception e1) {

					Error = e1.Message;
					Log.Error("Failed to save PacnetTransaction: {0}", Error);

					// PacnetTransaction error
					SendMail("NL: Failed to save PacnetTransaction", history, nlFees, nlSchedule, nlAgreements);
				}

				// 11. if setup fee - add payment to offset it
				SetupOffsetPayment();
				
				// 6. broker commissions
				// done in controller. When old loan removed: check if this is the broker's customer, calc broker fees, insert into LoanBrokerCommission
				if (model.Offer.BrokerSetupFeePercent > 0) {
					DB.ExecuteNonQuery(string.Format("UPDATE dbo.LoanBrokerCommission SET NLLoanID = {0} WHERE LoanID = {1}", LoanID, model.Loan.OldLoanID));
				}

				// OK
				SendMail("NL: Saved successfully", history, nlFees, nlSchedule, nlAgreements);

				// copy LoanCharges Ids into OldFeeID, NL_LoanFees
				DB.ExecuteNonQuery("NL_LoanFeesOldIDUpdate", CommandSpecies.StoredProcedure);

				// temporary - should be removed/modified after "old" loan remove
				CopyRebateTransaction();

				//MigrateLoanTransaction sMigrateLoan = new MigrateLoanTransaction();
				//try {
				//	sMigrateLoan.Execute();
				//	// ReSharper disable once CatchAllClause
				//} catch (Exception mex) {
				//	Error = mex.Message;
				//	Log.Error("Failed sync migration: {0}", Error);
				//	NL_AddLog(LogType.Error, "Failed sync migration", this.strategyArgs, Error, mex.ToString(), mex.StackTrace);
				//}

				NL_AddLog(LogType.Info, "Strategy End", this.strategyArgs, LoanID, Error, null);

				// ReSharper disable once CatchAllClause
			} catch (Exception ex) {
				NL_AddLog(LogType.Error, "Strategy failed", this.strategyArgs, Error, ex.ToString(), ex.StackTrace);
			}
		}//Execute
コード例 #7
0
        }         // Parse

        public CallCredit Save(CallCredit data)
        {
            if (data == null)
            {
                return(null);
            }


            Log.Info("Saving CallCredit data into DB...");

            ConnectionWrapper con = DB.GetPersistent();

            con.BeginTransaction();

            try {
                var arg = DB.CreateTableParameter <CallCredit>("Tbl", new List <CallCredit> {
                    data
                });


                //Log.Debug("\n\n\n\n\n\n\n\n\n\nSaveCallCredit - begin: {0}\n\n\n\n\n\n\n\n\n\n", data.Error.Length);

                long CallCreditID = DB.ExecuteScalar <long>(con, "SaveCallCredit", CommandSpecies.StoredProcedure, arg);

                //Log.Debug("\n\n\n\n\n\n\n\n\n\nSaveCallCredit - end, new id = {0}\n\n\n\n\n\n\n\n\n\n", CallCreditID);

                if (data.ApplicantData.Any())
                {
                    SaveCallCreditData(data.ApplicantData, CallCreditID, con);
                }

                if (data.Amendments.Any())
                {
                    SaveCallCreditAmendments(data.Amendments, CallCreditID, con);
                }

                if (data.ApplicantAddresses.Any())
                {
                    SaveCallCreditApplicantAddresses(data.ApplicantAddresses, CallCreditID, con);
                }

                if (data.ApplicantNames.Any())
                {
                    SaveCallCreditApplicantNames(data.ApplicantNames, CallCreditID, con);
                }

                if (data.Email.Any())
                {
                    SaveCallCreditEmail(data.Email, CallCreditID, con);
                }

                if (data.Telephone.Any())
                {
                    SaveCallCreditTelephone(data.Telephone, CallCreditID, con);
                }
            } catch (Exception ex) {
                Log.Warn(ex, "Failed to save CallCredit data");
                con.Rollback();
                return(null);
            }

            con.Commit();
            Log.Info("Saving CallCredit data into DB complete");
            return(data);
        }         // Save
コード例 #8
0
ファイル: Misc.cs プロジェクト: mbahar94/fracture
 public Transaction (ConnectionWrapper wrapper, bool exclusive) {
     _Wrapper = wrapper;
     _Future = _Wrapper.BeginTransaction(exclusive);
     _Active = true;
 }
コード例 #9
0
ファイル: Misc.cs プロジェクト: mbahar94/fracture
 public Transaction (ConnectionWrapper wrapper) {
     _Wrapper = wrapper;
     _Future = _Wrapper.BeginTransaction();
     _Active = true;
 }
コード例 #10
0
ファイル: CancelPayment.cs プロジェクト: vijayamazon/ezbob
		/// <exception cref="NL_ExceptionInputDataInvalid">Condition. </exception>
		/// <exception cref="NL_ExceptionLoanNotFound">Condition. </exception>
		/// <exception cref="NL_ExceptionCustomerNotFound">Condition. </exception>
		public override void Execute() {
			if (!CurrentValues.Instance.NewLoanRun) {
				NL_AddLog(LogType.Info, "NL disabled by configuration", null, null, null, null);
				return;
			}

			NL_AddLog(LogType.Info, "Started", this.strategyArgs, Error, null, null);

			if (CustomerID == 0) {
				Error = NL_ExceptionCustomerNotFound.DefaultMessage;
				NL_AddLog(LogType.Error, NL_ExceptionCustomerNotFound.DefaultMessage, this.strategyArgs, null, Error, null);
				throw new NL_ExceptionCustomerNotFound(Error);
			}

			if (Payment == null || Payment.LoanID == 0) {
				Error = NL_ExceptionLoanNotFound.DefaultMessage;
				NL_AddLog(LogType.Error, NL_ExceptionLoanNotFound.DefaultMessage, this.strategyArgs, null, Error, null);
				throw new NL_ExceptionLoanNotFound(Error);
			}

			if (Payment.PaymentID == 0) {
				Error = NL_ExceptionInputDataInvalid.DefaultMessage;
				NL_AddLog(LogType.Error, NL_ExceptionInputDataInvalid.DefaultMessage, this.strategyArgs, null, Error, null);
				throw new NL_ExceptionInputDataInvalid(Error);
			}

			if (Payment.PaymentStatusID != (int)NLPaymentStatuses.ChargeBack && Payment.PaymentStatusID != (int)NLPaymentStatuses.WrongPayment) {
				Error = "PaymentStatusID not ChargeBack and not WrongPayment";
				NL_AddLog(LogType.Error, NL_ExceptionInputDataInvalid.DefaultMessage, this.strategyArgs, Error, null, null);
				throw new NL_ExceptionInputDataInvalid(Error);
			}

			if (Payment.DeletionTime.Equals(DateTime.MinValue) || Payment.DeletionTime == null) {
				Error = "DeletionTime not set";
				NL_AddLog(LogType.Error, NL_ExceptionInputDataInvalid.DefaultMessage, this.strategyArgs, Error, null, null);
				throw new NL_ExceptionInputDataInvalid(Error);
			}

			if (Payment.DeletedByUserID == null || Payment.DeletedByUserID == 0) {
				Error = "DeletedByUserID not set";
				NL_AddLog(LogType.Error, NL_ExceptionInputDataInvalid.DefaultMessage, this.strategyArgs, Error, null, null);
				throw new NL_ExceptionInputDataInvalid(Error);
			}

			ConnectionWrapper pconn = DB.GetPersistent();

			try {

				pconn.BeginTransaction();

				Log.Debug("==============================={0}", new QueryParameter("PaymentStatusID", Payment.PaymentStatusID));

				// RESET PAID PRINCIPAL, INTEREST (SCHEDULE), FEES PAID AFTER [DeletionTime] on delete payment  - in SP NL_ResetPaymentsPaidAmounts, called from NL_PaymentCancel
				DB.ExecuteNonQuery(pconn, "NL_PaymentCancel", CommandSpecies.StoredProcedure, 
					new QueryParameter("PaymentID", Payment.PaymentID),
					new QueryParameter("LoanID", Payment.LoanID),
					new QueryParameter("PaymentStatusID", Payment.PaymentStatusID),
					new QueryParameter("DeletionTime", Payment.DeletionTime),
					new QueryParameter("DeletedByUserID", Payment.DeletedByUserID),
					new QueryParameter("Notes", Payment.Notes)
				);
				
				pconn.Commit();

				// ReSharper disable once CatchAllClause
			} catch (Exception ex) {

				pconn.Rollback();

				Error = ex.Message;
				Log.Error("Failed to cancel payment: {0}", Error);

				NL_AddLog(LogType.Error, "Failed - Rollback", Payment, Error, ex.ToString(), ex.StackTrace);

				return;
			}

			NL_AddLog(LogType.Info, "End", this.strategyArgs, Payment, null, null);

			// recalculate state with calculator + save new state to DB
			UpdateLoanDBState reloadLoanDBState = new UpdateLoanDBState(CustomerID, Payment.LoanID, UserID);
			try {
				reloadLoanDBState.Execute();
			} catch (Exception ex) {
				Error = ex.Message;
				NL_AddLog(LogType.Error, "Failed on UpdateLoanDBState", Payment, reloadLoanDBState.Error + "\n" + Error, ex.ToString(), ex.StackTrace);
			}

		}
コード例 #11
0
        /// <exception cref="NL_ExceptionCustomerNotFound">Condition. </exception>
        /// <exception cref="NL_ExceptionLoanNotFound">Condition. </exception>
        public override void Execute()
        {
            if (!CurrentValues.Instance.NewLoanRun)
            {
                NL_AddLog(LogType.Info, "NL disabled by configuration", null, null, null, null);
                return;
            }

            NL_AddLog(LogType.Info, "Strategy Start", this.strategyArgs, null, Error, null);

            if (model.CustomerID == 0)
            {
                Error = NL_ExceptionCustomerNotFound.DefaultMessage;
                NL_AddLog(LogType.Error, NL_ExceptionCustomerNotFound.DefaultMessage, this.strategyArgs, null, Error, null);
                throw new NL_ExceptionCustomerNotFound(Error);
            }

            if (model.Loan.LoanID == 0)
            {
                Error = NL_ExceptionLoanNotFound.DefaultMessage;
                NL_AddLog(LogType.Error, NL_ExceptionLoanNotFound.DefaultMessage, this.strategyArgs, null, Error, null);
                throw new NL_ExceptionLoanNotFound(Error);
            }

            NL_AddLog(LogType.Info, "recalculated loan state", model, null, Error, null);

            List <NL_LoanSchedules>        schedules        = new List <NL_LoanSchedules>();
            List <NL_LoanSchedulePayments> schedulePayments = new List <NL_LoanSchedulePayments>();
            List <NL_LoanFeePayments>      feePayments      = new List <NL_LoanFeePayments>();

            ConnectionWrapper pconn = DB.GetPersistent();

            try {
                pconn.BeginTransaction();

                // save new history - on rescheduling/rollover
                foreach (NL_LoanHistory h in model.Loan.Histories.Where(h => h.LoanHistoryID == 0))
                {
                    h.LoanHistoryID = DB.ExecuteScalar <long>(pconn, "NL_LoanHistorySave", CommandSpecies.StoredProcedure, DB.CreateTableParameter("Tbl", h));
                    // set for newly created scheduled it historyID
                    h.Schedule.ForEach(s => s.LoanHistoryID = h.LoanHistoryID);
                }

                // save up-to-date outstanding princpal, outstanding late fees, outstanding distributed fees, outstanding accumulated interest
                foreach (NL_LoanHistory h in model.Loan.Histories.Where(h => h.LoanHistoryID > 0))
                {
                    DB.ExecuteNonQuery(pconn, "NL_LoanHistoryUpdate", CommandSpecies.StoredProcedure,
                                       new QueryParameter("LoanHistoryID", h.LoanHistoryID),
                                       new QueryParameter("LateFees", h.LateFees),
                                       new QueryParameter("DistributedFees", h.DistributedFees),
                                       new QueryParameter("OutstandingInterest", h.OutstandingInterest));
                }

                // collect all schedules into one list
                model.Loan.Histories.ForEach(h => h.Schedule.ForEach(s => schedules.Add(s)));

                // save new schedules - on rescheduling/rollover
                DB.ExecuteNonQuery(pconn, "NL_LoanSchedulesSave", CommandSpecies.StoredProcedure,
                                   DB.CreateTableParameter <NL_LoanSchedules>("Tbl", schedules.Where(s => s.LoanScheduleID == 0)));

                // update schedules - closed time and statuses
                foreach (NL_LoanSchedules s in schedules.Where(s => s.LoanScheduleID > 0))
                {
                    DB.ExecuteNonQuery(pconn, "NL_LoanSchedulesUpdate", CommandSpecies.StoredProcedure,
                                       new QueryParameter("LoanScheduleID", s.LoanScheduleID),
                                       new QueryParameter("LoanScheduleStatusID", s.LoanScheduleStatusID),
                                       new QueryParameter("ClosedTime", s.ClosedTime));
                }

                // insert fees
                DB.ExecuteNonQuery(pconn, "NL_LoanFeesSave", CommandSpecies.StoredProcedure,
                                   DB.CreateTableParameter <NL_LoanFees>("Tbl", model.Loan.Fees.Where(f => f.LoanFeeID == 0)));

                // assign payment to loan
                foreach (NL_Payments p in model.Loan.Payments)
                {
                    // new SchedulePayments
                    p.SchedulePayments.Where(sp => sp.NewEntry).ForEach(sp => schedulePayments.Add(sp));

                    // update existing schedule payments - TODO remove after development end
                    p.SchedulePayments.Where(sp => !sp.NewEntry).ForEach(sp =>
                                                                         DB.ExecuteNonQuery(pconn, "NL_LoanSchedulePaymentsUpdate", CommandSpecies.StoredProcedure,
                                                                                            new QueryParameter("LoanSchedulePaymentID", sp.LoanSchedulePaymentID),
                                                                                            new QueryParameter("PrincipalPaid", sp.PrincipalPaid),
                                                                                            new QueryParameter("InterestPaid", sp.InterestPaid)));

                    // new FeePayments
                    p.FeePayments.Where(fp => fp.NewEntry).ForEach(fp => feePayments.Add(fp));

                    // update existing fee payments - TODO remove after development end
                    p.FeePayments.Where(fp => !fp.NewEntry).ForEach(fp =>
                                                                    DB.ExecuteNonQuery(pconn, "NL_LoanFeePaymentsUpdate", CommandSpecies.StoredProcedure,
                                                                                       new QueryParameter("LoanFeePaymentID", fp.LoanFeePaymentID),
                                                                                       new QueryParameter("Amount", fp.Amount))
                                                                    );
                }

                // save new schedule payment
                if (schedulePayments.Count > 0)
                {
                    DB.ExecuteNonQuery(pconn, "NL_LoanSchedulePaymentsSave", CommandSpecies.StoredProcedure, DB.CreateTableParameter <NL_LoanSchedulePayments>("Tbl", schedulePayments));
                }

                // save new fee payments
                if (feePayments.Count > 0)
                {
                    DB.ExecuteNonQuery(pconn, "NL_LoanFeePaymentsSave", CommandSpecies.StoredProcedure, DB.CreateTableParameter <NL_LoanFeePayments>("Tbl", feePayments));
                }

                // update loan status
                if (runClose)
                {
                    DB.ExecuteNonQuery(pconn, "NL_LoanUpdate", CommandSpecies.StoredProcedure,
                                       new QueryParameter("LoanID", model.Loan.LoanID),
                                       new QueryParameter("LoanStatusID", model.Loan.LoanStatusID),
                                       new QueryParameter("DateClosed", model.Loan.DateClosed)
                                       );
                }

                pconn.Commit();

                NL_AddLog(LogType.Info, "Strategy End", this.strategyArgs, model, Error, null);

                // ReSharper disable once CatchAllClause
            } catch (Exception ex) {
                pconn.Rollback();

                Error = ex.Message;
                Log.Error("Failed to update loan DB dbState. err: {0}", Error);

                NL_AddLog(LogType.Error, "Failed - Rollback", this.strategyArgs, Error, ex.ToString(), ex.StackTrace);
            }
        }