public async Task <ExecutiveScoreCard> GetExecutiveScoreCard(long employeeId)
        {
            var emp = await _ctx.Employees.Include(p => p.Supervisor).ById(employeeId);

            if (emp == null)
            {
                return(new ExecutiveScoreCard(employeeId, "NA", null, null,
                                              Enumerable.Empty <ExecutiveScoreCardRow>()));
            }

            var reports = _ctx.Employees.Where(p => p.SupervisorId == employeeId).ToList();
            var list    = new List <ExecutiveScoreCardRow>();

            foreach (var directReport in reports)
            {
                var data = new RecurseDirectReportData();
                var an   = _ctx.Nodes.Active().ProductIsNotExlcuded()
                           .Where(p => p.BuildSpecification.OwnerEmployeeId == directReport.Id);
                var apn = an.InPciScope();
                var all = _ctx.Nodes.Active().ProductIsNotExlcuded()
                          .Where(p => p.OwnerEmployeeId == directReport.Id);

                data.Specs = await _ctx.BuildSpecifications.CountAsync(p => p.OwnerEmployeeId == directReport.Id);

                data.Assigned += new ScoreCardPciCount(await apn.CountAsync(), await an.CountAsync());
                data.Passing  += new ScoreCardPciCount(
                    await apn.ByComplianceStatus(ComplianceStatusConstant.Succeeded).InChefScope().CountAsync(),
                    await an.ByComplianceStatus(ComplianceStatusConstant.Succeeded).InChefScope().CountAsync());
                data.Failing += new ScoreCardPciCount(
                    await apn.ByComplianceStatus(ComplianceStatusConstant.Failed).InChefScope().CountAsync(),
                    await an.ByComplianceStatus(ComplianceStatusConstant.Failed).InChefScope().CountAsync());
                data.NotReporting += new ScoreCardPciCount(
                    await apn.ByComplianceStatus(ComplianceStatusConstant.NotFound).InChefScope().CountAsync(),
                    await an.ByComplianceStatus(ComplianceStatusConstant.NotFound).InChefScope().CountAsync());
                data.OutOfChefScope += new ScoreCardPciCount(await apn.OutOfChefScope().CountAsync(),
                                                             await an.OutOfChefScope().CountAsync());
                data.All += new ScoreCardPciCount(await all.InPciScope().CountAsync(), await all.CountAsync());

                var reportCount = await _ctx.Employees.CountAsync(p => p.SupervisorId == directReport.Id);

                data = await RecurseDirectReports(directReport.Id, data);

                var row = new ExecutiveScoreCardRow(directReport.Id, directReport.OwnerText(), data.Specs,
                                                    data.Assigned, data.All, data.Passing, data.Failing, data.NotReporting, data.OutOfChefScope,
                                                    reportCount);
                list.Add(row);
            }

            return(new ExecutiveScoreCard(emp.Id, emp.OwnerText(), emp.SupervisorId, emp.Supervisor.OwnerText(),
                                          list.OrderBy(p => p.Name)));
        }
        private async Task <RecurseDirectReportData> RecurseDirectReports(long employeeId, RecurseDirectReportData data)
        {
            var direcReportIds = _ctx.Employees.Where(p => p.SupervisorId == employeeId).Select(p => p.Id).ToArray();
            var an             = _ctx.Nodes.Active().ProductIsNotExlcuded()
                                 .Where(p => direcReportIds.Contains(p.BuildSpecification.OwnerEmployeeId));
            var apn = an.InPciScope();
            var all = _ctx.Nodes.Active().ProductIsNotExlcuded()
                      .Where(p => direcReportIds.Contains(p.OwnerEmployeeId));

            data.Specs += await _ctx.BuildSpecifications.CountAsync(p => direcReportIds.Contains(p.OwnerEmployeeId));

            data.Assigned += new ScoreCardPciCount(await apn.CountAsync(), await an.CountAsync());
            data.Passing  += new ScoreCardPciCount(
                await apn.ByComplianceStatus(ComplianceStatusConstant.Succeeded).InChefScope().CountAsync(),
                await an.ByComplianceStatus(ComplianceStatusConstant.Succeeded).InChefScope().CountAsync());
            data.Failing += new ScoreCardPciCount(
                await apn.ByComplianceStatus(ComplianceStatusConstant.Failed).InChefScope().CountAsync(),
                await an.ByComplianceStatus(ComplianceStatusConstant.Failed).InChefScope().CountAsync());
            data.NotReporting += new ScoreCardPciCount(
                await apn.ByComplianceStatus(ComplianceStatusConstant.NotFound).InChefScope().CountAsync(),
                await an.ByComplianceStatus(ComplianceStatusConstant.NotFound).InChefScope().CountAsync());
            data.OutOfChefScope += new ScoreCardPciCount(await apn.OutOfChefScope().CountAsync(),
                                                         await an.OutOfChefScope().CountAsync());
            data.All += new ScoreCardPciCount(await all.InPciScope().CountAsync(), await all.CountAsync());


            foreach (var direcReportId in direcReportIds)
            {
                data = await RecurseDirectReports(direcReportId, data);
            }

            return(data);
        }