コード例 #1
0
        public ActionResult Default()
        {
            #region PreviousCoding
            Repository repoObj = new Repository();
            Member memberData = (Member)SessionStore.GetSessionValue(SessionStore.Memberobject);
            if (memberData != null)
            {
                //ViewData["LocationData"] = locations;
                //ViewData["Memberlocation"] = memberLocation;
            }
            else
            {
                string logoutString = TempData["Logout"] as string;
                if (logoutString != "Logout")
                {
                    const string myFacebookApiKey = "101151816623334";
                    const string myFacebookSecret = "65f49046dce2d1f54d6991e43c4af675";

                    var connectSession = new ConnectSession(myFacebookApiKey, myFacebookSecret);
                    if (connectSession.IsConnected())
                    {
                        ViewData["FBConnected"] = true;
                        var api = new Api(connectSession);
                        ViewData["FBUser"] = api.Users.GetInfo();
                        ViewData["UserID"] = api.Users.GetInfo().uid;
                        SessionStore.SetSessionValue(SessionStore.FacebookConnect, "FacebookUserLoggedIn");
                        string[] fbDetails = new string[2];
                        fbDetails[0] = Convert.ToString("fb_" + api.Users.GetInfo().uid);
                        fbDetails[1] = api.Users.GetInfo().name;
                        SessionStore.SetSessionValue("FacebookDetails", fbDetails);
                        api.Session.Logout();
                        connectSession.Logout();
                        return RedirectToAction("FBUser", "Member");
                    }
                }
            }
            #endregion

            GetTopPlanters();

            CommonMethods objCmnMethods = new CommonMethods();

            string strIpAddress = System.Web.HttpContext.Current.Request.UserHostAddress;
            if (strIpAddress == "127.0.0.1")
                strIpAddress = "61.246.241.162";

            string citySearch = string.Empty;
            string stateSearch = string.Empty;
            string zipCodeSearch = string.Empty;
            string latSearch = string.Empty;
            string lngSearch = string.Empty;
            string[] currentAddress;

            string ipLocation = objCmnMethods.MaxMindIPData(strIpAddress);
            if (!string.IsNullOrEmpty(ipLocation) && (!ipLocation.Contains("IP_NOT_FOUND")))
            {
                //IPaddressAPI
                currentAddress = ipLocation.Split(',');

                if (string.IsNullOrEmpty(currentAddress[1].Replace("\"", "").ToString()))
                    stateSearch = "AZ";
                else
                {
                    stateSearch = currentAddress[1].Replace("\"", "").ToString();
                    //stateSearch = "WA";
                }

                if (string.IsNullOrEmpty(currentAddress[2].ToString()))
                    citySearch = "Phoenix";
                else
                {
                    citySearch = currentAddress[2].Replace("\"", "").ToString();
                    //citySearch = "Seattle";
                }

                if (string.IsNullOrEmpty(currentAddress[3].Replace("\"", "").ToString()))
                {
                    //zipCodeSearch = "85027";
                    SeedAction objS = new SeedAction();
                    LocationAction objLocation = new LocationAction();
                    string cityId = objLocation.GetCityIdByCityName(citySearch, stateSearch);
                    zipCodeSearch = objS.GetZipOfSeedByCityId(cityId);
                }
                else
                    zipCodeSearch = currentAddress[3].Replace("\"", "").ToString();

                latSearch = currentAddress[4].Replace("\"", "").ToString();
                lngSearch = currentAddress[5].Replace("\"", "").ToString();
            }
            else
            {
                //MaxMind
                ipLocation = objCmnMethods.IP2AddressMaxMind();
                currentAddress = ipLocation.Split('\'');

                if (string.IsNullOrEmpty(currentAddress[7].ToString()))
                    stateSearch = "AZ";
                else
                    stateSearch = currentAddress[7].ToString();

                if (string.IsNullOrEmpty(currentAddress[5].ToString()))
                    citySearch = "Phoenix";
                else
                    citySearch = currentAddress[5].ToString();

                if (string.IsNullOrEmpty(currentAddress[15].ToString()))
                    zipCodeSearch = "85027";
                else
                    zipCodeSearch = currentAddress[15].ToString();

                latSearch = currentAddress[11].ToString();
                lngSearch = currentAddress[13].ToString();
            }

            ViewData["LocLat"] = latSearch;
            ViewData["LocLng"] = lngSearch;
            Session["LocLatLng"] = latSearch + "," + lngSearch;

            SeedAction objSeed = new SeedAction();
            IList<Seed> lstSeed = getHomeSearchResult(citySearch, "", "", zipCodeSearch, "");
            if (lstSeed.Count > 0)
            {
                ViewData["SeedList"] = lstSeed.OrderByDescending(x => x.createDate).ToList();
                ViewData["userLocation"] = "Your Location : " + citySearch + ", " + stateSearch;
                ViewData["CatLocation"] = citySearch + ", " + stateSearch;
            }
            else
            {
                lstSeed = repoObj.List<Seed>().Where(x => x.status.Equals(SystemStatements.STATUS_NEW) || x.status.Equals(SystemStatements.STATUS_GROWING)).OrderByDescending(x => x.createDate).Take(20).ToList();
                ViewData["SeedList"] = lstSeed;
                ViewData["userLocation"] = "Your Location : " + citySearch + ", " + stateSearch;
                ViewData["CatLocation"] = citySearch + ", " + stateSearch;
                ViewData["CitySearchMsg"] = "<span>Sorry, no seeds planted in '" + citySearch + "' area. Showing latest additions.</span>";
                string streamFeed = "Select top 20 * from Seed order by createDate desc";
                SessionStore.SetSessionValue(SessionStore.DefaultFeed, streamFeed);
            }

            string advSearch = TempData["DiscoverSeed"] as string;
            if (advSearch != "AdvanceSearch")
            {
                if (lstSeed.Count > 0)
                    SessionStore.SetSessionValue(SessionStore.DiscoverSeed, lstSeed);
            }

            if (SessionStore.GetSessionValue(SessionStore.DiscoverSeed) != null)
                lstSeed = (IList<Seed>)SessionStore.GetSessionValue(SessionStore.DiscoverSeed);

            int rowCount = lstSeed.Count;
            Session["RowCount"] = rowCount;
            Session["PageCount"] = "1";
            ViewData["SeedList"] = lstSeed.Take(10).ToList();
            ViewData["PrevVisibility"] = "visibility:hidden;";
            if (lstSeed.Count > 10)
                ViewData["NxtVisibility"] = "visibility:visible;";
            else
                ViewData["NxtVisibility"] = "visibility:hidden;";

            foreach (Seed sd in lstSeed)
            {
                sd.seedDistance = (int)objCmnMethods.distance(Convert.ToDouble(latSearch), Convert.ToDouble(lngSearch), Convert.ToDouble(sd.Location.localLat), Convert.ToDouble(sd.Location.localLong));
            }
            if (lstSeed.Count > 0)
                SessionStore.SetSessionValue(SessionStore.DiscoverSeed, lstSeed);
            ViewData["SeedList"] = lstSeed.OrderBy(x => x.seedDistance).ToList();

            ViewData["MarkerList"] = MarkerGenerator((IList<Seed>)ViewData["SeedList"]);

            //ListBox
            if (Session["SelectedCategory"] != null)
            {
                Session["SelectedCategory"] = null;
            }
            else
            {
                if (str != null)
                {
                    string myString = null;
                    for (int i = 0; i < str.Length; i++)
                    {
                        if (i == 0)
                        {
                            myString = str[i];

                        }
                        else
                        {
                            myString = myString + "," + str[i];
                        }
                    }
                    Session["SelectedCategory"] = myString;
                    ViewData["SelectedCategories"] = myString;
                }
            }
            //ListBox
            if (lstSeed.Count > 0)
            {
                CategoryAction objCat = new CategoryAction();
                IList<Category> categ = new List<Category>();
                Category c = null;
                foreach (Seed s in lstSeed)
                {
                    IList<Category> listCategory = s.Categories.ToList();
                    if (listCategory.Count > 0)
                    {
                        foreach (Category c1 in listCategory)
                        {
                            c = objCat.GetCategoryById(s.Categories.FirstOrDefault().id.ToString());
                            if (c != null)
                                categ.Add(c);
                        }
                    }
                }
                ViewData["SeedCategories"] = categ.Distinct().ToList();
            }

            return View();
        }
