public async Task <Schools> GetData(ISchoolsDataService dataService,
                                            int startIndex,
                                            int maxIndex)
        {
            Schools           schoolList = new Schools();
            List <SchoolItem> schools;
            int index        = 0;
            int indexCounter = 0;
            int schoolCount;

            ErrorString = "";

            try
            {
                schools = await dataService.GetSchoolsAsync();

                MaxListCount = schools.Count;
                if (maxIndex == 0)
                {
                    schoolCount = schools.Count;
                }
                else if (maxIndex > schools.Count)
                {
                    schoolCount = schools.Count;
                }
                else
                {
                    schoolCount = maxIndex;
                }
                schoolList.schools = null;
                if (schools.Count > 0)
                {
                    schoolList.schools = new SchoolItem[schoolCount];
                }

                foreach (SchoolItem school in schools)
                {
                    if (((indexCounter++ >= startIndex) && (index < maxIndex)) || (maxIndex == 0))
                    {
                        SchoolItem newSchool = new SchoolItem
                        {
                            Id     = school.Id,
                            name   = school.name,
                            street = school.street,
                            city   = school.city,
                            state  = school.state,
                            zip    = school.zip
                        };
                        schoolList.schools[index++] = newSchool;
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorString = $"Exception getting our schools database: { ex.Message }";
            }

            return(schoolList);
        }
 public async Task UpdateData(Schools schoolList, ISchoolsDataService dataService)
 {
     ErrorString = "";
     try
     {
         await dataService.Create(schoolList);
     }
     catch (Exception ex)
     {
         ErrorString = $"Exception creating our schools database: { ex.Message }";
     }
 }
        public SchoolModelController(ILogger <SchoolModelController> logger,
                                     IHttpClientFactory clientFactory,
                                     IConfiguration configuration,
                                     SchoolsSqlDataService sqlService,
                                     SchoolEFDataService efService,
                                     SchoolsSimDataService simService)
        {
            _logger        = logger;
            _clientFactory = clientFactory;

            try
            {
                string useSim = configuration.GetValue <string>("UseSIM");
                if (useSim == "1")
                {
                    _dataService = simService;
                }
                else
                {
                    string useEF = configuration.GetValue <string>("UseEF");
                    if (useEF == "1")
                    {
                        _dataService = efService;
                    }
                    else
                    {
                        _dataService = sqlService;
                    }
                }

                string maxPage = configuration.GetValue <string>("MaxPage");
                MaxPage = Convert.ToInt32(maxPage);
            }
            catch (Exception e)
            {
                logger.LogError("Exception loading configuration", e);
            }

            _support = new CommonControllerSupport();
        }