public void SaveLoanSchedule(LoanSchedule model) { using (LoanPriceEntities context = new LoanPriceEntities()) { if (model.ID > 0) { context.AddObject("LoanSchedule", model); } else { context.AddToLoanSchedules(model); } context.SaveChanges(); } }
protected void btnAddNewLoan_Click(object sender, EventArgs e) { try { LoansBLL bll = new LoansBLL(); if (txtBoxAddMaturityDate.SelectedDate.ToString() != "" && txtBoxAddSigningDate.SelectedDate.ToString() != "") { DateTime dtMaturity = Convert.ToDateTime(txtBoxAddMaturityDate.SelectedDate.Value); DateTime dtSigning = Convert.ToDateTime(txtBoxAddSigningDate.SelectedDate.Value); SettingsBLL settingBL = new SettingsBLL(); Setting setting = settingBL.GetSettingyear("Loan Year Settings"); if (setting != null) { TimeSpan ts = dtMaturity - dtSigning; int differenceYear = Convert.ToInt32((ts.TotalDays) / 365); int year = Convert.ToInt16(setting.Value); if (dtMaturity.Year > dtSigning.Year && (differenceYear) > year) { lblMessage.Text = "Maturity Date is not Valid"; lblMessage.Visible = true; return; } } } else { //lblMessage.Text = "Enter the Details"; //lblMessage.Visible = true; RadWindowManager1.RadAlert("Maturity Date and Signing Date required", 300, 150, "realedge associates", "alertCallBackFn"); return; } // check to see either the loan has been added or updated bool isNewLoan = false; Loans loan = new Loans(); if (!string.IsNullOrEmpty(hfLoanID.Value)) { isNewLoan = false; loan.ID = Convert.ToInt32(hfLoanID.Value); LogActivity("Update the Loan", "Update the existing loan", string.Empty); } else { isNewLoan = true; LogActivity("New Loan Added", "Add the new loan", string.Empty); } List<RatingDetails> ratingDetails = new List<RatingDetails>(); ratingDetails = ShowCheckedNodes(tvCreditRating); foreach (var item in ratingDetails) { switch (item.agencyName) { case "Moody's": loan.CreditRatingModys = item.rating; break; case "S&P's": loan.CreditRatingSPs = item.rating; break; case "Fitch": loan.CreditRatingFitch = item.rating; break; case "ING": loan.CreditRatingING = item.rating; break; default: break; } } loan.CodeName = ddlAddLoanCode.Text; loan.Borrower = ddlBorrower.Text; loan.Sector = ddlSector.SelectedValue; //txtBoxAddSector.Text; loan.Signing_Date = txtBoxAddSigningDate.SelectedDate.Value.ToShortDateString(); loan.Maturity_Date = txtBoxAddMaturityDate.SelectedDate.Value.ToShortDateString(); loan.FixedOrFloating = ddlAddFixedOrFloating.SelectedValue; loan.Margin = txtBoxAddMargin.Text; loan.Currency = ddlAddCurrency.SelectedValue; loan.Country = ddlCountry.SelectedValue; loan.CouponFrequency = ddlAddCouponFrequency.SelectedValue; loan.Gurantor = txtGurantor.Text; loan.Grid = txtGrid.Text; loan.SummitCreditEntity = txtSummitCredit.Text; if (txtBoxFacilitySize.Text != string.Empty) { loan.FacilitySize = Convert.ToDecimal(txtBoxFacilitySize.Text).ToString("N"); } loan.Bilateral = ddlAddBilateral.SelectedValue == "Yes"; loan.Amortizing = ddlAmortizing.SelectedValue; loan.PP = txtPP.Text; // loan.CreditRating = txtCRating.Text; loan.StructureID = txtStructureID.Text; //Coupon Date and Notional are missing. if (txtCouponDate.SelectedDate != null) { loan.CouponDate = txtCouponDate.SelectedDate.Value.ToShortDateString(); } loan.Notional = Convert.ToDecimal(txtNotional.Text).ToString("N").Trim(); if (ddlAmortizing.SelectedValue == "Yes") { if (txtAmortisationsStartDate.SelectedDate != null) { loan.AmortisationsStartPoint = txtAmortisationsStartDate.SelectedDate.Value.ToShortDateString(); } if (txtAmortisations.Text != string.Empty) { loan.NoOfAmortisationPoint = Convert.ToInt16(txtAmortisations.Text); } } else { loan.Amortizing = "Yes"; DateTime cpnDT; if (txtCouponDate.SelectedDate.ToString() == string.Empty) { cpnDT = AddBusinessDays(DateTime.Now, 10); loan.AmortisationsStartPoint = cpnDT.ToShortDateString(); } else { cpnDT = Convert.ToDateTime(txtCouponDate.SelectedDate); loan.AmortisationsStartPoint = txtCouponDate.SelectedDate.Value.ToShortDateString(); } loan.NoOfAmortisationPoint = 10; LoanScheduleBL loanScheduleBL = new LoanScheduleBL(); DateTime tradeDate = DateTime.Now; DataTable dtSchedule = loanScheduleBL.GenerateTable(15, Convert.ToInt16(loan.NoOfAmortisationPoint), Convert.ToDateTime(loan.AmortisationsStartPoint), loan.CouponFrequency.ToString(), loan.Notional.ToString(), Convert.ToDateTime(loan.Maturity_Date), Convert.ToDateTime(loan.CouponDate), Convert.ToDecimal(loan.Margin), Convert.ToString(loan.Currency), Convert.ToDateTime(tradeDate), AddBusinessDays(Convert.ToDateTime(tradeDate), 10)); Session["LoanSchedule"] = dtSchedule; } DAL.Login login = Session["LogedInUser"] as DAL.Login; loan.CreatedBy = login.Name; loan.LastEdited = DateTime.Now; switch (_operation) { case "Add": if (bll.CheckForLoanCode(ddlAddLoanCode.Text.Trim())) { bll.SaveLoan(loan); login = Session["LogedInUser"] as DAL.Login; LoanHistory loanHistory = new LoanHistory(); LoanHistoryBL historyBL = new LoanHistoryBL(); loanHistory.Action = "Add"; loanHistory.LoanName = loan.CodeName; loanHistory.UserName = login.Name; loanHistory.LastModified = DateTime.Now; historyBL.SaveHistory(loanHistory); // lblAddLoanMessage.Visible = true; on 7-1 CalculateFactors(); LoanScheduleBL loanScheduleBL = new LoanScheduleBL(); if (Session["LoanSchedule"] != null) { dt1 = (DataTable)Session["LoanSchedule"]; } foreach (DataRow dr in dt1.Rows) { LoanSchedule loanSchedule = new LoanSchedule(); loanSchedule.LoanID = loan.ID; loanSchedule.StartDate = Convert.ToDateTime(dr["StartDate"]); loanSchedule.EndDate = Convert.ToDateTime(dr["EndDate"]); loanSchedule.CoupFrac = Convert.ToDecimal(dr["CoupFrac"]); loanSchedule.Notation = Convert.ToDecimal(dr["Notation"]); loanSchedule.Amortisation = Convert.ToDecimal(dr["Amortisation"]); loanSchedule.Factor = Convert.ToDecimal(dr["Factor"]); loanSchedule.Spread = Convert.ToDecimal(dr["Spread"]); loanSchedule.AllInRate = Convert.ToDecimal(dr["AllInRate"]); loanSchedule.CouponPaymentDate = Convert.ToDateTime(dr["CouponPaymentDate"]); loanSchedule.RiskFreeDP1 = Convert.ToDecimal(dr["RiskFreeDP1"]); loanSchedule.RiskFreeDP2 = Convert.ToDecimal(dr["RiskFreeDP2"]); loanSchedule.FloatingRate = Convert.ToDecimal(dr["FloatingRate"]); loanSchedule.Interest = Convert.ToDecimal(dr["Interest"]); loanSchedule.Days = Convert.ToInt16(dr["Days"]); loanSchedule.AmortisationInt = Convert.ToDecimal(dr["AmortisationInt"]); loanSchedule.CreatedOn = DateTime.UtcNow; loanScheduleBL.SaveLoanSchedule(loanSchedule); } //lblMessage.Text = "Loan added Successfully"; //lblMessage.Visible = true; RadWindowManager1.RadAlert(ddlAddLoanCode.Text + " added Successfully", 300, 150, "realedge associates", "alertCallBackFn"); } else { InsertDuplicateLoan(); } break; case "Edit": bll.EditLoan(loan, Convert.ToInt16(Session["EditLoanID"]), 2); login = Session["LogedInUser"] as DAL.Login; LoanHistory loanHis = new LoanHistory(); LoanHistoryBL historiesBL = new LoanHistoryBL(); loanHis.Action = "Edit"; loanHis.LoanName = loan.CodeName; loanHis.UserName = login.Name; loanHis.LastModified = DateTime.Now; historiesBL.SaveHistory(loanHis); CalculateFactors(); LoanScheduleBL scheduleBL = new LoanScheduleBL(); if (Session["LoanSchedule"] != null) { dt1 = (DataTable)Session["LoanSchedule"]; } scheduleBL.EditSchedule(Convert.ToInt16(Session["EditLoanID"]), dt1); // Clear(); //lblMessage.Text = "Loan updated Successfully"; //lblMessage.Visible = true; RadWindowManager1.RadAlert(ddlAddLoanCode.Text + " updated Successfully", 300, 150, "realedge associates", "alertCallBackFn"); //lblConfirm.Text = "Are you sure you want to add this loan to database?"; //_operation = "Add"; //Session.Remove("EditLoanID"); break; default: break; } // all loans List<Loans> allLoans = bll.GetLoans(); BindLoansTab(allLoans); BindLoansData(); BindHistoricalQuotesAndTradesTab(); // check to see if the loan has been added or updated if (isNewLoan) { ApplicationHub.NewLoanAdded(loan); } else { ApplicationHub.RefreshLoans(allLoans); } hdnSaved.Value = "Y"; BindLoanCode(); } catch (Exception ex) { //lblAddLoanMessage.Visible = true; on 7-1 //lblAddLoanMessage.Text = "Loan failed to save"; on 7-1 // lblMessage.Text = "Loan failed to save"; lblMessage.Text = ex.Message; lblMessage.Text = ex.InnerException.Message; lblMessage.Visible = true; LogActivity("New Loan(Unsuccessfull)", "Unable to save the loan", ex.Message); } }
public string AddImportedLoans(Loans item) { LogsBLL logBL = new LogsBLL(); string str = ""; try { using (LoanPriceEntities context = new LoanPriceEntities()) { string codeName = item.CodeName; if (CheckForLoanCode(item.CodeName)) { context.AddToLoans(item); context.SaveChanges(); //item = GetLoanByCode(codeName); LoanScheduleBL loanScheduleBL = new LoanScheduleBL(); string couponDT = item.CouponDate.ToString(); DateTime cpnDT; if (couponDT == string.Empty) cpnDT = AddBusinessDays(DateTime.Now, 10); else cpnDT = Convert.ToDateTime(item.CouponDate); DateTime tradeDate = DateTime.Now; DataTable dtSchedule = loanScheduleBL.GenerateTable(15, Convert.ToInt16(item.NoOfAmortisationPoint), Convert.ToDateTime(item.AmortisationsStartPoint), item.CouponFrequency.ToString(), item.Notional.ToString(), Convert.ToDateTime(item.Maturity_Date), Convert.ToDateTime(item.CouponDate), Convert.ToDecimal(item.Margin), Convert.ToString(item.Currency), Convert.ToDateTime(tradeDate), AddBusinessDays(Convert.ToDateTime(tradeDate), 10)); if (dtSchedule != null) { try { foreach (DataRow dr in dtSchedule.Rows) { LoanSchedule loanSchedule = new LoanSchedule(); loanSchedule.LoanID = item.ID; loanSchedule.StartDate = Convert.ToDateTime(dr["StartDate"]); loanSchedule.EndDate = Convert.ToDateTime(dr["EndDate"]); loanSchedule.Notation = Convert.ToDecimal(dr["Notation"]); loanSchedule.CoupFrac = Convert.ToDecimal(dr["CoupFrac"]); loanSchedule.Amortisation = Convert.ToDecimal(dr["Amortisation"]); loanSchedule.Factor = Convert.ToDecimal(dr["Factor"]); loanSchedule.CouponPaymentDate = Convert.ToDateTime(dr["CouponPaymentDate"]); loanSchedule.Spread = Convert.ToDecimal(dr["Spread"]); loanSchedule.RiskFreeDP1 = Convert.ToDecimal(dr["RiskFreeDP1"]); loanSchedule.RiskFreeDP2 = Convert.ToDecimal(dr["RiskFreeDP2"]); loanSchedule.FloatingRate = Convert.ToDecimal(dr["FloatingRate"]); loanSchedule.AllInRate = Convert.ToDecimal(dr["AllInRate"]); loanSchedule.Interest = Convert.ToDecimal(dr["Interest"]); loanSchedule.Days = Convert.ToInt16(dr["Days"]); loanSchedule.AmortisationInt = Convert.ToDecimal(dr["AmortisationInt"]); loanScheduleBL.SaveLoanSchedule(loanSchedule); } } catch (Exception ex) { str = ex.Message; // str = ex.Message; } } } else { DuplicateLoan loan = new DuplicateLoan(); loan.CodeName = item.CodeName; loan.Borrower = item.Borrower; loan.Country = item.Country; loan.Sector = item.Sector; loan.Maturity_Date = item.Maturity_Date; loan.Signing_Date = item.Signing_Date; loan.FixedOrFloating = item.FixedOrFloating; loan.Margin = item.Margin; loan.Currency = item.Currency; loan.CouponFrequency = item.CouponFrequency; loan.FacilitySize = item.FacilitySize; loan.Bilateral = item.Bilateral; loan.Amortizing = item.Amortizing; loan.AmortisationsStartPoint = loan.AmortisationsStartPoint; loan.CouponDate = loan.CouponDate; loan.Notional = loan.Notional; loan.NoOfAmortisationPoint = loan.NoOfAmortisationPoint; context.AddToDuplicateLoans(loan); context.SaveChanges(); } } } catch (Exception ex) { str = ex.Message; if (ex.InnerException != null) { str = str + " :: " + ex.InnerException.Message; } } return str; }
public void EditSchedule(int loanID, DataTable dt) { try { using (LoanPriceEntities context = new LoanPriceEntities()) { List<LoanSchedule> oldScheduleList = context.LoanSchedules.Where(s => s.LoanID == loanID).ToList(); if (oldScheduleList.Count > 0) { LoanScheduleBL loanScheduleBL = new LoanScheduleBL(); loanScheduleBL.RemoveLoanSchedule(loanID); for (int i = 0; i < dt.Rows.Count; i++) { // oldScheduleList[i].ID = Convert.ToInt16(dt.Rows[i][0]); //if (i >= oldScheduleList.Count) //{ LoanSchedule loanSchedule = new LoanSchedule(); loanSchedule.LoanID = loanID; loanSchedule.StartDate = Convert.ToDateTime(dt.Rows[i][1].ToString()); loanSchedule.EndDate = Convert.ToDateTime(dt.Rows[i][2].ToString()); loanSchedule.CoupFrac = Convert.ToDecimal(Convert.ToDecimal(dt.Rows[i][3].ToString()).ToString("0.00")); loanSchedule.Notation = Convert.ToDecimal(dt.Rows[i][4].ToString()); loanSchedule.Amortisation = Convert.ToDecimal(Convert.ToDecimal(dt.Rows[i][5].ToString()).ToString("0.00")); loanSchedule.Factor = Convert.ToDecimal(Convert.ToDecimal(dt.Rows[i][6].ToString()).ToString("0.00000")); if (dt.Rows[i][7] != null) loanSchedule.Spread = Convert.ToDecimal(Convert.ToDecimal(dt.Rows[i][7].ToString()).ToString("0.00000")); if (dt.Rows[i][8] != null) loanSchedule.CouponPaymentDate = Convert.ToDateTime(dt.Rows[i][8].ToString()); if (dt.Rows[i][9] != null) loanSchedule.RiskFreeDP1 = Convert.ToDecimal(Convert.ToDecimal(dt.Rows[i][9].ToString()).ToString("0.0000000")); if (dt.Rows[i][10] != null) loanSchedule.RiskFreeDP2 = Convert.ToDecimal(Convert.ToDecimal(dt.Rows[i][10].ToString()).ToString("0.0000000")); if (dt.Rows[i][11] != null) loanSchedule.FloatingRate = Convert.ToDecimal(Convert.ToDecimal(dt.Rows[i][11].ToString()).ToString("0.0000000")); if (dt.Rows[i][12] != null) loanSchedule.AllInRate = Convert.ToDecimal(Convert.ToDecimal(dt.Rows[i][12].ToString()).ToString("0.00000")); if (dt.Rows[i][13] != null) loanSchedule.Interest = Convert.ToDecimal(Convert.ToDecimal(dt.Rows[i][13].ToString()).ToString("0.00000")); if (dt.Rows[i][14] != null) loanSchedule.Days = Convert.ToInt16(dt.Rows[i][14].ToString()); if (dt.Rows[i][15] != null) loanSchedule.AmortisationInt = Convert.ToDecimal(Convert.ToDecimal(dt.Rows[i][15].ToString()).ToString("0.0000000")); SaveLoanSchedule(loanSchedule); // } //else //{ // oldScheduleList[i].StartDate = Convert.ToDateTime(dt.Rows[i][1].ToString()); // oldScheduleList[i].EndDate = Convert.ToDateTime(dt.Rows[i][2].ToString()); // oldScheduleList[i].CoupFrac = Convert.ToDecimal(Convert.ToDecimal(dt.Rows[i][3].ToString()).ToString("0.00")); // oldScheduleList[i].Notation = Convert.ToDecimal(dt.Rows[i][4].ToString()); // oldScheduleList[i].Amortisation = Convert.ToDecimal(Convert.ToDecimal(dt.Rows[i][5].ToString()).ToString("0.00")); // oldScheduleList[i].Factor = Convert.ToDecimal(Convert.ToDecimal(dt.Rows[i][6].ToString()).ToString("0.00000")); //} } } else { foreach (DataRow dr in dt.Rows) { LoanSchedule loanSchedule = new LoanSchedule(); loanSchedule.LoanID = loanID; loanSchedule.StartDate = Convert.ToDateTime(dr["StartDate"]); loanSchedule.EndDate = Convert.ToDateTime(dr["EndDate"]); loanSchedule.CoupFrac = Convert.ToDecimal(dr["CoupFrac"]); loanSchedule.Notation = Convert.ToDecimal(dr["Notation"]); loanSchedule.Amortisation = Convert.ToDecimal(dr["Amortisation"]); loanSchedule.Factor = Convert.ToDecimal(Convert.ToDecimal(dr["Factor"]).ToString("0.00000")); loanSchedule.Spread = Convert.ToDecimal(dr["Spread"]); loanSchedule.AllInRate = Convert.ToDecimal(dr["AllInRate"]); loanSchedule.CouponPaymentDate = Convert.ToDateTime(dr["CouponPaymentDate"]); loanSchedule.RiskFreeDP1 = Convert.ToDecimal(dr["RiskFreeDP1"]); loanSchedule.RiskFreeDP2 = Convert.ToDecimal(dr["RiskFreeDP2"]); loanSchedule.FloatingRate = Convert.ToDecimal(dr["FloatingRate"]); loanSchedule.Interest = Convert.ToDecimal(dr["Interest"]); loanSchedule.Days = Convert.ToInt16(dr["Days"]); loanSchedule.AmortisationInt = Convert.ToDecimal(dr["AmortisationInt"]); SaveLoanSchedule(loanSchedule); } } context.SaveChanges(); } } catch (Exception) { } }
/// <summary> /// Deprecated Method for adding a new object to the LoanSchedules EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToLoanSchedules(LoanSchedule loanSchedule) { base.AddObject("LoanSchedules", loanSchedule); }
/// <summary> /// Create a new LoanSchedule object. /// </summary> /// <param name="id">Initial value of the ID property.</param> public static LoanSchedule CreateLoanSchedule(global::System.Int32 id) { LoanSchedule loanSchedule = new LoanSchedule(); loanSchedule.ID = id; return loanSchedule; }