コード例 #1
0
        public ActionResult LocationToSearch(string address)
        {
            if (!string.IsNullOrEmpty(address))
            {
                GLatLong loc = new GLatLong();
                //    loc = GeoCodingHelper.GetLatLong(address);//uncomment this

                loc.Latitude  = 41.330215;  //comment this
                loc.Longitude = -73.859004; //comment this

                Session["UserLocLat"]  = loc.Latitude;
                Session["UserLocLong"] = loc.Longitude;
                Session["UserLoc"]     = address;



                LocationsSearched ls = new LocationsSearched();
                ls.Location    = address;
                ls.Latitude    = Convert.ToDecimal(loc.Latitude);
                ls.Longitude   = Convert.ToDecimal(loc.Longitude);
                ls.DateCreated = DateTime.Now;
                ls.UserID      = WebSecurity.CurrentUserId;
                dbmeals.LocationsSearcheds.Add(ls);
                dbmeals.SaveChanges();


                SearchParam searchparam = new SearchParam();
                return(RedirectToAction("Index", "Home", new RouteValueDictionary(searchparam)));
            }

            return(View());
        }
コード例 #2
0
        public GLatLong GetLatLong(string latlongstring)
        {
            GLatLong latlong = new GLatLong();

            string[] nums = latlongstring.Split(",".ToCharArray()).ToArray();
            latlong.Latitude  = Convert.ToDouble(nums[0]);
            latlong.Longitude = Convert.ToDouble(nums[1]);

            return(latlong);
        }
コード例 #3
0
        public static string GetAddress(GLatLong latlong)
        {
            WebRequest request = WebRequest
                                 .Create("http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address=" + latlong);

            using (WebResponse response = request.GetResponse())
            {
                using (Stream stream = response.GetResponseStream())
                {
                    XDocument document = XDocument.Load(new StreamReader(stream));

                    string address = document.Descendants("formatted_address").FirstOrDefault().ToString();
                    return(address);
                }
            }
        }
コード例 #4
0
        public GLatLong GetLatLng(string address)
        {
            //IGeoCoder geoCoder = new GoogleGeoCoder("my-api-key");
            //Address[] addresses = geoCoder.GeoCode("123 Main St");

            //IGeoCoder geoCoder = new YahooGeoCoder("my-app-ID");
            // addresses = geoCoder.GeoCode(38.8976777, -77.036517);

            GLatLong loc = new GLatLong();
            var      c   = GeoCodingHelper.GetLatLong(address);

            if (c != null)
            {
                loc.Latitude  = c.Latitude;
                loc.Longitude = c.Longitude;
            }
            return(loc);
        }
コード例 #5
0
        private GLatLong GetUserLocation(int UserId)
        {
            var      userdetails = dbmeals.UserDetails.FirstOrDefault(u => u.UserId == UserId);
            GLatLong userloc     = new GLatLong();

            if (userdetails != null)
            {
                userloc.Latitude  = Convert.ToDouble(userdetails.AddressList.Latitude);
                userloc.Longitude = Convert.ToDouble(userdetails.AddressList.Longitude);

                return(userloc);
            }

            else
            {
                return(null);
            }
        }
コード例 #6
0
        public ActionResult LocateAddress(string address)
        {
            //address = "1 whitehall street new york ny 10004";

            //IGeoCoder geoCoder = new GoogleGeoCoder("my-api-key");
            //Address[] addresses = geoCoder.GeoCode("123 Main St");

            //IGeoCoder geoCoder = new YahooGeoCoder("my-app-ID");
            // addresses = geoCoder.GeoCode(38.8976777, -77.036517);

            GLatLong loc = new GLatLong();
            var      c   = GeoCodingHelper.GetLatLong(address);

            loc.Latitude  = c.Latitude;
            loc.Longitude = c.Longitude;

            string revgeocode = "";

            var g = GeoCodingHelper.GetAddress(loc);

            revgeocode = g.ToString();

            return(View(loc));
        }
