예제 #1
0
        public GetHighlightValuesResponse GetHighlightValues(GetHighlightValuesRequest request)
        {
            var prevDate = request.Date.AddDays(-1);
            var derHighlights = request.HighlightTypeIds;
            var highlights = DataContext.Highlights.Include(x => x.HighlightType)
                .Where(x => derHighlights.Contains(x.HighlightType.Id) && x.PeriodeType == PeriodeType.Daily && (x.Date == request.Date || x.Date == prevDate)).ToList();

            //var highlights = GetHighligts(derHighlights, request.Date);
            var response = new GetHighlightValuesResponse();
            if (highlights != null)
            {
                foreach (var highlight in highlights)
                {
                    if(highlight == null)
                    {
                        continue;
                    }
                    #region daily
                    if (highlight.PeriodeType == PeriodeType.Daily)
                    {
                        var highlightResp = response.Highlights.FirstOrDefault(x => x.HighlightTypeId == highlight.HighlightType.Id);
                        if (highlightResp == null)
                        {
                            highlightResp = new GetHighlightValuesResponse.DerHighlight { HighlightTypeId = highlight.HighlightType.Id };
                            response.Highlights.Add(highlightResp);
                        }
                        var isTodayValue = highlight.Date == request.Date && highlight.PeriodeType == PeriodeType.Daily;
                        if (isTodayValue)
                        {
                            highlightResp.HighlightTypeId = highlight.HighlightType.Id;
                            highlightResp.HighlightTypeValue = highlight.HighlightType.Value;
                            highlightResp.HighlightMessage = highlight.Message;
                            highlightResp.HighlightTitle = highlight.Title;
                            highlightResp.Date = highlight.Date;
                            highlightResp.Type = "now";
                            highlightResp.Id = highlight.Id;
                        }
                        else
                        {
                            var todayValue = highlights.FirstOrDefault(x => x.HighlightType.Id == highlight.HighlightType.Id && x.Date == request.Date && highlight.PeriodeType == PeriodeType.Daily);
                            if (todayValue != null)
                            {
                                highlightResp.HighlightTypeId = todayValue.HighlightType.Id;
                                highlightResp.HighlightTypeValue = todayValue.HighlightType.Value;
                                highlightResp.HighlightMessage = todayValue.Message;
                                highlightResp.HighlightTitle = todayValue.Title;
                                highlightResp.Date = todayValue.Date;
                                highlightResp.Type = "now";
                                highlightResp.Id = todayValue.Id;
                            }
                            else
                            {
                                var prevValue = highlights.OrderByDescending(x=>x.Date).FirstOrDefault(x => x.HighlightType.Id == highlight.HighlightType.Id && x.Date <= request.Date && highlight.PeriodeType == PeriodeType.Daily);
                                if (prevValue != null)
                                {
                                    highlightResp.HighlightTypeId = prevValue.HighlightType.Id;
                                    highlightResp.HighlightTypeValue = prevValue.HighlightType.Value;
                                    highlightResp.HighlightMessage = prevValue.Message;
                                    highlightResp.HighlightTitle = prevValue.Title;
                                    highlightResp.Date = prevValue.Date;
                                    highlightResp.Type = "prev";
                                    highlightResp.Id = 0;
                                }
                                else
                                {
                                    //yesterday value selected
                                    highlightResp.HighlightTypeId = highlight.HighlightType.Id;
                                    highlightResp.HighlightTypeValue = highlight.HighlightType.Value;
                                    highlightResp.HighlightMessage = highlight.Message;
                                    highlightResp.HighlightTitle = highlight.Title;
                                    highlightResp.Date = highlight.Date;
                                    highlightResp.Type = "prev";
                                    highlightResp.Id = 0;
                                }
                            }
                        }
                    }
                    #endregion
                    #region monthly
                    if (highlight.PeriodeType == PeriodeType.Monthly)
                    {
                        var highlightResp = response.Highlights.FirstOrDefault(x => x.HighlightTypeId == highlight.HighlightType.Id);
                        if (highlightResp == null)
                        {
                            highlightResp = new GetHighlightValuesResponse.DerHighlight { HighlightTypeId = highlight.HighlightType.Id };
                            response.Highlights.Add(highlightResp);
                        }
                        var isCurrentMonthValue = (highlight.Date.Month == request.Date.Month && highlight.Date.Year == request.Date.Year) && highlight.PeriodeType == PeriodeType.Monthly;
                        if (isCurrentMonthValue)
                        {
                            highlightResp.HighlightTypeId = highlight.HighlightType.Id;
                            highlightResp.HighlightTypeValue = highlight.HighlightType.Value;
                            highlightResp.HighlightMessage = highlight.Message;
                            highlightResp.HighlightTitle = highlight.Title;
                            highlightResp.Date = highlight.Date;
                            highlightResp.Type = "now";
                            highlightResp.Id = highlight.Id;
                        }
                        else
                        {
                            var currentMonthValue = highlights.FirstOrDefault(x => x.HighlightType.Id == highlight.HighlightType.Id && (x.Date.Month == request.Date.Month && x.Date.Year == request.Date.Year) && highlight.PeriodeType == PeriodeType.Monthly);
                            if (currentMonthValue != null)
                            {
                                highlightResp.HighlightTypeId = currentMonthValue.HighlightType.Id;
                                highlightResp.HighlightTypeValue = currentMonthValue.HighlightType.Value;
                                highlightResp.HighlightMessage = currentMonthValue.Message;
                                highlightResp.HighlightTitle = currentMonthValue.Title;
                                highlightResp.Date = currentMonthValue.Date;
                                highlightResp.Type = "now";
                                highlightResp.Id = currentMonthValue.Id;
                            }
                            else
                            {
                                var prevMonthValue = highlights.OrderByDescending(x=>x.Date).FirstOrDefault(x => x.HighlightType.Id == highlight.HighlightType.Id && x.Date <= request.Date && highlight.PeriodeType == PeriodeType.Monthly);
                                if (prevMonthValue != null)
                                {
                                    highlightResp.HighlightTypeId = prevMonthValue.HighlightType.Id;
                                    highlightResp.HighlightTypeValue = prevMonthValue.HighlightType.Value;
                                    highlightResp.HighlightMessage = prevMonthValue.Message;
                                    highlightResp.HighlightTitle = prevMonthValue.Title;
                                    highlightResp.Date = prevMonthValue.Date;
                                    highlightResp.Type = "prev";
                                    highlightResp.Id = prevMonthValue.Id;
                                }
                                else
                                {
                                    //yesterday value selected
                                    highlightResp.HighlightTypeId = highlight.HighlightType.Id;
                                    highlightResp.HighlightTypeValue = highlight.HighlightType.Value;
                                    highlightResp.HighlightMessage = highlight.Message;
                                    highlightResp.HighlightTitle = highlight.Title;
                                    highlightResp.Date = highlight.Date;
                                    highlightResp.Type = "prev";
                                    highlightResp.Id = highlight.Id;
                                }
                            }
                        }
                    }
                    #endregion
                    #region yearly
                    if(highlight.PeriodeType == PeriodeType.Yearly)
                    {
                        var highlightResp = response.Highlights.FirstOrDefault(x => x.HighlightTypeId == highlight.HighlightType.Id);
                        if (highlightResp == null)
                        {
                            highlightResp = new GetHighlightValuesResponse.DerHighlight { HighlightTypeId = highlight.HighlightType.Id };
                            response.Highlights.Add(highlightResp);
                        }
                        var isCurrentYear = highlight.Date == request.Date && highlight.PeriodeType == PeriodeType.Yearly;
                        if (isCurrentYear)
                        {
                            highlightResp.HighlightTypeId = highlight.HighlightType.Id;
                            highlightResp.HighlightTypeValue = highlight.HighlightType.Value;
                            highlightResp.HighlightMessage = highlight.Message;
                            highlightResp.HighlightTitle = highlight.Title;
                            highlightResp.Date = highlight.Date;
                            highlightResp.Type = "now";
                            highlightResp.Id = highlight.Id;
                        }
                        else
                        {
                            var CurrentYearValue = highlights.FirstOrDefault(x => x.HighlightType.Id == highlight.HighlightType.Id && x.Date.Year == request.Date.Year && highlight.PeriodeType == PeriodeType.Daily);
                            if (CurrentYearValue != null)
                            {
                                highlightResp.HighlightTypeId = CurrentYearValue.HighlightType.Id;
                                highlightResp.HighlightTypeValue = CurrentYearValue.HighlightType.Value;
                                highlightResp.HighlightMessage = CurrentYearValue.Message;
                                highlightResp.HighlightTitle = CurrentYearValue.Title;
                                highlightResp.Date = CurrentYearValue.Date;
                                highlightResp.Type = "now";
                                highlightResp.Id = CurrentYearValue.Id;
                            }
                            else
                            {
                                var lastYearValue = highlights.OrderByDescending(x => x.Date).FirstOrDefault(x => x.HighlightType.Id == highlight.HighlightType.Id && x.Date.Year <= request.Date.Year && highlight.PeriodeType == PeriodeType.Yearly);
                                if (lastYearValue != null)
                                {
                                    highlightResp.HighlightTypeId = lastYearValue.HighlightType.Id;
                                    highlightResp.HighlightTypeValue = lastYearValue.HighlightType.Value;
                                    highlightResp.HighlightMessage = lastYearValue.Message;
                                    highlightResp.HighlightTitle = lastYearValue.Title;
                                    highlightResp.Date = lastYearValue.Date;
                                    highlightResp.Type = "prev";
                                    highlightResp.Id = lastYearValue.Id;
                                }
                                else
                                {
                                    //yesterday value selected
                                    highlightResp.HighlightTypeId = highlight.HighlightType.Id;
                                    highlightResp.HighlightTypeValue = highlight.HighlightType.Value;
                                    highlightResp.HighlightMessage = highlight.Message;
                                    highlightResp.HighlightTitle = highlight.Title;
                                    highlightResp.Date = highlight.Date;
                                    highlightResp.Type = "prev";
                                    highlightResp.Id = highlight.Id;
                                }
                            }
                        }
                    }
                    #endregion
                }
            }
            return response;
        }
예제 #2
0
 private DerValuesViewModel GetDerValuesPerSection(string date, int[] actualKpiIds, int[] targetKpiIds, int[] highlightTypeIds)
 {
     var theDate = DateTime.ParseExact(date, "MM/dd/yyyy", CultureInfo.InvariantCulture);
     var kpiInformationValuesRequest = new GetKpiInformationValuesRequest
     {
         Date = theDate,
         ActualKpiIds = actualKpiIds,
         TargetKpiIds = targetKpiIds
     };
     var kpiInformationValuesResponse = _derTransactionService.GetKpiInformationValues(kpiInformationValuesRequest);
     var highlightValuesRequest = new GetHighlightValuesRequest
     {
         Date = theDate,
         HighlightTypeIds = highlightTypeIds
     };
     var highlightValuesResponse = _derTransactionService.GetHighlightValues(highlightValuesRequest);
     var viewModel = new DerValuesViewModel();
     viewModel.Highlights = highlightValuesResponse.Highlights.MapTo<DerValuesViewModel.DerHighlightValuesViewModel>();
     viewModel.KpiInformations = kpiInformationValuesResponse.KpiInformations.MapTo<DerValuesViewModel.KpiInformationValuesViewModel>();
     return viewModel;
 }