Beispiel #1
0
        /// <summary>
        /// Get Heat Map for clients
        /// </summary>
        /// <param name="heatMapRequest"></param>
        /// <returns></returns>
        public string GetClientsHeatMap(ClientsHeatMapRequestViewModel heatMapRequest)
        {
            String json             = string.Empty;
            string heatMapItemsJson = string.Empty;
            string heatMapJson      = string.Empty;

            try
            {
                UserContext userContext = UserHelper.getUserContext();
                if (heatMapRequest != null && heatMapRequest.EmployeeID == null)
                {
                    heatMapRequest.EmployeeID = userContext.UserId;
                }
                ClientsHeatMapRequest request        = BusinessMapper.MappingHeatMapViewModelToBusinessModel(heatMapRequest);
                HeatMapDetails        heatMapDetails = _clientsHeatMapRepository.GetHeatMapForClients(request);
                if (heatMapDetails != null && heatMapDetails.ClientsHeatMapList != null && heatMapDetails.ClientsHeatMapList.Count > 0)
                {
                    ClientsHeatMapResponse[]             clientsHeatMapItemsArray = heatMapDetails.ClientsHeatMapList.ToArray();
                    List <IDictionary <string, object> > pivotArray = clientsHeatMapItemsArray.ToPivotArray(item => item.HeatMapItemName,
                                                                                                            item => item.ClientCode,
                                                                                                            items => items.Any() ? items.First().HeatMapItemNameDetail : new HeatMapItemDetail());
                    foreach (IDictionary <string, object> ele in pivotArray)
                    {
                        int?                     riskFactorScore   = null;
                        int?                     metricScore       = null;
                        List <object>            metricRiskFactors = ele.Where(x => x.Key != "ClientCode").Select(x => x.Value).ToList();
                        List <HeatMapItemDetail> heatmapItems      = new List <HeatMapItemDetail>();
                        foreach (HeatMapItemDetail item in metricRiskFactors)
                        {
                            if (item.Type == "RiskFactor" && item.Score != null)
                            {
                                if (riskFactorScore == null)
                                {
                                    riskFactorScore = item.Score;
                                }
                                else
                                {
                                    riskFactorScore += item.Score;
                                }
                            }
                            if (item.Type == "Metric" && item.Score != null)
                            {
                                if (metricScore == null)
                                {
                                    metricScore = item.Score;
                                }
                                else
                                {
                                    metricScore += item.Score;
                                }
                            }
                        }

                        ClientsHeatMapResponse result = heatMapDetails.ClientsHeatMapList.First(c => c.ClientCode == (ele.ContainsKey("ClientCode") ? (string)ele["ClientCode"] : string.Empty));
                        if (result != null)
                        {
                            ele.Add("ChecklistMonthlyDate", result.ChecklistMonthlyDate != null ? result.ChecklistMonthlyDate.Value.ToString("MMM") : "N/A");
                            ele.Add("ChecklistWeeklyDate", result.ChecklistWeeklyDate != null ? result.ChecklistWeeklyDate.Value.ToString("dd MMM") : "N/A");
                            ele.Add("ClientName", result.ClientName);
                            ele.Add("LTM", result.Ltm);
                            ele.Add("MetricScore", metricScore);
                            ele.Add("RiskFactorScore", riskFactorScore);
                            ele.Add("Risk", result.Risk);
                            ele.Add("RiskPercent", result.RiskPercentage);
                            ele.Add("RiskPercentClass", result.RiskPercentage != null ? "risk_" + result.RiskPercentage : "");
                            ele.Add("SiteAcronym", result.SiteAcronym);
                            ele.Add("Specialty", result.Specialty);
                            ele.Add("BusinessUnitCode", result.BusinessUnitCode);
                            ele.Add("SystemCode", result.SystemCode);
                            string trendStatus = string.Empty;
                            if (result.Trend != null)
                            {
                                trendStatus = result.Trend == result.Risk ? "trend_equal" : (result.Trend < result.Risk ? "fa-caret-down red_Trend" : "fa-caret-up green_Trend");
                            }
                            ele.Add("Trend", trendStatus);
                        }
                    }
                    heatMapJson = JsonConvert.SerializeObject(pivotArray, new KeyValuePairConverter());
                }

                if (heatMapDetails != null && heatMapDetails.HeatMapItemTypeDetail != null && heatMapDetails.HeatMapItemTypeDetail.Count > 0)
                {
                    heatMapItemsJson = JsonConvert.SerializeObject(heatMapDetails.HeatMapItemTypeDetail);
                }
                json = JsonConvert.SerializeObject(new { heatmaps = heatMapJson, heatmapItems = heatMapItemsJson });
                return(json);
            }
            catch (Exception ex)
            {
                _logger.Log(ex, LogLevel.Error, ex.Message);
                return(null);
            }
        }