public async Task <List <AssessmentMetadataEntity> > GetListOfAllAssignedAssessmentsFromServer()
        {
            List <AssessmentEntity> assessmentResponseFromServer = await GetListOfAllAssignedAssessmentsFromServerAPICall();

            List <AssessmentMetadataEntity> metadataEntities = new List <AssessmentMetadataEntity>();

            WeatherService weatherService            = new WeatherService();
            bool           isWeatherServiceAvailable = true;

            foreach (AssessmentEntity entity in assessmentResponseFromServer)
            {
                AssessmentMetadataEntity metadataEntity = JsonConvert.DeserializeObject <AssessmentMetadataEntity>(entity.AssessmentMetadata);

                //create the map url when data is pulled the first time.
                metadataEntity.MapUrl = "http://maps.apple.com/?daddr=" + metadataEntity.OrganizationAddress;
                metadataEntity.LastUpdatedDateFormatted = Convert.ToDateTime(metadataEntity.LastUpdatedDate).TimeAgo();
                metadataEntity.AssessmentCategoriesIcon = GetCategoryIcon(metadataEntity.AssessmentCategories);

                try
                {
                    if (isWeatherServiceAvailable)
                    {
                        //send online.offline param to the method
                        metadataEntity.Weather     = weatherService.GetWeather(metadataEntity.OrganizationCityState);
                        metadataEntity.WeatherIcon = GetWeatherIcon(metadataEntity.Weather);
                    }
                    else
                    {
                        metadataEntity.Weather     = "-";
                        metadataEntity.WeatherIcon = "NoWeather.png";
                    }
                }
                catch
                {
                    isWeatherServiceAvailable  = false;
                    metadataEntity.Weather     = "-";
                    metadataEntity.WeatherIcon = "NoWeather.png";
                }


                string updatedAssessmentMetadata = JsonConvert.SerializeObject(metadataEntity);

                //Store assessments metadata on the device
                StoreAssessmentsOnDevice(updatedAssessmentMetadata, metadataEntity); //entity.AssessmentMetadata, metadataEntity);
                StoreFormsOnDevice(metadataEntity, entity.Forms);
                metadataEntities.Add(metadataEntity);
            }

            return(metadataEntities.OrderByDescending(x => x.LastUpdatedDate).ToList());
        }
Пример #2
0
        public List <AssessmentMetadataEntity> GetListOfAllAssignedAssessmentsFromServer()
        {
            List <AssessmentEntity> assessmentResponseFromServer = GetListOfAllAssignedAssessmentsFromServerAPICall();

            List <AssessmentMetadataEntity> metadataEntities = new List <AssessmentMetadataEntity>();

            WeatherService weatherService            = new WeatherService();
            bool           isWeatherServiceAvailable = true;

            foreach (AssessmentEntity entity in assessmentResponseFromServer)
            {
                AssessmentMetadataEntity metadataEntity = JsonConvert.DeserializeObject <AssessmentMetadataEntity>(entity.AssessmentMetadata);

                //create the map url when data is pulled the first time.
                metadataEntity.MapUrl = "http://maps.apple.com/?daddr=" + metadataEntity.OrganizationAddress;

                try
                {
                    if (isWeatherServiceAvailable)
                    {
                        //send online.offline param to the method
                        metadataEntity.Weather     = weatherService.GetWeather(metadataEntity.OrganizationCityState);
                        metadataEntity.WeatherIcon = GetWeatherIcon(metadataEntity.Weather);
                        //entity.MapUrl = "http://maps.apple.com/?daddr=" + entity.OrganizationAddress; //Some Place&saddr=Some Other Place";
                    }
                    else
                    {
                        metadataEntity.Weather     = "-";
                        metadataEntity.WeatherIcon = "NoWeather.png";
                    }
                }
                catch
                {
                    isWeatherServiceAvailable  = false;
                    metadataEntity.Weather     = "-";
                    metadataEntity.WeatherIcon = "NoWeather.png";
                }


                string updatedAssessmentMetadata = JsonConvert.SerializeObject(metadataEntity);

                //Store assessments metadata on the device
                StoreAssessmentsOnDevice(updatedAssessmentMetadata, metadataEntity); //entity.AssessmentMetadata, metadataEntity);
                StoreFormsOnDevice(metadataEntity, entity.Forms);
                metadataEntities.Add(metadataEntity);
            }

            return(metadataEntities);
        }
Пример #3
0
        public List <AssessmentMetadataEntity> GetListOfAllAssignedAssessmentsFromDevice()
        {
            List <AssessmentMetadataEntity> entities = new List <AssessmentMetadataEntity>();
            WeatherService weatherService            = new WeatherService();

            List <string> assessmentsFromDevice = LoadAssessmentFromDevice();

            //bool isInternetAvailable = true;

            foreach (string assessment in assessmentsFromDevice)
            {
                AssessmentMetadataEntity entity = JsonConvert.DeserializeObject <AssessmentMetadataEntity>(assessment);

                try
                {
                    //if (isInternetAvailable)
                    //{
                    //send online.offline param to the method
                    entity.Weather     = weatherService.GetWeather(entity.OrganizationCityState);
                    entity.WeatherIcon = GetWeatherIcon(entity.Weather);
                    //  isInternetAvailable = true;
                    //}
                    //else
                    //{
                    //    entity.Weather = "-";
                    //    entity.WeatherIcon = "NoWeather.png";
                    //}
                }
                catch
                {
                    //set this to false so it does not keep hitting the server again and again
                    //isInternetAvailable = false;
                    entity.Weather     = "-";
                    entity.WeatherIcon = "NoWeather.png";
                }
                entities.Add(entity);
            }


            return(entities);
        }
        public async Task <List <AssessmentMetadataEntity> > GetListOfAllAssignedAssessmentsFromDevice()
        {
            List <AssessmentMetadataEntity> entities = new List <AssessmentMetadataEntity>();
            WeatherService weatherService            = new WeatherService();

            List <string> assessmentsFromDevice = await LoadAllAssessmentFromDevice();

            //bool isInternetAvailable = true;

            foreach (string assessment in assessmentsFromDevice)
            {
                AssessmentMetadataEntity entity = JsonConvert.DeserializeObject <AssessmentMetadataEntity>(assessment);

                try
                {
                    entity.Weather     = weatherService.GetWeather(entity.OrganizationCityState);
                    entity.WeatherIcon = GetWeatherIcon(entity.Weather);
                    entity.LastUpdatedDateFormatted = Convert.ToDateTime(entity.LastUpdatedDate).TimeAgo();

                    if (entity.AssessmentCategories != null)
                    {
                        entity.AssessmentCategoriesIcon = GetCategoryIcon(entity.AssessmentCategories);
                    }
                }
                catch
                {
                    //set this to false so it does not keep hitting the server again and again
                    //isInternetAvailable = false;
                    entity.Weather     = "-";
                    entity.WeatherIcon = "NoWeather.png";
                }
                entities.Add(entity);
            }


            return(entities.OrderByDescending(x => x.LastUpdatedDate).ToList());
        }