public ActionResult AdvanceSearch(string AdvLocation, string currentLocValue, string AnotherLocValue, string LocationAdvSearchRadius, string CoordinatesAdvSearchRadius, string advMedia, string advReplySeeds, string txtAdvSearchIncludeTerms, string txtAdvSearchExcludeTerms) { #region Front Logic Member memberData = (Member)SessionStore.GetSessionValue(SessionStore.Memberobject); SeedAction objSeed = new SeedAction(); string advSearchQuery = "Select Seed.* from Seed where (seed.[status] = 'New' or seed.[status] = 'Growing')"; if (advReplySeeds != "IncludeReplySeeds") advSearchQuery += " and seed.parentSeedID is null"; #region add location in query if (!string.IsNullOrEmpty(AdvLocation)) { if (AdvLocation != "AllLocations") { string radius = string.Empty; string radiusZipList = string.Empty; string ZipCodeAdvSearch = string.Empty; if (AdvLocation == "CurrentLocation") { radius = currentLocValue; 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[] currentAddress; if (!string.IsNullOrEmpty(ipLocation)) { //IPaddressAPI currentAddress = ipLocation.Split(','); if (string.IsNullOrEmpty(currentAddress[7].Replace("\"", "").ToString())) ZipCodeAdvSearch = "85027"; else ZipCodeAdvSearch = currentAddress[7].Replace("\"", "").ToString(); } else { //MaxMind ipLocation = objCmnMethods.IP2AddressMaxMind(); currentAddress = ipLocation.Split('\''); if (string.IsNullOrEmpty(currentAddress[15].ToString())) ZipCodeAdvSearch = "85027"; else ZipCodeAdvSearch = currentAddress[15].ToString(); } } if (AdvLocation == "NewLocation") { radius = AnotherLocValue; //Format address string[] splitAddressSearch = LocationAdvSearchRadius.Split(','); if (splitAddressSearch.Length > 4) { string[] splitZipRegion = splitAddressSearch[3].ToString().Trim().Split(' '); ZipCodeAdvSearch = splitZipRegion[1].ToString().Trim(); } else { string[] splitZipRegion = splitAddressSearch[2].ToString().Trim().Split(' '); ZipCodeAdvSearch = splitZipRegion[1].ToString().Trim(); } //End formatting address } //Get zip codes according to radius CommonMethods objCommon = new CommonMethods(); radiusZipList = objCommon.GetZipByRadiusNew(radius, ZipCodeAdvSearch); //End get zip codes according to radius if (string.IsNullOrEmpty(radiusZipList)) radiusZipList = ZipCodeAdvSearch; advSearchQuery += " and locationId in (Select id from Location where zipcode in (" + radiusZipList + "))"; } } #endregion #region include terms in query if (!string.IsNullOrEmpty(txtAdvSearchIncludeTerms)) { string inCondition = string.Empty; string[] includeTerms = txtAdvSearchIncludeTerms.Split(','); for (int i = 0; i < includeTerms.Length; i++) { if (i == 0) inCondition = "'" + includeTerms[i].ToString() + "'"; else inCondition += ",'" + includeTerms[i].ToString() + "'"; } advSearchQuery += " and Seed.id in (select sc.seedId from Category c ,Seed_has_Category sc where c.id=sc.categoryId and c.name in (" + inCondition + ") union select Seed.id from Seed,Member where Member.id = Seed.ownerId and Member.firstName in (" + inCondition + "))"; } #endregion #region exclude terms in query if (!string.IsNullOrEmpty(txtAdvSearchExcludeTerms)) { string exCondition = string.Empty; string[] excludeTerms = txtAdvSearchExcludeTerms.Split(','); for (int i = 0; i < excludeTerms.Length; i++) { if (i == 0) exCondition = "'" + excludeTerms[i].ToString() + "'"; else exCondition += ",'" + excludeTerms[i].ToString() + "'"; } advSearchQuery += " and Seed.id not in (select sc.seedId from Category c ,Seed_has_Category sc where c.id=sc.categoryId and c.name in (" + exCondition + ") union select Seed.id from Seed,Member where Member.id = Seed.ownerId and Member.firstName in (" + exCondition + "))"; } #endregion #region add media in query if (!string.IsNullOrEmpty(advMedia)) { switch (advMedia) { case "All": advSearchQuery += " and Seed.id in (Select m.seedId from Media m)"; break; case "NoMedia": advSearchQuery += " and Seed.id not in (Select m.seedId from Media m)"; break; case "PhotosOnly": advSearchQuery += " and Seed.id in (Select m.seedId from Media m where m.[type]='" + SystemStatements.MEDIA_IMAGE + "')"; break; case "VideosOnly": advSearchQuery += " and Seed.id in (Select m.seedId from Media m where m.[type]='" + SystemStatements.MEDIA_VIDEO + "')"; break; default: break; } } #endregion IList<Seed> lstSeed = null; lstSeed = objSeed.GetSeedListByCriteria(advSearchQuery); lstSeed = lstSeed.Distinct().ToList(); SessionStore.SetSessionValue(SessionStore.SearchSeeds, lstSeed); TempData["DiscoverSeed"] = "AdvanceSearch"; #endregion return RedirectToAction("SearchSeeds", "Home"); }