Пример #1
0
        public ActionResult Index()
        {
            var isAdmin = this.UserProfile().IsSuperAdmin;

            ViewBag.IsSuperAdmin = isAdmin;
            var response = new AllKpiTargetsResponse();

            if (isAdmin)
            {
                response = _kpiTargetService.GetAllKpiTargets();
            }
            else
            {
                response = _kpiTargetService.GetAllKpiTargetByRole(new GetKpiTargetsConfigurationRequest {
                    RoleGroupId = this.UserProfile().RoleId
                });
            }
            if (response.IsSuccess)
            {
                var viewModel = response.MapTo <IndexKpiTargetViewModel>();
                return(View(viewModel));
            }

            return(base.ErrorPage(response.Message));
        }
Пример #2
0
        public AllKpiTargetsResponse GetAllKpiTargets()
        {
            var response = new AllKpiTargetsResponse();

            try
            {
                var kpiTargets = DataContext.Kpis
                                 .Include(x => x.Measurement)
                                 .Include(x => x.Type)
                                 .Include(x => x.RoleGroup)
                                 .AsEnumerable()
                                 .OrderBy(x => x.Order)
                                 .GroupBy(x => x.RoleGroup).ToDictionary(x => x.Key);



                foreach (var item in kpiTargets)
                {
                    var kpis = new List <AllKpiTargetsResponse.Kpi>();
                    foreach (var val in item.Value)
                    {
                        kpis.Add(val.MapTo <AllKpiTargetsResponse.Kpi>());
                    }

                    response.RoleGroups.Add(new AllKpiTargetsResponse.RoleGroup
                    {
                        Id   = item.Key.Id,
                        Name = item.Key.Name,
                        Kpis = kpis
                    });
                }

                response.IsSuccess = true;
            }
            catch (ArgumentNullException argumentNullException)
            {
                response.Message = argumentNullException.Message;
            }
            catch (InvalidOperationException invalidOperationException)
            {
                response.Message = invalidOperationException.Message;
            }

            return(response);
        }