Пример #1
0
        public mProducts GetProductDetails(string ProductId)
        {
            var Product = _MongoContext.mProducts.AsQueryable().Where(a => a.VoyagerProduct_Id == ProductId).FirstOrDefault();

            if (Product == null)
            {
                return(null);
            }
            if (string.IsNullOrEmpty(Product.Lat) || string.IsNullOrEmpty(Product.Long))
            {
                string address = Product.ProdName + "," + Product.CityName + "," + Product.CountryName;
                string type    = new Func <string>(() => { switch (Product.ProductType)
                                                           {
                                                           case "Hotel": return("lodging");

                                                           case "Meal": return("restaurant");

                                                           default: return(null);
                                                           }
                                                   })();

                GeocoderLocation ProductLatLon = GetLocationLatLonByType(address, type).GeocoderLocation;

                Product.Lat      = Convert.ToString(ProductLatLon.Latitude);
                Product.Long     = Convert.ToString(ProductLatLon.Longitude);
                Product.EditDate = DateTime.Now;
                Product.EditUser = "******";

                ReplaceOneResult replaceResult = _MongoContext.mProducts.ReplaceOne(Builders <mProducts> .Filter.Eq("VoyagerProduct_Id", Product.VoyagerProduct_Id), Product);
            }
            return(Product);
        }
Пример #2
0
        private async Task ApplyGeocodingAsync(JOBDC oldObject, JOBDC newObject, HttpRequestMessage request)
        {
            bool applyGeoCoding = false;

            if (oldObject == null)
            {
                applyGeoCoding = true;
                //new geo codding
            }
            if (oldObject != null && oldObject.CompleteAddress != newObject.CompleteAddress)
            {
                applyGeoCoding = true;
            }

            if (applyGeoCoding)
            {
                JOBBL            jobsBL          = new JOBBL();
                string           completeAddress = newObject.CompleteAddress;
                GeocoderLocation geoCode         = null;
                try
                {
                    geoCode = await GMGeocoder.GoeCodeAsync(completeAddress);
                }
                catch (Exception exp)
                {
                    int userID = Common.Utility.GetUserID(Request);
                    Util.Utility.InsertIntoErrorLog(exp.Message, exp.StackTrace, userID);
                }

                if (geoCode != null)
                {
                    newObject.LAT  = geoCode.Latitude.ToString();
                    newObject.LONG = geoCode.Longitude.ToString();
                    if (newObject != null)
                    {
                        List <EXCEPTIONDC> lstException = new List <EXCEPTIONDC>();
                        try
                        {
                            List <JOBDC> jobListToBeUpdated = new List <JOBDC>();
                            jobListToBeUpdated.Add(newObject);
                            if (jobListToBeUpdated.Count > 0)
                            {
                                jobsBL.Update(jobListToBeUpdated, ref lstException, true);
                            }
                        }
                        catch (Exception exp)
                        {
                            new TextResult(lstException, request);
                        }
                    }
                }
            }

            //return "Finished";
        }
Пример #3
0
        public void OpenStreetMap()
        {
            IGeoCoder        g        = new OpenStreetMap();
            GeocoderLocation location = g.Geocode(new PropertyLocation()
            {
                Street       = "Marienplatz",
                StreetNumber = "8",
                City         = "München",
                ZipCode      = "80331"
            });

            Assert.AreEqual(48.137d, location.Latitude, 0.001);
            Assert.AreEqual(11.576d, location.Longitude, 0.001);
        }
Пример #4
0
        public mResort GetCityDetails(string CityId)
        {
            var City = _MongoContext.mResort.AsQueryable().Where(a => a.Voyager_Resort_Id == CityId).FirstOrDefault();

            if (City == null)
            {
                return(null);
            }
            if (string.IsNullOrEmpty(City.Lat) || string.IsNullOrEmpty(City.Lon) || City.Lon == "0.00")
            {
                GeocoderLocation CityLatLon = GetLocationLatLon(City.Lookup).GeocoderLocation;

                City.Lat      = Convert.ToString(CityLatLon.Latitude);
                City.Lon      = Convert.ToString(CityLatLon.Longitude);
                City.EditDate = DateTime.Now;
                City.EditUser = "******";

                ReplaceOneResult replaceResult = _MongoContext.mResort.ReplaceOne(Builders <mResort> .Filter.Eq("Voyager_Resort_Id", City.Voyager_Resort_Id), City);
            }
            return(City);
        }
Пример #5
0
        private async Task ValidateUserModel(UserModel userModel, bool isAdultCheck, bool?termsAndConditions)
        {
            ModelState[nameof(userModel.Id)]?.Errors.Clear();
            ModelState[nameof(userModel.UserId)]?.Errors.Clear();
            ModelState[nameof(userModel.Email)]?.Errors.Clear();

            userModel.Location = GeocoderLocation.GeneratePoint(userModel.LatLng.Split(','));

            /*
             * ModelState[nameof(userModel.Location)]?.Errors.Clear();
             *
             * var pointAddress = userModel.Country + ", " + userModel.State + ", " + userModel.City + ", " + userModel.Address;
             * var address = await GeocoderLocation.GetAddressAsync(pointAddress) as GoogleAddress;
             * userModel.Location = GeocoderLocation.GeneratePoint(address);
             *
             * if (address == null)
             *  ModelState.AddModelError(nameof(userModel.Address), @"Dirección inválida.");
             *
             * if (address != null && address[GoogleAddressType.StreetNumber] == null)
             *  ModelState.AddModelError(nameof(userModel.Address), @"La dirección debe tener altura en la calle.");
             */

            if (termsAndConditions.HasValue && !termsAndConditions.Value)
            {
                ModelState.AddModelError(nameof(termsAndConditions), @"Debe aceptar terminos y condiciones.");
            }

            if (userModel.IsProductUser)
            {
                ModelState[nameof(userModel.ResponsableName)].Errors.Clear();
                ModelState[nameof(userModel.ResponsableLastName)].Errors.Clear();
                ModelState[nameof(userModel.ResponsableDni)].Errors.Clear();
                if (userModel.Birth >= DateTime.UtcNow.AddYears(-18))
                {
                    ModelState.AddModelError(nameof(userModel.Birth), @"Debe ser mayor de 18 años.");
                }
                return;
            }

            if (!isAdultCheck)
            {
                ModelState.AddModelError("BirthDeclaration", @"Debe ser mayor de 18 años.");
            }

            //if (userModel.Birth >= DateTime.UtcNow.AddYears(-4))
            //    ModelState.AddModelError(nameof(userModel.Birth), @"El usuario de la prótesis debe ser mayor de 4 años.");

            if (string.IsNullOrWhiteSpace(userModel.ResponsableName))
            {
                ModelState.AddModelError(nameof(userModel.ResponsableName), @" ");
            }

            if (string.IsNullOrWhiteSpace(userModel.ResponsableLastName))
            {
                ModelState.AddModelError(nameof(userModel.ResponsableLastName), @" ");
            }

            if (string.IsNullOrWhiteSpace(userModel.ResponsableDni))
            {
                ModelState.AddModelError(nameof(userModel.ResponsableDni), @" ");
            }
        }
Пример #6
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);
            }
        }