コード例 #2
0
        public ActionResult Default(string addr, string criteria, string[] sel0, string searchCriteriaTxt, string btnNext, string btnPrevious, string postLat, string postLng, string postZip)
        {
            GetTopPlanters();

            ViewData["LocLat"] = postLat;
            ViewData["LocLng"] = postLng;

            #region fb Coding
            string appid = ConfigurationManager.AppSettings["AppID"];
            ViewData["AppID"] = ConfigurationManager.AppSettings["AppID"];

            Repository repoObj = new Repository();
            Member memberData = (Member)SessionStore.GetSessionValue(SessionStore.Memberobject);
            if (memberData != null)
            {

            }
            else
            {
                FacebookConnect fbConnect = new FacebookConnect();
                if (fbConnect.IsConnected)
                {
                    // message = "You are connected to Facebook";

                    //Use the wrapper class to get the access token
                    string token = fbConnect.AccessToken;
                    //Alternatively you can just pull the accesstoken out directly with the following line
                    //string token = HttpContext.Request.Cookies["fbs_" + ConfigurationManager.AppSettings["AppID"]]["\"access_token"];

                    //Note - you need to decode the token or it will be encoded twice.
                    token = HttpUtility.UrlDecode(token);

                    FacebookAPI api = new FacebookAPI(token);
                    JSONObject me = api.Get("/" + fbConnect.UserID);
                    SessionStore.SetSessionValue(SessionStore.FacebookConnect, "FacebookUserLoggedIn");

                    return RedirectToAction("DiscoverSeed", "Seed");
                }
                else
                {

                }
            }
            #endregion

            #region Search Code
            //Category Selected Seeds
            Session["SelectedCategory"] = null;
            str = sel0;
            string myChoise = null;
            if (sel0 != null)
            {
                for (int i = 0; i < sel0.Length; i++)
                {
                    if (i == 0)
                    {
                        myChoise = sel0[0];
                    }
                    else
                    {
                        myChoise = myChoise + "," + sel0[i];
                    }
                }
            }
            Session["SelectedCategory"] = myChoise;

            ViewData["SelectedCategory"] = Session["SelectedCategory"];
            if (sel0 != null)
            {
                if (sel0.Count() == 1 && sel0[0].ToString().Equals("all"))
                    Session["SelectedCategory"] = null;
            }
            #endregion

            #region Home Page Paging
            if (btnNext == ".." || btnPrevious == ".")
            {
                int PageCount = Convert.ToInt32(Session["PageCount"]);
                int rowCount = Convert.ToInt32(Session["RowCount"]);
                int NoOfPage = rowCount / 10;
                if (rowCount % 10 != 0)
                {
                    NoOfPage += 1;
                }

                IList<Seed> lstseed = (IList<Seed>)SessionStore.GetSessionValue(SessionStore.DiscoverSeed);
                if (btnNext != null && btnNext == "..")
                {
                    int skipRecord = PageCount * 10;
                    IList<Seed> lst = lstseed.Skip(skipRecord).ToList();
                    ViewData["SeedList"] = lst.Take(10).ToList();
                    PageCount += 1;
                    Session["PageCount"] = PageCount;
                    if (PageCount == NoOfPage)
                    {
                        ViewData["NxtVisibility"] = "visibility:hidden;";
                        ViewData["PrevVisibility"] = "visibility:visible;";
                    }
                }
                else if (btnPrevious != null && btnPrevious == ".")
                {
                    int takeRecord = (PageCount - 1) * 10;
                    IList<Seed> lst = lstseed.Take(takeRecord).ToList();
                    ViewData["SeedList"] = lst.Reverse().Take(10).Reverse().ToList();
                    PageCount -= 1;
                    if (PageCount == 1)
                    {
                        ViewData["NxtVisibility"] = "visibility:visible;";
                        ViewData["PrevVisibility"] = "visibility:hidden;";
                    }
                    Session["PageCount"] = PageCount;
                }

                ViewData["MarkerList"] = MarkerGenerator((IList<Seed>)ViewData["SeedList"]);
                return View();
            }
            #endregion

            #region Search Logic
            if (addr != "" || criteria != "" || sel0 != null)
            {
                string categList = string.Empty;
                if (sel0 != null)
                {
                    if (sel0.Count() == 1 && sel0[0].ToString().Equals("all"))
                    {
                        categList = "all";
                    }
                    else if (sel0.Count() > 0 && !sel0[0].ToString().Equals("all"))
                    {
                        for (int c = 0; c < sel0.Count(); c++)
                        {
                            if (string.IsNullOrEmpty(categList))
                                categList = "'" + sel0[c].ToString() + "'";
                            else
                                categList = categList + ",'" + sel0[c].ToString() + "'";
                        }
                    }
                    else if (sel0.Count() > 1 && sel0[0].ToString().Equals("all"))
                    {
                        for (int c = 1; c < sel0.Count(); c++)
                        {
                            if (string.IsNullOrEmpty(categList))
                                categList = "'" + sel0[c].ToString() + "'";
                            else
                                categList = categList + ",'" + sel0[c].ToString() + "'";
                        }
                    }
                }

                //Neighborhood
                try
                {
                    if (!string.IsNullOrEmpty(addr))
                    {
                        if (!addr.Contains(','))
                        {
                            string[] checkString = addr.Trim().Split(' ');
                            if (checkString.Length > 1)
                            {
                                int splitCount = checkString.Count();
                                if (checkString[splitCount - 1].ToString().Length == 2)
                                {
                                    int idx = addr.LastIndexOf(' ');
                                    string idxString = addr.Insert(idx, ",");
                                    addr = idxString;
                                }
                            }
                        }
                    }
                }
                catch { }

                string[] splitString1 = addr.Split(',');
                string cityName1 = string.Empty;
                if (splitString1.Length > 0)
                {
                    string citySplit = splitString1[0].ToString();
                    if (citySplit.Contains("Your Location"))
                        citySplit = citySplit.Replace("Your Location : ", "");

                    cityName1 = citySplit;
                }
                ViewData["CatLocation"] = cityName1;
                IList<Seed> newListSeed = this.getHomeSearchResult(cityName1, categList, criteria, postZip, criteria);
                ViewData["SeedList"] = newListSeed.Distinct().ToList();

                if (newListSeed.Count > 0)
                {
                    ViewData["SeedList"] = newListSeed.OrderByDescending(x => x.createDate).ToList();
                }
                else
                {
                    newListSeed = repoObj.List<Seed>().Where(x => (x.status.Equals(SystemStatements.STATUS_NEW) || x.status.Equals(SystemStatements.STATUS_GROWING))).Take(20).OrderByDescending(x => x.createDate).ToList();
                    ViewData["SeedList"] = newListSeed;
                    ViewData["CitySearchMsg"] = "<span>Sorry, no seeds planted in '" + cityName1 + "' area. Showing latest additions.</span>";
                    string streamFeed = "Select top 20 * from Seed order by createDate desc";
                    SessionStore.SetSessionValue(SessionStore.DefaultFeed, streamFeed);
                }

                if (newListSeed.Count > 0)
                    SessionStore.SetSessionValue(SessionStore.DiscoverSeed, newListSeed);
                Session["RowCount"] = newListSeed.Count();
                Session["PageCount"] = "1";
                ViewData["PrevVisibility"] = "visibility:hidden;";
                if (newListSeed.Count > 10)
                    ViewData["NxtVisibility"] = "visibility:visible;";
                else
                    ViewData["NxtVisibility"] = "visibility:hidden;";

                CommonMethods objCmnMethods = new CommonMethods();
                string locLatLng = Session["LocLatLng"].ToString();
                string[] locLatLngSplit = locLatLng.Split(',');
                foreach (Seed sd in newListSeed)
                {
                    sd.seedDistance = (int)objCmnMethods.distance(Convert.ToDouble(locLatLngSplit[0].ToString()), Convert.ToDouble(locLatLngSplit[1].ToString()), Convert.ToDouble(sd.Location.localLat), Convert.ToDouble(sd.Location.localLong));
                }
                if (newListSeed.Count > 0)
                    SessionStore.SetSessionValue(SessionStore.DiscoverSeed, newListSeed);
                ViewData["SeedList"] = newListSeed.OrderBy(x => x.seedDistance).ToList();
                ViewData["MarkerList"] = MarkerGenerator(newListSeed);
                ViewData["Criteria"] = criteria;

                if (newListSeed.Count > 0)
                {
                    CategoryAction objCat = new CategoryAction();
                    IList<Category> categ = new List<Category>();
                    Category c = null;
                    foreach (Seed s in newListSeed)
                    {
                        IList<Category> listCategory = s.Categories.ToList();
                        if (listCategory.Count > 0)
                        {
                            foreach (Category c1 in listCategory)
                            {
                                c = objCat.GetCategoryById(s.Categories.FirstOrDefault().id.ToString());
                                if (c != null)
                                    categ.Add(c);
                            }
                        }
                    }
                    ViewData["SeedCategories"] = categ.Distinct().ToList();
                }
            }
            #endregion

            return View();
        }
