public IHttpActionResult GetDashboardData(int id)
        {
            //if user is not admin return..
            var    identity = User.Identity as ClaimsIdentity;
            string userRole = identity.FindFirst(ClaimTypes.Role).Value;
            int    userId   = int.Parse(identity.FindFirst(ClaimTypes.SerialNumber).Value);

            if (userRole != "admin" && userId != id)
            {
                //ModelState.AddModelError("InvalidAccess", "You are not authorized !");
                return(BadRequest("UnauthorizedAccess"));
            }
            DashboardData dbData        = new DashboardData();
            ClientFunding clientFunding = new ClientFunding();
            Dictionary <string, List <DashboardReportData> > assetClassesData = clientFunding.GetAssetClassesReportData(id);
            List <DashboardReportData> assetClassesReportData                = assetClassesData["All"];
            List <DashboardReportData> assetClassesComparisonReportData      = assetClassesData["Growth"];
            Dictionary <string, List <DashboardReportData> > assetWealthData = clientFunding.GetNetWealthReportData(id);
            List <DashboardReportData> netWealthReportData           = assetWealthData["All"];
            List <DashboardReportData> netWealthComparisonReportData = assetWealthData["Net"];

            foreach (DashboardReportData item in assetClassesReportData)
            {
                switch (item.key)
                {
                case "Attractive Assets":
                    item.color = "darkred"; break;

                case "Int. Shares":
                case "Other Entities Assets":
                    item.color = "red"; break;

                case "Aus. Shares":
                case "Pension Assets":
                    item.color = "orange"; break;

                case "Property":
                case "Super Assets":
                    item.color = "yellow"; break;

                case "Int. Fixed Interest":
                    item.color = "lightgreen"; break;

                case "Aus. Fixed Interest":
                case "Personal Assets":
                    item.color = "green"; break;

                case "Cash":
                    item.color = "darkgreen"; break;
                }
            }

            foreach (DashboardReportData item in netWealthReportData)
            {
                switch (item.key)
                {
                case "Other Entities Assets":
                    item.color = "red"; break;

                case "Pension Assets":
                    item.color = "orange"; break;

                case "Super Assets":
                    item.color = "yellow"; break;

                case "Personal Assets":
                    item.color = "green"; break;
                }
            }

            dbData.AssetClassesReportData           = assetClassesReportData;
            dbData.NetWealthReportData              = netWealthReportData;
            dbData.AssetClassesComparisonReportData = assetClassesComparisonReportData;
            dbData.NetWealthComparisonReportData    = netWealthComparisonReportData;

            dbData.userData    = AppUser.GetById(id);
            dbData.lastFunding = clientFunding.GetLatestClientFunding(dbData.userData.UserEmail);

            AssetAllocationMaster assetAllocationMaster = db.AssetAllocationMasters.Find(dbData.lastFunding.RiskProfile);

            if (assetAllocationMaster != null)
            {
                dbData.lastFunding.ExpectedAttractiveAssets = assetAllocationMaster.AttractiveAssets;
                dbData.lastFunding.ExpectedAusFixedInterest = assetAllocationMaster.AusFixedInterest;
                dbData.lastFunding.ExpectedAusShares        = assetAllocationMaster.AusShares;
                dbData.lastFunding.ExpectedCash             = assetAllocationMaster.Cash;
                dbData.lastFunding.ExpectedIntFixedInterest = assetAllocationMaster.IntFixedInterest;
                dbData.lastFunding.ExpectedIntShares        = assetAllocationMaster.IntShares;
                dbData.lastFunding.ExpectedProperty         = assetAllocationMaster.Property;
            }

            dbData.ExpectedTotalFund = ProjectedData.GetByUserIdAndYear(id, dbData.lastFunding.FundingYear);

            return(Ok(dbData));
        }
        public IHttpActionResult GetClientFunding(int id, int fundingId)
        {
            //if user is not admin return..
            var    identity = User.Identity as ClaimsIdentity;
            string userRole = identity.FindFirst(ClaimTypes.Role).Value;
            int    userId   = int.Parse(identity.FindFirst(ClaimTypes.SerialNumber).Value);

            if (userRole != "admin" && userId != id)
            {
                //ModelState.AddModelError("InvalidAccess", "You are not authorized !");
                return(BadRequest("UnauthorizedAccess"));
            }

            ClientFundingDetails clientFundingDetails = new ClientFundingDetails();

            ClientFunding clientFunding = new ClientFunding();

            foreach (AssetAllocationMaster assetMaster in db.AssetAllocationMasters.ToList <AssetAllocationMaster>())
            {
                clientFundingDetails.riskProfiles.Add(new RiskProfileTypes
                {
                    RiskProfileType = assetMaster.RiskProfileType,
                    DisplayField    = assetMaster.DisplayField
                });
            }

            AppUser user = AppUser.GetById(id);

            clientFundingDetails.user = new AppUserBasicData();

            clientFundingDetails.user.UserEmail       = user.UserEmail;
            clientFundingDetails.user.FirstName       = user.FirstName;
            clientFundingDetails.user.LastName        = user.LastName;
            clientFundingDetails.user.DOB             = user.DOB;
            clientFundingDetails.user.SpouseFirstName = user.SpouseFirstName;
            clientFundingDetails.user.SpouseLastName  = user.SpouseLastName;
            clientFundingDetails.user.SpouseDOB       = user.SpouseDOB;

            if (fundingId == 0)
            {
                clientFundingDetails.funding = clientFunding.GetLatestClientFunding(clientFundingDetails.user.UserEmail);
            }
            else
            {
                clientFundingDetails.funding = clientFunding.GetByFundingId(fundingId);

                AssetAllocationMaster assetAllocationMaster = db.AssetAllocationMasters.Find(clientFundingDetails.funding.RiskProfile);

                clientFundingDetails.funding.ExpectedAttractiveAssets = assetAllocationMaster.AttractiveAssets;
                clientFundingDetails.funding.ExpectedAusFixedInterest = assetAllocationMaster.AusFixedInterest;
                clientFundingDetails.funding.ExpectedAusShares        = assetAllocationMaster.AusShares;
                clientFundingDetails.funding.ExpectedCash             = assetAllocationMaster.Cash;
                clientFundingDetails.funding.ExpectedIntFixedInterest = assetAllocationMaster.IntFixedInterest;
                clientFundingDetails.funding.ExpectedIntShares        = assetAllocationMaster.IntShares;
                clientFundingDetails.funding.ExpectedProperty         = assetAllocationMaster.Property;

                ProjectedData projections = new ProjectedData();
                clientFundingDetails.listProjectedData = projections.GetProjectedDataByClientId(id);
                ProjectedData clientExpectedProjectData = clientFundingDetails.listProjectedData.Find(i => i.Year == clientFundingDetails.funding.FundingYear);

                if (clientExpectedProjectData != null)
                {
                    clientFundingDetails.ExpectedTotalFund = clientExpectedProjectData.Value;
                }
                else
                {
                    clientFundingDetails.ExpectedTotalFund = 0;
                }
            }
            if (clientFundingDetails.funding == null)
            {
                return(NotFound());
            }

            return(Ok(clientFundingDetails));
        }