コード例 #7
0
        public ActionResult Index(SearchParam parameters)
        {
            if (TempData["ErrorMessage"] != null)
            {
                ViewBag.ErrorMessage = TempData["ErrorMessage"];
            }
            else
            {
                ViewBag.ErrorMessage = "";
            }
            var ChangeLocation = HttpContext.Request.QueryString["ChangeLocation"];

            if ((ChangeLocation != null) && (ChangeLocation != ""))
            {
                GLatLong loc = new GLatLong();
                loc = GeoCodingHelper.GetLatLong(ChangeLocation.ToString());


                if (loc != null)
                {
                    Session["UserLocLat"]  = loc.Latitude;
                    Session["UserLocLong"] = loc.Longitude;
                }
                Session["UserLoc"] = ChangeLocation;
            }
            else
            {
                var LocationsSearched = dbmeals.LocationsSearcheds.Where(x => x.UserID == WebSecurity.CurrentUserId).OrderByDescending(x => x.DateCreated).ToList().FirstOrDefault();
                if (LocationsSearched != null)
                {
                    Session["UserLoc"]          = LocationsSearched.Location;
                    parameters.FreeSearch       = LocationsSearched.Keywords;
                    Session["UserLocLat"]       = LocationsSearched.Latitude;
                    Session["UserLocLong"]      = LocationsSearched.Longitude;
                    parameters.DistanceSearch   = LocationsSearched.Distance.HasValue ? LocationsSearched.Distance.Value.ToString() : string.Empty;
                    parameters.PickUpDateSearch = Common.AbsoluteEnd(LocationsSearched.DateRangeStart.HasValue ? LocationsSearched.DateRangeStart.Value : DateTime.Now);// LocationsSearched.DateRangeStart;
                    //parameters.DateRangeEnd = LocationsSearched.DateRangeEnd;
                }
            }


            if (String.IsNullOrEmpty(parameters.DistanceSearch))
            {
                parameters.DistanceSearch = "100";
            }

            if (parameters.PickUpDateSearch == null)
            {
                parameters.PickUpDateSearch = DateTime.Now;
            }



            string pointofreference = Session["UserLocLat"] + "," + Session["UserLocLong"];

            LocationsSearched ls = new LocationsSearched();

            ls.Location       = Convert.ToString(Session["UserLoc"]);//.ToString();
            ls.Keywords       = parameters.FreeSearch;
            ls.Latitude       = Convert.ToDecimal(Session["UserLocLat"]);
            ls.Longitude      = Convert.ToDecimal(Session["UserLocLong"]);
            ls.DateRangeStart = Common.AbsoluteStart(parameters.PickUpDateSearch);
            ls.DateRangeEnd   = Common.AbsoluteEnd(parameters.PickUpDateSearch);
            ls.Distance       = Convert.ToInt32(parameters.DistanceSearch);
            ls.DistanceUnit   = "km";
            ls.DateCreated    = DateTime.Now;
            ls.UserID         = WebSecurity.CurrentUserId;
            try
            {
                dbmeals.LocationsSearcheds.Add(ls);
                dbmeals.SaveChanges();
            }
            catch (Exception e)
            {
                string message = e.Message;
            }
            try
            {
                ICollection <ISolrFacetQuery> list =
                    AllFacetFields.Except(SelectedFacetFields(parameters)).
                    Select(f => new SolrFacetFieldQuery(f)
                {
                    MinCount = 1
                })
                    .Cast <ISolrFacetQuery>().ToList();



                var start = (parameters.PageIndex - 1) * parameters.PageSize;

                var matchingProducts = solr.Query(BuildQuery(parameters), new QueryOptions
                {
                    FilterQueries = BuildFilterQueries(parameters),
                    Rows          = parameters.PageSize,
                    Start         = start,
                    OrderBy       = GetSelectedSort(parameters),
                    SpellCheck    = new SpellCheckingParameters(),
                    Facet         = new FacetParameters
                    {
                        Queries = list
                    },


                    ExtraParams = new Dictionary <string, string>
                    {
                        // uncomment for filtering by distance
                        { "fq", "{!geofilt}" },
                        { "d", parameters.DistanceSearch },         // distance.ToString(CultureInfo.InvariantCulture)} replace distance with your radius filter
                        { "sfield", "latlng" },                     // replace lat_long with your field in solr that stores the lat long values
                        { "pt", pointofreference },                 // this is the point of reference
                        // {"sort","geodist() asc"},
                        { "fl", "*,Distance:geodist()" },
                    }
                });

                var distancemodel = new DistanceViewModel();


                // var matchingProducts

                var ProductModel = new ProductView
                {
                    WholeSet   = matchingProducts,
                    Search     = parameters,
                    TotalCount = matchingProducts.NumFound,
                    Facets     = matchingProducts.FacetFields,
                    //  PickUpTimeFacet = GetPickUpTimeFacet(matchingProducts.FacetQueries),
                    // DistanceFacet = GetDistanceFacet(matchingProducts.FacetQueries),
                    DidYouMean = GetSpellCheckingResult(matchingProducts),
                    //DistanceLimitList.SelectedDistance = parameters.DistanceLimit
                };


                // Preselect the option with Value = "US"
                // Make sure you have such option in the Countries list


                List <SolrResultSet> SolrResultSetList = new List <SolrResultSet>();
                SolrResultSetList = (from n in ProductModel.WholeSet
                                     select n).ToList();

                var ProductViewModel = new ResultSetViewModel();
                ProductViewModel.Search       = ProductModel.Search;
                ProductViewModel.TotalCount   = ProductModel.TotalCount;
                ProductViewModel.Facets       = ProductModel.Facets;
                ProductViewModel.DidYouMean   = ProductModel.DidYouMean;
                ProductViewModel.ProviderList = (from n in SolrResultSetList
                                                 group n by new
                {
                    n.ProviderName,
                    n.ProviderType
                    ,
                    n.Distance,
                    n.latlng,
                    n.PhoneNumber,
                    n.FullAddress,
                    n.Cuisine
                } into g
                                                 select new Provider()
                {
                    ProviderName = g.Key.ProviderName,
                    ProviderType = g.Key.ProviderType,
                    Distance = g.Key.Distance,
                    latlng = g.Key.latlng,
                    PhoneNumber = g.Key.PhoneNumber,
                    FullAddress = g.Key.FullAddress,
                    Cuisine = g.Key.Cuisine,
                }).ToList();

                foreach (Provider p in ProductViewModel.ProviderList)
                {
                    p.Products = (from n in SolrResultSetList
                                  where n.ProviderName == p.ProviderName
                                  select new Product()

                    {
                        MealAdID = n.MealAdID,
                        MealItemName = n.MealItemName,
                        FoodType = n.FoodType,
                        MealType = n.MealType,
                        Price = n.Price,
                        Ingredients = n.Ingredients,
                        AllergenicIngredients = n.AllergenicIngredients,
                        Timestamp = n.Timestamp,
                        Description = n.Description
                    }).ToList();
                }


                distancemodel.SelectedDistanceLimit = parameters.DistanceSearch;
                ProductViewModel.DistanceDD         = distancemodel;

                return(View(ProductViewModel));
            }
            catch (SolrConnectionException e)
            {
                string msg = e.Message;
                return(View(new ResultSetViewModel
                {
                    QueryError = true,
                }));
            }
        }
