Ejemplo n.º 1
0
        private bool savePortFolioModel()
        {
            try
            {
                if ((optnAgreeRiskProfileYes.Selected == true && lblRiskProfile.Text != "Capital Preservation") || (optnAgreeRiskProfileNo.Selected == true && ddlRiskProfileList.SelectedIndex > 1))
                {
                    if (!validateAllRequiredFields())
                    {
                        return false;
                    }
                }

                int riskProfileId = -1;
                switch (strProfileName)
                {
                    case "Capital Preservation":
                        riskProfileId = 0;
                        break;
                    case "Cautious":
                        riskProfileId = 1;
                        break;
                    case "Moderately Cautious":
                        riskProfileId = 2;
                        break;
                    case "Balanced":
                        riskProfileId = 3;
                        break;
                    case "Moderately Adventurous":
                        riskProfileId = 4;
                        break;
                    case "Adventurous":
                        riskProfileId = 5;
                        break;
                    default:
                        break;
                }

                bool agreeRiskProfile = true;
                if (optnAgreeRiskProfileYes.Selected == true)
                {
                    agreeRiskProfile = true;
                }
                if (optnAgreeRiskProfileNo.Selected == true)
                {
                    agreeRiskProfile = false;
                }

                string newRiskProfile = "-1";
                newRiskProfile = ddlRiskProfileList.SelectedValue.ToString();

                bool followAssetAllocationOnRiskProfileYesNo = false;
                if (optnAssetAllocRiskProfile1.Selected == true)
                {
                    followAssetAllocationOnRiskProfileYesNo = true;
                }
                if (optnAssetAllocRiskProfile2.Selected == true)
                {
                    followAssetAllocationOnRiskProfileYesNo = false;
                }

                //True = Fund Risk Plottor, False = Fund Selection
                bool assetAllocationOnRiskProfileYesNo = false;
                if (optnAllocRiskProfile1.Selected == true)
                {
                    assetAllocationOnRiskProfileYesNo = true;
                }
                if (optnAllocRiskProfile2.Selected == true)
                {
                    assetAllocationOnRiskProfileYesNo = false;
                }

                bool includeNonCoreFundsYesNo = false;
                if (optnNonCoreFunds1.Selected == true)
                {
                    includeNonCoreFundsYesNo = true;
                }
                if (optnNonCoreFunds2.Selected == true)
                {
                    includeNonCoreFundsYesNo = false;
                }

                int premiumSelect = -1;
                if (optnPremiumSelect1.Selected == true)
                {
                    premiumSelect = 0;
                }
                if (optnPremiumSelect2.Selected == true)
                {
                    premiumSelect = 1;
                }

                double premiumAmount = 0;
                double premiumPercent = 0;
                double totalPremiumAmount = 0;
                if (premium.Text != null && premium.Text != "")
                {
                    premiumAmount = Convert.ToDouble(premium.Text);
                }

                string paymentMode = "-1";
                paymentMode = ddlPaymentMode.SelectedValue.ToString();

                List<int> lstAssetId = new List<int>();
                List<int> lstFundId = new List<int>();
                List<int> lstAllocationPercent = new List<int>();
                List<int> lstAmount = new List<int>();

                DataTable dtPortFolioBuilderDetail = new DataTable();
                dtPortFolioBuilderDetail.Columns.Add("AssetId", typeof(string));
                dtPortFolioBuilderDetail.Columns.Add("FundId", typeof(string));
                dtPortFolioBuilderDetail.Columns.Add("AllocationPercent", typeof(string));
                dtPortFolioBuilderDetail.Columns.Add("Amount", typeof(string));

                List<GridViewRow> gvRows = new List<GridViewRow>();
                if (optnAssetAllocRiskProfile1.Selected == true && (optnNonCoreFunds1.Selected == true || optnNonCoreFunds2.Selected == true))
                {
                    if (!validateFundAllocation())
                    {
                        return false;
                    }
                    foreach (GridViewRow gvRow in grdNonCoreFunds.Rows)
                    {
                        gvRows.Add(gvRow);
                    }
                }
                if (optnAssetAllocRiskProfile2.Selected == true && optnAllocRiskProfile1.Selected == true)
                {
                    if (!validateFundPlotter())
                    {
                        return false;
                    }
                    foreach (GridViewRow gvRow in grdFundRiskPlotter.Rows)
                    {
                        gvRows.Add(gvRow);
                    }
                    foreach (GridViewRow gvRow in grdSecondaryFunds.Rows)
                    {
                        gvRows.Add(gvRow);
                    }
                }
                if (optnAssetAllocRiskProfile2.Selected == true && optnAllocRiskProfile2.Selected == true)
                {
                    if (!ValidateFundSelection())
                    {
                        return false;
                    }
                    foreach (GridViewRow gvRow in grdFundsSelection.Rows)
                    {
                        gvRows.Add(gvRow);
                    }
                }

                if (gvRows != null)
                {
                    foreach (GridViewRow gvr in gvRows)
                    {
                        Label lblAssedId = (Label)gvr.FindControl("lblAssetId");
                        Label lblFundId = (Label)gvr.FindControl("lblFundId");
                        TextBox tbAllocationPercent = (TextBox)gvr.FindControl("txtAllocation");
                        TextBox tbAmount = (TextBox)gvr.FindControl("txtAmount");

                        string iAssetId = lblAssedId.Text;
                        string iFundId = lblFundId.Text;
                        string strAllocationPercent = tbAllocationPercent.Text;
                        string strAmount = tbAmount.Text;
                        double totalPercent = 0;
                        double totalpremiumAmt = 0;

                        if ((strAllocationPercent != null && strAllocationPercent != "" && Convert.ToDouble(strAllocationPercent) > 0) ||
                            (strAmount != null && strAmount != "" && Convert.ToDouble(strAmount) > 0))
                        {
                            if (strAllocationPercent == null || strAllocationPercent == "")
                            {
                                strAllocationPercent = "0";
                            }
                            if ( Convert.ToDouble(strAllocationPercent) == 0)
                            {
                                continue;
                            }
                            //{
                            totalPercent = Convert.ToDouble(strAllocationPercent);
                            //}
                            if (strAmount == null || strAmount == "")
                            {
                                strAmount = "0";
                            }
                            //else
                            //{
                            totalpremiumAmt = Convert.ToDouble(strAmount);
                            //}
                            dtPortFolioBuilderDetail.Rows.Add(iAssetId, iFundId, strAllocationPercent, strAmount);
                        }

                        premiumPercent = premiumPercent + totalPercent;
                        totalPremiumAmount = totalPremiumAmount + totalpremiumAmt;
                        //if (txtTotalPremium.Text != null && txtTotalPremium.Text != "")
                        //{
                        //premiumPercent = Convert.ToDouble(txtTotalPremium.Text);
                        //}
                    }

                    PortFolioModellingDAO portFolioDAO = new PortFolioModellingDAO();
                    bool bResult = portFolioDAO.SavePortFolioBuilderInfo(caseID,
                                                                        riskProfileId,
                                                                        agreeRiskProfile,
                                                                        newRiskProfile,
                                                                        followAssetAllocationOnRiskProfileYesNo,
                                                                        assetAllocationOnRiskProfileYesNo,
                                                                        includeNonCoreFundsYesNo,
                                                                        premiumSelect,
                                                                        premiumAmount,
                                                                        paymentMode,
                                                                        premiumPercent,
                                                                        totalPremiumAmount,
                                                                        dtPortFolioBuilderDetail);

                    if (bResult)
                    {
                        string actv = "";
                        if (ViewState["activity"] != null)
                        {
                            actv = ViewState["activity"].ToString();
                        }

                        string status = activityStatusCheck.getPortfolioBuilderStatus(premiumPercent);
                        activityStatusDao.saveOrUpdateActivityStatus(caseID, actv, status);

                        cst.Value = markStatusOnTab(caseID);
                        ScriptManager.RegisterStartupScript(this, typeof(string), "TabStatus", "tabstatus('"+cst.Value+"');", true);

                        string caseStatus = activityStatusCheck.getZPlanStatus(caseID);

                        string url = Server.MapPath("~/_layouts/Zurich/Printpages/");
                        pdfData = activityStatusCheck.sendDataToSalesPortal(caseID, caseStatus, url, sendPdf);

                        LoadPortFolioDetails();

                        if ((txtTotalPremium.Text != string.Empty && (Convert.ToInt32(txtTotalPremium.Text) < 100))
                            && !(optnAgreeRiskProfileNo.Selected == true && ddlRiskProfileList.SelectedIndex == 1))
                        {
                            lblSubmitMessageLessThan100.Visible = true;
                            lblSubmitMessage.Visible = false;
                        }
                        else
                        {
                            lblSubmitMessageLessThan100.Visible = false;
                            lblSubmitMessage.Visible = true;
                        }

                        return true;
                    }
                }
            }
            catch (Exception ex)
            {
                exceptionlog exLog = new exceptionlog();
                exLog.message = ex.Message + " class: PortFolioModelling Method: SavePortFolioModel";
                exLog.source = ex.Source;

                string strtmp = ex.StackTrace;
                strtmp = strtmp.Replace('\r', ' ');
                strtmp = strtmp.Replace('\n', ' ');
                exLog.stacktrace = strtmp;

                exLog.targetsitename = ex.TargetSite.Name;

                ActivityStatusDAO activityStatus = new ActivityStatusDAO();
                activityStatus.logException(exLog);
            }

            return false;
        }