示例#1
0
        public IHttpActionResult GetAllJobsWithInvalidLatLongs()
        {
            JOBBL        objUser       = new JOBBL();
            List <JOBDC> objResultList = new List <JOBDC>();

            objResultList = objUser.GetAllJobsWithInvalidLatLongs();
            return(Ok(new { objResultList }));
        }
示例#2
0
        public async Task ApplyGeocodingAsync()
        {
            JOBBL        jobsBL             = new JOBBL();
            List <JOBDC> jobListToBeUpdated = new List <JOBDC>();

            try
            {
                GeocoderLocation geoCode = null;
                int requestLimit         = 2500;
                int requestCount         = 0;

                List <JOBDC> jobList_InvalidLatLong = jobsBL.GetAllJobsWithInvalidLatLongs();
                if (jobList_InvalidLatLong != null && jobList_InvalidLatLong.Count > 0)
                {
                    try
                    {
                        foreach (var jobObj in jobList_InvalidLatLong)
                        {
                            if (requestCount > requestLimit)
                            {
                                break;
                            }
                            // Perform GeoCoding if Either Latitude or Longitude is missing
                            string completeAddress = jobObj.CompleteAddress;
                            // Do not Perform GeoCoding if Address Information is completely missing to minimize limit-violation of Google Maps API
                            if (!String.IsNullOrEmpty(completeAddress))
                            {
                                geoCode = await GMGeocoder.GoeCodeAsync(completeAddress);

                                if (geoCode != null)
                                {
                                    jobObj.LAT  = geoCode.Latitude.ToString();
                                    jobObj.LONG = geoCode.Longitude.ToString();
                                    if (jobObj != null)
                                    {
                                        jobListToBeUpdated.Add(jobObj);
                                    }
                                }
                                requestCount++;
                                await Task.Delay(300);
                            }
                        }
                    }
                    catch (Exception exp)
                    {
                        Util.Utility.InsertIntoErrorLog(exp.Message, exp.StackTrace, Constants.AdminUserID);
                    }
                }
            }
            catch (Exception exp)
            {
                Util.Utility.InsertIntoErrorLog(exp.Message, exp.StackTrace, Constants.AdminUserID);
            }

            //update the address
            List <EXCEPTIONDC> lstException = new List <EXCEPTIONDC>();

            try
            {
                if (jobListToBeUpdated.Count > 0)
                {
                    jobsBL.UpdateJobLatLong(jobListToBeUpdated, true);
                }
            }
            catch (Exception exp)
            {
                Util.Utility.InsertIntoErrorLog(exp.Message, exp.StackTrace, Constants.AdminUserID);
            }
        }