コード例 #8
0
        public RedirectToRouteResult RedirectPage(int userid)
        {
            string ipaddress = Request.ServerVariables["REMOTE_ADDR"];

            ipaddress = ipaddress == null ? String.Empty : ipaddress;
            ipaddress = ipaddress.Replace("\r\n", ",");
            ipaddress = ipaddress.Replace(" ", ",");
            ipaddress = ipaddress.Replace(":", "");
            string[] arripaddress = ipaddress.Split(',');
            string   location     = string.Empty;
            string   address      = String.Empty;

            if (arripaddress.Length != 0)
            {
                for (int i = 0; i <= arripaddress.Length - 1; i++)
                {
                    if (arripaddress[i] != "")
                    {
                        // check if the IP address is supported in demo version
                        long ipno = IP2Decimal(arripaddress[i]);
                        if ((ipno > 0) || (ipno < 33554431))
                        {
                            SqlDataReader reader;
                            // select MS-SQL database using DSNless connection
                            SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
                            // query string to lookup the country by matching the range of IP address number
                            SqlCommand sqlCmd = new SqlCommand("SELECT TOP 1 * FROM ip2location_db3_ipv6 WHERE " + ipno.ToString() + " <= ip_to ORDER BY ip_to", sqlConn);
                            sqlCmd.Connection.Open();
                            // execute the query
                            reader = sqlCmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
                            // display results
                            if (reader.Read())
                            {
                                location = Convert.ToString(reader["city_name"]);
                                address  = Convert.ToString(reader["city_name"]) + "," + Convert.ToString(reader["region_name"]) + "," + Convert.ToString(reader["country_name"]);

                                //Response.Write("<tr>");
                                //Response.Write("<td align=center>" + arripaddress[i] + "</td>");
                                //Response.Write("<td align=center>" + reader.GetString(0) + "</td>");
                                //Response.Write("<td align=center>" + reader.GetString(1) + "</td>");
                                //Response.Write("</tr>");
                            }
                            sqlCmd.Connection.Close();
                        }
                    }
                }
            }
            var user = db.UserProfiles.Where(x => x.UserId.Equals(userid)).First();

            Session["FirstName"] = user.FirstName;
            LocationsSearched ls = new LocationsSearched();

            ls = dbmeals.LocationsSearcheds.Where(x => x.UserID.Equals(userid)).OrderByDescending(y => y.DateCreated).FirstOrDefault();
            if (ls != null)
            {
                Session["UserLoc"]     = ls.Location;
                Session["UserLocLat"]  = Convert.ToDouble(ls.Latitude);
                Session["UserLocLong"] = Convert.ToDouble(ls.Longitude);
            }
            else
            {
                if (!string.IsNullOrEmpty(location))
                {
                    Session["UserLoc"] = location;

                    GLatLong latlng = GetLatLng(address);
                    Session["UserLocLat"]  = (decimal)latlng.Latitude;
                    Session["UserLocLong"] = (decimal)latlng.Longitude;
                }
                else
                {
                    return(RedirectToAction("LocationToSearch", "Home", null));
                }
            }

            if (Session["UserLoc"] == null)
            {
                UserDetail userdetail = new UserDetail();
                userdetail = dbmeals.UserDetails.Where(x => x.UserId.Equals(userid)).FirstOrDefault();
                if (userdetail != null)
                {
                    Session["UserLoc"]     = Common.GetFullAddress(userdetail.AddressList);
                    Session["UserLocLat"]  = Convert.ToDouble(userdetail.AddressList.Latitude);
                    Session["UserLocLong"] = Convert.ToDouble(userdetail.AddressList.Longitude);
                }
                else
                {
                    Session["UserLoc"] = null;
                }

                if (Session["UserLocLat"] == null)
                {
                    return(RedirectToAction("LocationToSearch", "Home", null));
                }
            }
            SearchParam searchparam = new SearchParam();

            return(RedirectToAction("Index", "Home", new RouteValueDictionary(searchparam)));
        }
