Example #1
0
        public static async Task <(Ministry, ProgramArea, ScreeningType)> GetMinistryScreeningTypeAsync(
            IDynamicsClient dynamicsClient, string orgCode, string screeningTypeId)
        {
            var getMinistries     = DynamicsUtility.GetMinistriesAsync(dynamicsClient);
            var getProgramAreas   = DynamicsUtility.GetProgramAreasAsync(dynamicsClient, orgCode);
            var getScreeningTypes = DynamicsUtility.GetActiveScreeningTypesAsync(dynamicsClient);

            var screeningType = (await getScreeningTypes).SingleOrDefault(s => s.SpiceServicesid == screeningTypeId);
            var programArea   = (await getProgramAreas).SingleOrDefault(p => p.SpiceMinistryid == screeningType?._spiceMinistryserviceidValue);
            var ministry      = (await getMinistries).SingleOrDefault(m => m.SpiceGovministryid == programArea?._spiceGovministryidValue);

            return(ministry?.ToViewModel(), programArea?.ToViewModel(), screeningType?.ToViewModel());
        }
        public static async Task <IEnumerable <Ministry> > GetMinistryScreeningTypesAsync(IDynamicsClient dynamicsClient)
        {
            var getMinistries     = DynamicsUtility.GetMinistriesAsync(dynamicsClient);
            var getProgramAreas   = DynamicsUtility.GetProgramAreasAsync(dynamicsClient);
            var getScreeningTypes = DynamicsUtility.GetScreeningTypesAsync(dynamicsClient);

            var screeningTypes = (await getScreeningTypes).ToList();
            var programAreas   = (await getProgramAreas).ToList();
            var ministries     = (await getMinistries).ToList();

            foreach (var programArea in programAreas)
            {
                programArea.SpiceSpiceMinistrySpiceServices =
                    screeningTypes.Where(t => t._spiceMinistryserviceidValue == programArea.SpiceMinistryid).ToList();
            }

            foreach (var ministry in ministries)
            {
                ministry.SpiceGovministrySpiceMinistry =
                    programAreas.Where(a => a._spiceGovministryidValue == ministry.SpiceGovministryid).ToList();
            }

            return(ministries.Select(m => m.ToViewModel()));
        }