Ejemplo n.º 1
0
        // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

        public LatLngDomain AddressGetLatLng(string address)
        {
            // string address = model.Address1 + ", " + model.City + ",  " + model.State + ", " + model.ZipCode;

            LatLngDomain result = null;

            string requestUri = string.Format("http://maps.googleapis.com/maps/api/geocode/xml?address={0}&sensor=false", Uri.EscapeDataString(address));

            WebRequest  request  = WebRequest.Create(requestUri);
            WebResponse response = request.GetResponse();
            XDocument   xdoc     = XDocument.Load(response.GetResponseStream());

            XElement resultElem      = xdoc.Element("GeocodeResponse").Element("result");
            XElement locationElement = resultElem.Element("geometry").Element("location");
            XElement lat             = locationElement.Element("lat");
            XElement lng             = locationElement.Element("lng");

            if (lat != null && lng != null)
            {
                Decimal latitude = Decimal.Parse(lat.Value);

                Decimal longitude = Decimal.Parse(lng.Value);
                result = new LatLngDomain
                {
                    Latitude  = latitude,
                    Longitude = longitude
                };
            }
            return(result);
        }
Ejemplo n.º 2
0
        // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

        public int InsertAddress(AddressRequiredRequest model)
        {
            int Id = 0;

            string addressString = String.Concat(model.Address1, ", ", model.City, ",  "
                                                 , model.State, ", ", model.ZipCode);

            LatLngDomain latlng = AddressGetLatLng(addressString);

            model.Latitude  = latlng.Latitude;
            model.Longitude = latlng.Longitude;

            try
            {
                DataProvider.ExecuteNonQuery(GetConnection, "dbo.Address_Insert"
                                             , inputParamMapper : delegate(SqlParameterCollection paramCollection)
                {
                    paramCollection.AddWithValue("@CompanyId", model.CompanyId);
                    paramCollection.AddWithValue("@Date", DateTime.Now);
                    paramCollection.AddWithValue("@Address1", model.Address1);
                    paramCollection.AddWithValue("@City", model.City);
                    paramCollection.AddWithValue("@State", model.State);
                    paramCollection.AddWithValue("@ZipCode", model.ZipCode);
                    paramCollection.AddWithValue("@Latitude", model.Latitude);
                    paramCollection.AddWithValue("@Longitude", model.Longitude);
                    paramCollection.AddWithValue("@Slug", model.Slug);
                    paramCollection.AddWithValue("@AddressType", model.AddressType);

                    var p       = new SqlParameter("@id", System.Data.SqlDbType.Int);
                    p.Direction = System.Data.ParameterDirection.Output;

                    paramCollection.Add(p);
                }, returnParameters : delegate(SqlParameterCollection param)
                {
                    int.TryParse(param["@Id"].Value.ToString(), out Id);
                });
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(Id);
        }
Ejemplo n.º 3
0
        // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

        public bool UpdateAddress(AddressUpdateRequest model)
        {
            bool success = false;

            string addressString = String.Concat(model.Address1, ", ", model.City, ",  "
                                                 , model.State, ", ", model.ZipCode);

            LatLngDomain latlng = AddressGetLatLng(addressString);

            model.Latitude  = latlng.Latitude;
            model.Longitude = latlng.Longitude;


            try
            {
                DataProvider.ExecuteNonQuery(GetConnection, "dbo.Address_Update"
                                             , inputParamMapper : delegate(SqlParameterCollection paramCollection)
                {
                    paramCollection.AddWithValue("@CompanyId", model.CompanyId);
                    paramCollection.AddWithValue("@Date", model.Date);
                    paramCollection.AddWithValue("@Address1", model.Address1);
                    paramCollection.AddWithValue("@City", model.City);
                    paramCollection.AddWithValue("@State", model.State);
                    paramCollection.AddWithValue("@ZipCode", model.ZipCode);
                    paramCollection.AddWithValue("@Latitude", model.Latitude);
                    paramCollection.AddWithValue("@Longitude", model.Longitude);
                    paramCollection.AddWithValue("@Slug", model.Slug);
                    paramCollection.AddWithValue("@AddressType", model.AddressType);
                    paramCollection.AddWithValue("@Id", model.AddressId);

                    success = true;
                });
            }
            catch (System.Exception ex)
            {
                throw ex;
            }

            return(success);
        }