コード例 #9
0
        public RedirectToRouteResult RedirectPage(int userid)
        {
            bool userinvited = dbmeals.ContactLists.Any(x => x.RecipientUserID == userid);

            if (userinvited)
            {
                return(RedirectToAction("Index", "Contact", new { userid = userid }));
            }
            string ipaddress = Request.ServerVariables["REMOTE_ADDR"];

            ipaddress = ipaddress == null ? String.Empty : ipaddress;
            ipaddress = ipaddress.Replace("\r\n", ",");
            ipaddress = ipaddress.Replace(" ", ",");
            ipaddress = ipaddress.Replace(":", "");
            string[] arripaddress = ipaddress.Split(',');
            string   location     = string.Empty;
            string   address      = String.Empty;

            if (arripaddress.Length != 0)
            {
                for (int i = 0; i <= arripaddress.Length - 1; i++)
                {
                    if (arripaddress[i] != "")
                    {
                        long ipno = Common.IP2Decimal(arripaddress[i]);
                        if ((ipno > 0) || (ipno < 33554431))
                        {
                            SqlDataReader reader;
                            SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
                            SqlCommand    sqlCmd  = new SqlCommand("SELECT TOP 1 * FROM ip2location_db3_ipv6 WHERE " + ipno.ToString() + " <= ip_to ORDER BY ip_to", sqlConn);
                            sqlCmd.Connection.Open();
                            reader = sqlCmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
                            if (reader.Read())
                            {
                                location = Convert.ToString(reader["city_name"]);
                                address  = Convert.ToString(reader["city_name"]) + "," + Convert.ToString(reader["region_name"]) + "," + Convert.ToString(reader["country_name"]);
                            }
                            sqlCmd.Connection.Close();
                        }
                    }
                }
            }
            var user = db.UserProfiles.Where(x => x.UserId.Equals(userid)).First();

            Session["FirstName"] = user.FirstName;
            LocationsSearched ls = new LocationsSearched();

            ls = dbmeals.LocationsSearcheds.Where(x => x.UserID.Equals(userid)).OrderByDescending(y => y.DateCreated).FirstOrDefault();
            if (ls != null)
            {
                Session["UserLoc"]     = ls.Location;
                Session["UserLocLat"]  = Convert.ToDouble(ls.Latitude);
                Session["UserLocLong"] = Convert.ToDouble(ls.Longitude);
            }
            else
            {
                if (!string.IsNullOrEmpty(location))
                {
                    Session["UserLoc"] = location;

                    GLatLong latlng = Common.GetLatLng(address);
                    Session["UserLocLat"]  = (decimal)latlng.Latitude;
                    Session["UserLocLong"] = (decimal)latlng.Longitude;
                }
                else
                {
                    return(RedirectToAction("LocationToSearch", "Home", null));
                }
            }

            if (Session["UserLoc"] == null)
            {
                UserDetail userdetail = new UserDetail();
                userdetail = dbmeals.UserDetails.Where(x => x.UserId.Equals(userid)).FirstOrDefault();
                if (userdetail != null)
                {
                    Session["UserLoc"]     = Common.GetFullAddress(userdetail.AddressList);
                    Session["UserLocLat"]  = Convert.ToDouble(userdetail.AddressList.Latitude);
                    Session["UserLocLong"] = Convert.ToDouble(userdetail.AddressList.Longitude);
                }
                else
                {
                    Session["UserLoc"] = null;
                }

                if (Session["UserLocLat"] == null)
                {
                    return(RedirectToAction("LocationToSearch", "Home", null));
                }
            }
            SearchParam searchparam = new SearchParam();

            return(RedirectToAction("Index", "Home", new RouteValueDictionary(searchparam)));
        }
