public bool RemoveLoan(int id) { using (LoanPriceEntities context = new LoanPriceEntities()) { Loans model = context.Loans.SingleOrDefault(c => c.ID == id); if (model != null) { // Delete the Password policy of this account LoanScheduleBL loanScheduleBL = new LoanScheduleBL(); loanScheduleBL.RemoveLoanSchedule(id); context.Loans.DeleteObject(model); context.SaveChanges(); return(true); } else { return(false); } } }
public bool RemoveAllLoans() { try { using (LoanPriceEntities context = new LoanPriceEntities()) { List <Loans> loans = context.Loans.ToList(); for (int i = 0; i < loans.Count; i++) { LoanScheduleBL loanScheduleBL = new LoanScheduleBL(); loanScheduleBL.RemoveLoanSchedule(loans[i].ID); context.DeleteObject(loans[i]); } context.SaveChanges(); return(true); } } catch (Exception ex) { return(false); } }
private void ComputeCouponDatesAndFractions(RadDatePicker txtBoxTradeDate, RadComboBox txtBoxLoanName, RadDatePicker txtBoxSettlementDate, RadDatePicker txtBoxMaturityDate, RadTextBox txtBoxCouponFrequency, RadTextBox txtNonDiscountedAverageLife, RadGrid grdCalculatedDates, int type, RadTextBox txtNotional, RadTextBox txtMargin, RadTextBox txtCurrency) { try { int countryID = getCountryForLoan(txtBoxLoanName); //PublicHolidayBLL bll = new PublicHolidayBLL(); //List<tblHoliday> publicHolidays = bll.GetPublicHolidays(countryID); List<CalculatedDates> calculatedList = new List<CalculatedDates>(); DateTime cpnDT; cpnDT = AddBusinessDays(DateTime.Now, 10); LoanScheduleBL loanScheduleBL = new LoanScheduleBL(); DataTable dtSchedule = loanScheduleBL.GenerateTable(15, 10, cpnDT, txtBoxCouponFrequency.Text, txtNotional.Text, txtBoxMaturityDate.SelectedDate.Value, cpnDT, Convert.ToDecimal(txtMargin.Text), Convert.ToString(txtCurrency.Text), Convert.ToDateTime(txtBoxTradeDate.SelectedDate.Value), txtBoxSettlementDate.SelectedDate.Value); if (dtSchedule.Rows.Count > 0) { LoansBLL loanBL = new LoansBLL(); int loanID = loanBL.GetLoanByCode(txtBoxLoanName.Text).ID; loanScheduleBL.EditSchedule(loanID, dtSchedule); } foreach (DataRow dr in dtSchedule.Rows) { CalculatedDates cal = new CalculatedDates(); cal.Fraction = dr["CoupFrac"].ToString(); cal.CalculatedDate = Convert.ToDateTime(dr["EndDate"]); calculatedList.Add(cal); } grdCalculatedDates.Visible = true; grdCalculatedDates.DataSource = calculatedList; grdCalculatedDates.DataBind(); switch (type) { case 1: tempCalculatedList1 = calculatedList; break; case 2: tempCalculatedList2 = calculatedList; break; case 3: tempCalculatedList3 = calculatedList; break; default: break; } } catch (Exception) { } }
private string CalculateIRR(string loanName, string marketPrice) { LoansBLL bll = new LoansBLL(); Loans loan = bll.GetLoanByCode(loanName); int loanID = loan.ID; double notional = Convert.ToDouble(loan.Notional); LoanScheduleBL loanScheduleBL = new LoanScheduleBL(); List<LoanSchedule> loanSchedule = new List<LoanSchedule>(); loanSchedule = loanScheduleBL.GetLoanByID(loanID); double[] cashFlows; double[] days; List<DateTime> scheduleDateTime = new List<DateTime>(); if (loanSchedule != null) { List<double> cashFlowDouble = new List<double>(); double mktPrice = 0.99; if (marketPrice != string.Empty) { mktPrice = Convert.ToDouble(marketPrice) / 100; } double dFirstCashFlow = (Convert.ToDouble(mktPrice) * Convert.ToDouble(notional)) * -1; scheduleDateTime.Add(loanSchedule.First().StartDate.Value); cashFlowDouble.Add(dFirstCashFlow); List<double> day = new List<double>(); foreach (var item in loanSchedule) { cashFlowDouble.Add(Convert.ToDouble(item.AmortisationInt)); day.Add(Convert.ToInt16(item.Days)); scheduleDateTime.Add(Convert.ToDateTime(item.EndDate)); } cashFlows = cashFlowDouble.ToArray(); days = day.ToArray(); } else { cashFlows = new double[1] { 0.0 }; days = new double[1] { 0.0 }; } //Zainco.NewtonRaphson.IRRCalculator.Domain.ICalculator calculator = new NewtonRaphsonIRRCalc(cashFlows); //Double d = calculator.Execute(); IRR irr = new IRR(); //double xirr = irr.Newtons_method(0.1, // irr.total_f_xirr(cashFlows, days), // irr.total_df_xirr(cashFlows, days)); double xirr = System.Numeric.Financial.XIrr(cashFlows, scheduleDateTime) * 100; return Convert.ToDecimal(xirr).ToString("0.00"); // return d; }
public List<LoanSchedule> BindLoanScheduleData() { LoanScheduleBL bll = new LoanScheduleBL(); if (ddlLoanDetailsCode.SelectedValue == string.Empty) { BindLoanDetails(); } List<LoanSchedule> lst = bll.GetLoanByID(Convert.ToInt16(ddlLoanDetailsCode.SelectedValue)); return lst; }
private void BindLoanDetailData(string loanCode) { LoanScheduleBL bll = new LoanScheduleBL(); LoansBLL loanBL = new LoansBLL(); if (loanCode != string.Empty) { Loans loan = loanBL.GetLoanByID(Convert.ToInt32(loanCode)); txtLoanDetailCurrency.Text = loan.Currency; txtLoanDetailMaturityDate.Text = loan.Maturity_Date; txtLoanDetailTradeDate.SelectedDate = DateTime.Now;//loan.Signing_Date; txtLoanDetailSettlementDate.SelectedDate = AddBusinessDays(DateTime.Now.Date, 10); txtLoanDetailNotional.Text = Convert.ToDecimal(loan.Notional).ToString("N"); hdnLoanDetailMargin.Value = loan.Margin.ToString(); txtLoanDetailCouponFreq.Text = loan.CouponFrequency; txtLoanDetailLastCouponDate.Text = loan.CouponDate; txtLoanDetailFixedOrFloating.Text = loan.FixedOrFloating; txtLoanDetailIRR.Text = CalculateIRR(loan.CodeName, txtLoanDetailPrice.Text); txtLoanDetailAvgLife.Text = AverageLife(loan.CodeName); txtAvgLifeNonDisc.Text = AverageLifeNonDiscount(loan.CodeName); txtLoanDetailAvgLifeRiskDisc.Text = AverageLifeRiskDisc(loan.CodeName); txtLoanDetailAvgLifeDisc.Text = AverageLifeDisc(loan.CodeName); if (txtLoanDetailPrice.Text != string.Empty) txtLoanDetailConsideration.Text = Convert.ToDecimal(Convert.ToDecimal(txtLoanDetailPrice.Text) * Convert.ToDecimal(loan.Notional)).ToString("0.00"); else txtLoanDetailConsideration.Text = Convert.ToDecimal(1 * Convert.ToDecimal(loan.Notional)).ToString("0.00"); //txtLoanDetailDiscountMargin.Text = loan.di grdLoanDetail.DataSource = bll.GetLoanByID(Convert.ToInt16(loanCode)); grdLoanDetail.DataBind(); } }
//private void BindLoanCodeDetails() //{ // try // { // LoansBLL bll = new LoansBLL(); // string strLoanName = ddlAddLoanCode.Text.ToString(); // if (strLoanName.Contains(';')) // { // strLoanName = strLoanName.Replace(';', ' '); // } // Loans loan = bll.GetLoanByCode(strLoanName.Trim()); // if (loan != null) // { // txtBoxAddBorrower.Text = Convert.ToString(loan.Borrower); // txtBoxAddSector.Text = Convert.ToString(loan.Sector); // if (loan.Signing_Date != "") // txtBoxAddSigningDate.SelectedDate = Convert.ToDateTime(loan.Signing_Date); // else // txtBoxAddSigningDate.Clear(); // if (loan.Maturity_Date != "") // txtBoxAddMaturityDate.SelectedDate = Convert.ToDateTime(loan.Maturity_Date); // else // txtBoxAddMaturityDate.Clear(); // txtBoxFacilitySize.Text = loan.FacilitySize; // ddlAddFixedOrFloating.SelectedValue = loan.FixedOrFloating; // txtBoxAddMargin.Text = loan.Margin; // ddlAddCurrency.SelectedValue = loan.Currency; // ddlCountry.SelectedValue = loan.Country; // ddlAddCouponFrequency.SelectedValue = loan.CouponFrequency; // if (loan.Bilateral == true) // ddlAddBilateral.SelectedValue = "Yes"; // else // ddlAddBilateral.SelectedValue = "No"; // ddlAmortizing.SelectedValue = loan.Amortizing; // lblConfirm.Text = "Loan already exists, do you wish to overwrite?"; // _operation = "Edit"; // } // else // { // _operation = "Add"; // } // //else // //{ // // Clear(); // //} // } // catch (Exception) // { // } //} private void BindLoanCodeDetails() { try { LoansBLL bll = new LoansBLL(); string strLoanName = ddlAddLoanCode.Text.ToString(); if (strLoanName.Contains(';')) { strLoanName = strLoanName.Replace(';', ' '); } Loans loan = bll.GetLoanByCode(strLoanName.Trim()); if (loan != null) { if (loan.Borrower != null) { ddlBorrower.SelectedValue = Convert.ToString(loan.Borrower); BorrowersBL borrowerBL = new BorrowersBL(); if (ddlBorrower.SelectedValue != string.Empty) { if (ddlBorrower.SelectedItem != null) { Borrower borrower = borrowerBL.GetBorrower(ddlBorrower.SelectedItem.Text); txtGrid.Text = loan.Grid; txtSummitCredit.Text = loan.SummitCreditEntity; } } } // txtBoxAddSector.Text = Convert.ToString(loan.Sector); if (loan.Sector != null) { ddlSector.SelectedValue = Convert.ToString(loan.Sector); } if (loan.Signing_Date != "" && loan.Signing_Date != null) txtBoxAddSigningDate.SelectedDate = Convert.ToDateTime(loan.Signing_Date); else txtBoxAddSigningDate.Clear(); if (loan.Maturity_Date != "" && loan.Maturity_Date != null) txtBoxAddMaturityDate.SelectedDate = Convert.ToDateTime(loan.Maturity_Date); else txtBoxAddMaturityDate.Clear(); if (loan.CouponDate != "" && loan.CouponDate != null) txtCouponDate.SelectedDate = Convert.ToDateTime(loan.CouponDate); else txtCouponDate.Clear(); if (loan.FacilitySize != null) { txtBoxFacilitySize.Text = Convert.ToDecimal(loan.FacilitySize).ToString("N"); } if (loan.Fixed_Floating != null) { ddlAddFixedOrFloating.SelectedValue = loan.FixedOrFloating; } txtBoxAddMargin.Text = loan.Margin; if (loan.Currency != null) { ddlAddCurrency.SelectedValue = loan.Currency; } if (loan.Country != null) { ddlCountry.SelectedValue = loan.Country; } txtPP.Text = loan.PP; // txtCRating.Text = loan.CreditRating; txtStructureID.Text = loan.StructureID; if (loan.CouponFrequency != null) { ddlAddCouponFrequency.SelectedValue = loan.CouponFrequency; } txtNotional.Text = Convert.ToDecimal(loan.Notional).ToString("N"); if (loan.Bilateral == true) ddlAddBilateral.SelectedValue = "Yes"; else ddlAddBilateral.SelectedValue = "No"; if (loan.Amortizing == "Yes") { ddlAmortizing.SelectedValue = loan.Amortizing; if (ddlAmortizing.SelectedValue == "Yes") { if (loan.AmortisationsStartPoint != null) txtAmortisationsStartDate.SelectedDate = Convert.ToDateTime(loan.AmortisationsStartPoint); txtAmortisations.Text = loan.NoOfAmortisationPoint.ToString(); trDate.Visible = true; trNo.Visible = true; tblAmortisation.Visible = true; } } else { ddlAmortizing.SelectedValue = "No"; trDate.Visible = false; trNo.Visible = false; tblAmortisation.Visible = false; } txtGurantor.Text = loan.Gurantor; txtGrid.Text = loan.Grid; txtSummitCredit.Text = loan.SummitCreditEntity; CheckNodes(tvCreditRating, loan); txtBoxAddMargin.Text = loan.Margin; LoanScheduleBL scheduleBL = new LoanScheduleBL(); List<LoanSchedule> scheduleList = scheduleBL.GetLoanByID(loan.ID); if (scheduleList != null && scheduleList.Count > 0) { dt1.Clear(); //dt1.Columns.Add("ID", typeof(int)); //dt1.Columns.Add("StartDate", typeof(DateTime)); //dt1.Columns.Add("EndDate", typeof(DateTime)); //dt1.Columns.Add("Notional", typeof(long)); //dt1.Columns.Add("Factor", typeof(float)); for (int i = 0; i < scheduleList.Count; i++) { // dt1.Rows.Add(scheduleList[i].ID, scheduleList[i].StartDate, scheduleList[i].EndDate, scheduleList[i].Notation, scheduleList[i].Factor); dt1.Rows.Add(i + 1, scheduleList[i].StartDate.Value.ToShortDateString(), scheduleList[i].EndDate.Value.ToShortDateString(), scheduleList[i].CoupFrac, scheduleList[i].Notation, scheduleList[i].Amortisation, scheduleList[i].Factor, scheduleList[i].Spread, scheduleList[i].CouponPaymentDate, scheduleList[i].RiskFreeDP1, scheduleList[i].RiskFreeDP2, scheduleList[i].FloatingRate, scheduleList[i].AllInRate, scheduleList[i].Interest, scheduleList[i].Days, scheduleList[i].AmortisationInt); } pnlAmortizing.Visible = true; grdAmortizing.Visible = true; btnCalculatSchedule.Visible = true; Session.Add("LoanScheduleData", dt1); grdAmortizing.DataSource = dt1; grdAmortizing.DataBind(); } else { Session.Remove("LoanScheduleData"); dt1.Clear(); pnlAmortizing.Visible = false; btnCalculatSchedule.Visible = false; grdAmortizing.Visible = false; } hfLoanID.Value = loan.ID.ToString(); Session.Add("EditLoanID", loan.ID.ToString()); lblConfirm.Text = "Loan already exists, do you wish to overwrite?"; _operation = "Edit"; } else { hfLoanID.Value = string.Empty; _operation = "Add"; lblConfirm.Text = "Are you sure you want to add this loan to database?"; // Clear(); } } catch (Exception) { } }
private List<LoanSchedule> GetLoanBySchedule(int loanID) { LoanScheduleBL loanScheduleBL = new LoanScheduleBL(); return loanScheduleBL.GetLoanByID(loanID); }
public bool RemoveLoan(int id) { using (LoanPriceEntities context = new LoanPriceEntities()) { Loans model = context.Loans.SingleOrDefault(c => c.ID == id); if (model != null) { // Delete the Password policy of this account LoanScheduleBL loanScheduleBL = new LoanScheduleBL(); loanScheduleBL.RemoveLoanSchedule(id); context.Loans.DeleteObject(model); context.SaveChanges(); return true; } else { return false; } } }
public bool RemoveAllLoans() { try { using (LoanPriceEntities context = new LoanPriceEntities()) { List<Loans> loans = context.Loans.ToList(); for (int i = 0; i < loans.Count; i++) { LoanScheduleBL loanScheduleBL = new LoanScheduleBL(); loanScheduleBL.RemoveLoanSchedule(loans[i].ID); context.DeleteObject(loans[i]); } context.SaveChanges(); return true; } } catch (Exception ex) { return false; } }
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) { } }
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) { } }
private void ComputeCouponDatesAndFractionsOld(RadDatePicker txtBoxTradeDate, RadComboBox txtBoxLoanName, RadDatePicker txtBoxSettlementDate, RadDatePicker txtBoxMaturityDate, RadTextBox txtBoxCouponFrequency, RadTextBox txtNonDiscountedAverageLife, RadGrid grdCalculatedDates, int type, RadTextBox txtNotional, RadTextBox txtMargin, RadTextBox txtCurrency) { try { int countryID = getCountryForLoan(txtBoxLoanName); PublicHolidayBLL bll = new PublicHolidayBLL(); List<tblHoliday> publicHolidays = bll.GetPublicHolidays(countryID); List<CalculatedDates> calculatedList = new List<CalculatedDates>(); DateTime cpnDT; cpnDT = AddBusinessDays(DateTime.Now, 10); LoanScheduleBL loanScheduleBL = new LoanScheduleBL(); DataTable dtSchedule = loanScheduleBL.GenerateTable(15, 10, cpnDT, txtBoxCouponFrequency.Text, txtNotional.Text, txtBoxMaturityDate.SelectedDate.Value, cpnDT, Convert.ToDecimal(txtMargin.Text), Convert.ToString(txtCurrency.Text), Convert.ToDateTime(txtBoxTradeDate.SelectedDate.Value), txtBoxSettlementDate.SelectedDate.Value); DateTime currentCouponDate; DateTime previousCouponDate; DateTime maturityDate; DateTime tradeDate; DateTime tradeDate1 = DateTime.Now.Date; if (txtBoxTradeDate.SelectedDate != null) { tradeDate1 = txtBoxTradeDate.SelectedDate.Value; } //DateTime settlementDate = DateTime.Now.Date; //if (txtBoxSettlementDate.SelectedDate != null) //{ // settlementDate = AddBusinessDays(txtBoxSettlementDate.SelectedDate.Value, 10); //} DateTime boxMaturityDate = DateTime.Now.Date; DateTime.TryParse(txtBoxSettlementDate.SelectedDate.Value.ToShortDateString(), out currentCouponDate); DateTime.TryParse(txtBoxSettlementDate.SelectedDate.Value.ToShortDateString(), out previousCouponDate); if (txtBoxMaturityDate.SelectedDate != null) { boxMaturityDate = txtBoxMaturityDate.SelectedDate.Value; } DateTime.TryParse(boxMaturityDate.ToShortDateString(), out maturityDate); DateTime.TryParse(tradeDate1.ToShortDateString(), out tradeDate); if (DateTime.TryParse(txtBoxSettlementDate.SelectedDate.Value.ToShortDateString(), out currentCouponDate)) { int cF = 0; System.Numeric.Frequency f = new System.Numeric.Frequency(); while (CurrentCouponDateLessThanMaturityDate(currentCouponDate, maturityDate)) { if (txtBoxCouponFrequency.Text == "Annual") { cF = 1; f = System.Numeric.Frequency.Annual; } if (txtBoxCouponFrequency.Text == "Semi-Annual") { cF = 2; f = System.Numeric.Frequency.SemiAnnual; } if (txtBoxCouponFrequency.Text == "Quarterly") { cF = 4; f = System.Numeric.Frequency.Quarterly; } if (txtBoxCouponFrequency.Text == "Monthly") { cF = 12; } int numberOfDaysPassed = 0; // if a weekend date or holiday move forward //while (IsSaturdaySundayDay(currentCouponDate) || IsPublicHoliday(publicHolidays, currentCouponDate)) //{ // currentCouponDate = currentCouponDate.AddDays(1); // numberOfDaysPassed = numberOfDaysPassed + 1; //} // Compute next coupon date using CoupNCD and correct for weekends CalculatedDates cal = new CalculatedDates(); System.Numeric.DayCountBasis d = System.Numeric.DayCountBasis.Actual365; previousCouponDate = currentCouponDate; currentCouponDate = System.Numeric.Financial.CoupNCD(currentCouponDate, maturityDate, f, d); DateTime previousBusinessDay = PreviousBusinessDay(currentCouponDate); cal.CalculatedDate = previousBusinessDay; //numberOfDaysPassed = currentCouponDate.Subtract(tradeDate).Days; // removed 31-03- 2014 asked by avr numberOfDaysPassed = currentCouponDate.Subtract(txtBoxSettlementDate.SelectedDate.Value).Days; //cal.Fraction = String.Format("{0:00.000}", numberOfDaysPassed / 365.25); cal.Fraction = String.Format("{0:00.00}", numberOfDaysPassed / 365.25); cal.ActualFraction = numberOfDaysPassed / 365.25; calculatedList.Add(cal); } if (calculatedList != null && calculatedList.Count > 0) { // When the cashflow is computed take the average of the fractions and set that to the non discounted average life text box. // txtNonDiscountedAverageLife.Text =Convert.ToDecimal( calculatedList.Last().ActualFraction).ToString("0.00"); } grdCalculatedDates.Visible = true; grdCalculatedDates.DataSource = calculatedList; grdCalculatedDates.DataBind(); switch (type) { case 1: tempCalculatedList1 = calculatedList; break; case 2: tempCalculatedList2 = calculatedList; break; case 3: tempCalculatedList3 = calculatedList; break; default: break; } } // tempLegend = txtBoxLoanName; } catch (Exception) { } }
protected DataTable GetCompactChartData(string loanName) { try { DataTable dt = new DataTable(); dt.Columns.Add("ID"); dt.Columns.Add("EndDate"); dt.Columns.Add("Notation"); LoansBLL loanBL = new LoansBLL(); int loanID = loanBL.GetLoanByCode(loanName).ID; LoanScheduleBL loanScheduleBL = new LoanScheduleBL(); List<LoanSchedule> loanSchedule = loanScheduleBL.GetLoanByID(loanID); if (loanSchedule != null) { for (int i = 0; i < loanSchedule.Count; i++) { dt.Rows.Add((i + 1), new DateTime(loanSchedule[i].EndDate.Value.Year, loanSchedule[i].EndDate.Value.Month, loanSchedule[i].EndDate.Value.Day), loanSchedule[i].Notation.ToString()); } } return dt; } catch (Exception) { return null; } }
private void FillData() { try { Loans loan = new Loans(); LoansBLL bll = new LoansBLL(); loan = bll.GetLoanByID(Convert.ToInt16(Session["EditLoanID"])); ddlAddLoanCode.SelectedValue = loan.CodeName; txtBoxAddLoanCode.Text = loan.CodeName; ddlBorrower.SelectedValue = loan.Borrower; // txtBoxAddSector.Text = loan.Sector; ddlSector.SelectedValue = loan.Sector; if (loan.Signing_Date != null) txtBoxAddSigningDate.SelectedDate = Convert.ToDateTime(loan.Signing_Date); if (loan.Maturity_Date != null) txtBoxAddMaturityDate.SelectedDate = Convert.ToDateTime(loan.Maturity_Date); ddlAddFixedOrFloating.SelectedValue = loan.FixedOrFloating; txtBoxAddMargin.Text = loan.Margin; ddlAddCurrency.SelectedValue = loan.Currency; bindCountry(); if (loan.Country != null) { CountryBL countryBL = new CountryBL(); int id = countryBL.GetCountryFromName(loan.Country); if (id != 0) ddlCountry.SelectedValue = Convert.ToString(id); } ddlAddCouponFrequency.SelectedValue = loan.CouponFrequency; txtBoxFacilitySize.Text = Convert.ToDecimal(loan.FacilitySize).ToString("N"); if (loan.Bilateral == true) ddlAddBilateral.SelectedValue = "Yes"; else ddlAddBilateral.SelectedValue = "No"; ddlAmortizing.SelectedValue = loan.Amortizing; CheckNodes(tvCreditRating, loan); //txtCouponDate. //txtNotional txtPP.Text = loan.PP; // txtCRating.Text = loan.CreditRating; txtStructureID.Text = loan.StructureID; txtBoxAddMargin.Text = loan.Margin; if (loan.CouponDate != null) txtCouponDate.SelectedDate = Convert.ToDateTime(loan.CouponDate); txtNotional.Text = Convert.ToDecimal(loan.Notional).ToString("N"); if (ddlAmortizing.SelectedValue == "Yes") { if (loan.AmortisationsStartPoint != null) txtAmortisationsStartDate.SelectedDate = Convert.ToDateTime(loan.AmortisationsStartPoint); txtAmortisations.Text = loan.NoOfAmortisationPoint.ToString(); trDate.Visible = true; trNo.Visible = true; tblAmortisation.Visible = true; } txtSummitCredit.Text = loan.SummitCreditEntity; txtGrid.Text = loan.Grid; txtGurantor.Text = loan.Gurantor; LoanScheduleBL scheduleBL = new LoanScheduleBL(); List<LoanSchedule> scheduleList = scheduleBL.GetLoanByID(loan.ID); if (scheduleList != null && scheduleList.Count > 0) { dt1.Clear(); //dt1.Columns.Add("ID", typeof(int)); //dt1.Columns.Add("StartDate", typeof(DateTime)); //dt1.Columns.Add("EndDate", typeof(DateTime)); //dt1.Columns.Add("Notional", typeof(long)); //dt1.Columns.Add("Factor", typeof(float)); for (int i = 0; i < scheduleList.Count; i++) { // dt1.Rows.Add(scheduleList[i].ID, scheduleList[i].StartDate, scheduleList[i].EndDate, scheduleList[i].Notation, scheduleList[i].Factor); dt1.Rows.Add(i + 1, scheduleList[i].StartDate.Value.ToShortDateString(), scheduleList[i].EndDate.Value.ToShortDateString(), scheduleList[i].CoupFrac, scheduleList[i].Notation, scheduleList[i].Amortisation, scheduleList[i].Factor); } pnlAmortizing.Visible = true; grdAmortizing.Visible = true; btnCalculatSchedule.Visible = true; grdAmortizing.DataSource = dt1; grdAmortizing.DataBind(); } hfLoanID.Value = loan.ID.ToString(); lblConfirm.Text = "Loan already exists, do you wish to overwrite?"; _operation = "Edit"; } catch (Exception) { } }
protected void txtLoanDetailSpread_TextChanged(object sender, EventArgs e) { LoanScheduleBL loanScheduleBL = new LoanScheduleBL(); loanScheduleBL.UpdateSpread(Convert.ToInt16(ddlLoanDetailsCode.SelectedValue), Convert.ToDecimal(txtLoanDetailSpread.Text)); Session.Add("LoanDetail", ddlLoanDetailsCode.SelectedValue); BindLoanDetailData(ddlLoanDetailsCode.SelectedValue); }
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); }