public static IQueryable <PROJECT_Dashboard> SummarizePROJECTDashboard(IQueryable <PROJECT> PROJECTS, Func <IQueryable <PROGRESS> > getLivePROGRESSESFunc, Func <IQueryable <BASELINE> > getLiveBASELINESFunc, Func <IQueryable <RATE> > getRATESFunc, Func <IQueryable <VARIATION> > getApprovedVARIATIONFunc = null)
        {
            IEnumerable <BASELINE>  LiveBASELINES  = getLiveBASELINESFunc().ToArray().AsEnumerable();
            IEnumerable <PROGRESS>  LivePROGRESSES = getLivePROGRESSESFunc().ToArray().AsEnumerable();
            IEnumerable <VARIATION> ApprovedVARIATIONS;

            if (getApprovedVARIATIONFunc != null)
            {
                ApprovedVARIATIONS = getApprovedVARIATIONFunc().ToArray().AsEnumerable();
            }
            else
            {
                ApprovedVARIATIONS = new List <VARIATION>();
            }

            IEnumerable <RATE>       AllRATES                = getRATESFunc();
            IEnumerable <PROJECT>    localPROJECTS           = PROJECTS.Where(x => x.STATUS == ProjectStatus.Active).ToArray().AsEnumerable(); //process only active PROJECTS
            List <PROJECT_Dashboard> returnPROJECT_Dashboard = new List <PROJECT_Dashboard>();

            IBluePrintsEntitiesUnitOfWork bluePrintsUnitOfWork = BluePrintsEntitiesUnitOfWorkSource.GetUnitOfWorkFactory().CreateUnitOfWork();
            IP6EntitiesUnitOfWork         p6UnitOfWork         = P6EntitiesUnitOfWorkSource.GetUnitOfWorkFactory().CreateUnitOfWork();

            foreach (PROJECT localPROJECT in localPROJECTS)
            {
                BASELINE currentPROJECTLiveBASELINE = LiveBASELINES.FirstOrDefault(x => x.GUID_PROJECT == localPROJECT.GUID);
                if (currentPROJECTLiveBASELINE == null)
                {
                    continue;
                }

                PROGRESS currentPROJECTLivePROGRESS = LivePROGRESSES.FirstOrDefault(x => x.GUID_PROJECT == localPROJECT.GUID);
                if (currentPROJECTLivePROGRESS == null)
                {
                    continue;
                }

                IQueryable <PROGRESS_ITEM> LivePROGRESS_ITEMS          = currentPROJECTLivePROGRESS.PROGRESS_ITEM.AsQueryable();
                IQueryable <BASELINE_ITEM> LiveBASELINE_ITEMS          = currentPROJECTLiveBASELINE.BASELINE_ITEM.AsQueryable();
                IQueryable <RATE>          RATESByProject              = AllRATES.Where(x => x.GUID_PROJECT == localPROJECT.GUID).AsQueryable();
                IEnumerable <VARIATION>    ApprovedVARIATIONSByProject = ApprovedVARIATIONS.Where(x => x.GUID_PROJECT == localPROJECT.GUID).AsEnumerable();

                IEnumerable <ReportableObject> PROJECTInfos = PROGRESS_ITEMProjectionQueries.JoinRATESAndPROGRESS_ITEMSOnBASELINE_ITEMS(
                    LiveBASELINE_ITEMS, () => currentPROJECTLivePROGRESS, () => currentPROJECTLiveBASELINE, () => LivePROGRESS_ITEMS, () => RATESByProject).ToArray().AsEnumerable();

                PROJECT_Dashboard currentPROJECT_Dashboard = new PROJECT_Dashboard()
                {
                    GUID = localPROJECT.GUID, PROJECT = localPROJECT, VARIATIONS = ApprovedVARIATIONSByProject
                };
                currentPROJECT_Dashboard.InitializeBuilder(PROJECTInfos, currentPROJECTLivePROGRESS, currentPROJECTLiveBASELINE, bluePrintsUnitOfWork, p6UnitOfWork);
                returnPROJECT_Dashboard.Add(currentPROJECT_Dashboard);
            }

            foreach (PROJECT_Dashboard project in returnPROJECT_Dashboard)
            {
                BuildProjectStats summaryManufacturer = new BuildProjectStats();
                summaryManufacturer.Manufacture(project.SummaryBuilder);
            }

            return(returnPROJECT_Dashboard.AsQueryable());
        }
        public static IQueryable <VARIATION_ITEMProjection> JoinRATESAndPROGRESS_ITEMSAndVARIATION_ITEMSOnBASELINE_ITEMS(IQueryable <BASELINE_ITEM> BASELINE_ITEMS, Func <PROGRESS> getPROGRESSFunc, Func <BASELINE> getBASELINEFunc, Func <VARIATION> getVARIATIONFunc, Func <IQueryable <PROGRESS_ITEM> > getPROGRESS_ITEMSFunc, Func <IQueryable <VARIATION_ITEM> > getVARIATION_ITEMSFunc, Func <IQueryable <RATE> > getRATESFunc, bool IsLocked)
        {
            BASELINE          BASELINE  = getBASELINEFunc();
            PROGRESS          PROGRESS  = getPROGRESSFunc();
            VARIATION         VARIATION = getVARIATIONFunc();
            IQueryable <RATE> RATES     = getRATESFunc();

            IQueryable <VARIATION_ITEM> LoadVARIATION_ITEMS;

            if (VARIATION == null)
            {
                LoadVARIATION_ITEMS = getVARIATION_ITEMSFunc().Where(x => x.GUID_VARIATION == Guid.Empty).ToArray().AsQueryable();
            }
            else
            {
                LoadVARIATION_ITEMS = getVARIATION_ITEMSFunc().ToArray().AsQueryable();
            }

            IQueryable <PROGRESS_ITEM> LoadPROGRESS_ITEMS;

            if (PROGRESS == null)
            {
                LoadPROGRESS_ITEMS = getPROGRESS_ITEMSFunc().Where(x => x.GUID_PROGRESS == Guid.Empty).ToArray().AsQueryable();
            }
            else
            {
                LoadPROGRESS_ITEMS = getPROGRESS_ITEMSFunc().ToArray().AsQueryable();
            }

            IQueryable <PROGRESS_ITEMProjection> BASELINE_ITEMJoinRATESJoinPROGRESS_ITEMS;

            if (PROGRESS == null || VARIATION == null)
            {
                BASELINE_ITEMJoinRATESJoinPROGRESS_ITEMS = PROGRESS_ITEMProjectionQueries.JoinRATESAndPROGRESS_ITEMSOnBASELINE_ITEMS(BASELINE_ITEMS.Where(x => x.GUID == Guid.Empty), getPROGRESSFunc, getBASELINEFunc, getPROGRESS_ITEMSFunc, getRATESFunc, true);
            }
            else
            {
                if (VARIATION.SUBMITTED != null)
                {
                    BASELINE_ITEMJoinRATESJoinPROGRESS_ITEMS = PROGRESS_ITEMProjectionQueries.JoinRATESAndPROGRESS_ITEMSOnBASELINE_ITEMS(BASELINE_ITEMS.Where(x => x.GUID_VARIATION == VARIATION.GUID && x.GUID_BASELINE != null), getPROGRESSFunc, getBASELINEFunc, getPROGRESS_ITEMSFunc, getRATESFunc, true);
                }
                else
                {
                    BASELINE_ITEMJoinRATESJoinPROGRESS_ITEMS = PROGRESS_ITEMProjectionQueries.JoinRATESAndPROGRESS_ITEMSOnBASELINE_ITEMS(BASELINE_ITEMS.Where(x => x.GUID_BASELINE == BASELINE.GUID || (x.GUID_VARIATION == VARIATION.GUID && x.GUID_BASELINE == null)), getPROGRESSFunc, getBASELINEFunc, getPROGRESS_ITEMSFunc, getRATESFunc, true);
                }
            }

            return(BASELINE_ITEMJoinRATESJoinPROGRESS_ITEMS.ToArray().AsQueryable().Select(x => new VARIATION_ITEMProjection()
            {
                GUID = x.GUID,
                VARIATION_ITEM = LoadVARIATION_ITEMS.Where(y => y.GUID_ORIBASEITEM == x.BASELINE_ITEMJoinRATE.BASELINE_ITEM.GUID_ORIGINAL).FirstOrDefault(),
                BASELINE_ITEMJoinRATE = x.BASELINE_ITEMJoinRATE,
                ISLOCKED = IsLocked
            }));
        }
        public static PROJECT_Dashboard SummarizeSinglePROJECTDashboard(PROJECT PROJECT, Func <PROGRESS> getPROGRESSFunc, Func <IQueryable <PROGRESS_ITEM> > getPROGRESS_ITEMSFunc, Func <IQueryable <BASELINE_ITEM> > getBASELINE_ITEMSFunc, Func <BASELINE> getBASELINEFunc, Func <IQueryable <RATE> > getRATESFunc)
        {
            IBluePrintsEntitiesUnitOfWork bluePrintsUnitOfWork = BluePrintsEntitiesUnitOfWorkSource.GetUnitOfWorkFactory().CreateUnitOfWork();
            IP6EntitiesUnitOfWork         p6UnitOfWork         = P6EntitiesUnitOfWorkSource.GetUnitOfWorkFactory().CreateUnitOfWork();

            IEnumerable <ReportableObject> PROJECTInfos = PROGRESS_ITEMProjectionQueries.JoinRATESAndPROGRESS_ITEMSOnBASELINE_ITEMS(
                getBASELINE_ITEMSFunc(), getPROGRESSFunc, getBASELINEFunc, getPROGRESS_ITEMSFunc, getRATESFunc).ToArray().AsEnumerable();

            PROJECT_Dashboard currentPROJECT_Dashboard = new PROJECT_Dashboard()
            {
                GUID = PROJECT.GUID, PROJECT = PROJECT
            };

            currentPROJECT_Dashboard.InitializeBuilder(PROJECTInfos, getPROGRESSFunc(), getBASELINEFunc(), bluePrintsUnitOfWork, p6UnitOfWork);
            BuildProjectStats summaryManufacturer = new BuildProjectStats();

            summaryManufacturer.Manufacture(currentPROJECT_Dashboard.SummaryBuilder);

            return(currentPROJECT_Dashboard);
        }