コード例 #10
0
        public ActionResult Create(UserDetailViewModel userinfovm, HttpPostedFileBase Photo)
        {
            if (!userinfovm.CheckIfSeller)
            {
                ModelState.Remove("KitchenName");
            }
            if (ModelState.IsValid)
            {
                var fileName = "";

                // Verify that the user selected a file
                if (Photo != null && Photo.ContentLength > 0)
                {
                    // extract only the fielname
                    fileName = "Profilephoto" + userinfovm.UserId + Path.GetExtension(Photo.FileName);
                    //   .GetFileName(Photo.FileName).;
                    // store the file inside ~/App_Data/uploads folder
                    var path = Path.Combine(Server.MapPath("~/ProfilePhotos"), fileName);
                    Photo.SaveAs(path);
                    try
                    {
                        System.Drawing.Image.FromFile(fileName);
                    }
                    catch (Exception e1)
                    {
                        ModelState.AddModelError("", "Please upload Image only. " + e1.Message.ToString());
                    }
                    userinfovm.Photo = fileName;
                }
                try
                {
                    string Country = dbmeals.LKUPCountries.Where(x => x.CountryID == userinfovm.Address.CountryID).First().Country;
                    string address = userinfovm.Address.Address1 + "," + userinfovm.Address.Telephone + "," + userinfovm.Address.Address2 + "," + userinfovm.Address.City + "," + userinfovm.Address.Province + "," + userinfovm.Address.Zip + "," + Country;

                    GLatLong latlng = GetLatLng(address);
                    userinfovm.Address.Latitude  = (decimal)latlng.Latitude;
                    userinfovm.Address.Longitude = (decimal)latlng.Longitude;
                    // userinfo.AddressList.DateCreated = DateTime.Now;


                    AddressList addr = Mapper.Map <AddressViewModel, AddressList>(userinfovm.Address);
                    addr.UserId      = userinfovm.UserId;
                    addr.DateCreated = DateTime.Now;
                    addr.Telephone   = userinfovm.Address.Telephone;
                    dbmeals.AddressLists.Add(addr);
                    dbmeals.SaveChanges();


                    UserDetail userinfo = Mapper.Map <UserDetailViewModel, UserDetail>(userinfovm);

                    userinfo.KitchenName = userinfovm.KitchenName;

                    int last_insert_id = addr.AddressID;
                    userinfo.AddressID   = last_insert_id;
                    userinfo.DateCreated = DateTime.Now;

                    dbmeals.UserDetails.Add(userinfo);
                    dbmeals.SaveChanges();
                }
                catch (DbEntityValidationException dbmealsEx)
                {
                    foreach (var validationErrors in dbmealsEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }
                // redirect back to the index action to show the form once again

                //  return RedirectToAction("InviteYourConnections", "User", new { userid = userinfovm.UserId });
                return(RedirectToAction("Details", "User", new { userid = userinfovm.UserId }));
            }
            else
            {
                userinfovm.CountryDDList = dbmeals.LKUPCountries.ToList().Select(x => new SelectListItem
                {
                    Value = x.CountryID.ToString(),
                    Text  = x.Country.ToString()
                });



                return(View(userinfovm));
            }
            //return View(userinfovm);
        }
コード例 #11
0
        public GLatLong GetLatLong(string latlongstring)
        {
            GLatLong latlong = new GLatLong();
            string[] nums = latlongstring.Split(",".ToCharArray()).ToArray();
            latlong.Latitude = Convert.ToDouble(nums[0]);
            latlong.Longitude = Convert.ToDouble(nums[1]);

            return latlong;
        }