コード例 #3
0
        public ActionResult SearchSeeds()
        {
            #region
            CommonMethods objCmnMethods = new CommonMethods();

            string strIpAddress = System.Web.HttpContext.Current.Request.UserHostAddress;
            if (strIpAddress == "127.0.0.1")
                strIpAddress = "61.246.241.162";

            string ipLocation = objCmnMethods.IP2AddressAPI(strIpAddress);
            string citySearch = string.Empty;
            string stateSearch = string.Empty;
            string zipCodeSearch = string.Empty;
            string latSearch = string.Empty;
            string lngSearch = string.Empty;
            string[] currentAddress;
            if (!string.IsNullOrEmpty(ipLocation))
            {
                //IPaddressAPI
                currentAddress = ipLocation.Split(',');

                if (string.IsNullOrEmpty(currentAddress[4].Replace("\"", "").ToString()))
                    stateSearch = "AZ";
                else
                    stateSearch = currentAddress[4].Replace("\"", "").ToString();

                if (string.IsNullOrEmpty(currentAddress[6].ToString()))
                    citySearch = "Phoenix";
                else
                    citySearch = currentAddress[6].Replace("\"", "").ToString();

                if (string.IsNullOrEmpty(currentAddress[7].Replace("\"", "").ToString()))
                    zipCodeSearch = "85027";
                else
                    zipCodeSearch = currentAddress[7].Replace("\"", "").ToString();

                latSearch = currentAddress[8].Replace("\"", "").ToString();
                lngSearch = currentAddress[9].Replace("\"", "").ToString();
            }
            else
            {
                //MaxMind
                ipLocation = objCmnMethods.IP2AddressMaxMind();
                currentAddress = ipLocation.Split('\'');

                if (string.IsNullOrEmpty(currentAddress[7].ToString()))
                    stateSearch = "AZ";
                else
                    stateSearch = currentAddress[7].ToString();

                if (string.IsNullOrEmpty(currentAddress[5].ToString()))
                    citySearch = "Phoenix";
                else
                    citySearch = currentAddress[5].ToString();

                if (string.IsNullOrEmpty(currentAddress[15].ToString()))
                    zipCodeSearch = "85027";
                else
                    zipCodeSearch = currentAddress[15].ToString();

                latSearch = currentAddress[11].ToString();
                lngSearch = currentAddress[13].ToString();
            }

            IList<Seed> lstSeed = null;
            if (SessionStore.GetSessionValue(SessionStore.SearchSeeds) != null)
                lstSeed = (IList<Seed>)SessionStore.GetSessionValue(SessionStore.SearchSeeds);

            foreach (Seed sd in lstSeed)
            {
                sd.seedDistance = (int)objCmnMethods.distance(Convert.ToDouble(latSearch), Convert.ToDouble(lngSearch), Convert.ToDouble(sd.Location.localLat), Convert.ToDouble(sd.Location.localLong));
            }
            ViewData["SearchSeeds"] = lstSeed;
            return View();
            #endregion
        }