/// <summary> /// This method is used to Add new Seeds. /// </summary> /// <param name="SeedName"></param> /// <param name="Description"></param> /// <param name="CityName"></param> /// <param name="Street"></param> /// <param name="RegionCode"></param> /// <param name="LatLong"></param> /// <param name="ZipCode"></param> /// <param name="ownerId"></param> /// <param name="tagName"></param> /// <returns></returns> public string AddSeedData(string SeedName, string Description, string CityName, string Street, string RegionCode, string Lat, string Lng, string ZipCode, string ownerId, string tagName, string imageName, string categoryNames) { bool actionCompleted = false; Seed seedData = null; string imagePath = imageName; string result = "Error while seed planting."; try { SeedAction objSeed = new SeedAction(); Seed objSeedEntity = new Seed(); Member memberData = new Member(); Tag objTagEntity = new Tag(); objSeedEntity.title = SeedName.Replace("|","&"); objSeedEntity.description = Description.Replace("|", "&"); LocationAction objLocation = new LocationAction(); string cityid = objLocation.GetCityIdByCityName(CityName, RegionCode); if (string.IsNullOrEmpty(cityid)) cityid = objSeed.AddCity(CityName, RegionCode); string lat = Lat; string longt = Lng; if (cityid.Length > 0) { Location objLoc = objLocation.CreateLocation(cityid, (ZipCode).ToString(), Convert.ToDouble(lat), Convert.ToDouble(longt), Street); objSeedEntity.locationId = new Guid(objLoc.id.ToString()); objSeedEntity.ownerId = new Guid(ownerId); seedData = objSeed.AddSeed(objSeedEntity); actionCompleted = true; result = seedData.id.ToString(); if (!string.IsNullOrEmpty(tagName)) { if (seedData.id != null && tagName.Length > 0) { if (!tagName.Equals("(null)")) { objTagEntity.name = tagName; objTagEntity.seedId = seedData.id; actionCompleted = objSeed.ManageTag(objTagEntity); } } } if (!string.IsNullOrEmpty(imageName)) { if (!imageName.Equals("No Image")) { AddMedia("Iphone Image1", imageName, seedData.id.ToString(), "Image", ownerId); imagePath = System.Configuration.ConfigurationManager.AppSettings["RootURL"].ToString() + "/UploadedMedia/" + imageName; } } if (!string.IsNullOrEmpty(categoryNames)) { if (seedData.id != null && categoryNames.Length > 0) { if (!categoryNames.Equals("Select Category")) { string[] arrCategoryIds; string[] arrCategoryNames; string ids = string.Empty; //categoryNames = categoryNames.TrimStart(','); arrCategoryNames = categoryNames.Split(','); CategoryAction objCategory = new CategoryAction(); for (int c = 0; c < arrCategoryNames.Length; c++) { if (!string.IsNullOrEmpty(ids)) ids = ids + "," + objCategory.GetCategoryIdByCategoryName(arrCategoryNames[c].ToString().Trim()); else ids = objCategory.GetCategoryIdByCategoryName(arrCategoryNames[c].ToString().Trim()); } arrCategoryIds = ids.Split(','); if (categoryNames.Trim().ToString() != "" && arrCategoryIds.Length > 0) { objSeed.AddCategories(seedData.id.ToString(), arrCategoryIds); } } } } result = seedData.id.ToString() + "||" + seedData.title + "||" + CityName + "||" + RegionCode + "||" + ZipCode + "||" + imageName + "||" + imagePath + "||" + DateTime.Now.ToString(); } if (actionCompleted == false) { result = "Error while seed planting."; } } catch (Exception ex) { result = "Error while seed planting."; } return result; }
public ActionResult AddStream(string gTitle, string gDesc, string gIsPublic, string streamType, string seedLocationStreamMini, string seedCoordinatesStreamMini, string txtCategoryStreamMini, string isEdit, string StreamId) { #region Front Logic try { Member memberData = (Member)SessionStore.GetSessionValue(SessionStore.Memberobject); StreamAction objStream = new StreamAction(); TempData["StreamTab"] = 1; if (isEdit == "Yes" && !string.IsNullOrEmpty(StreamId)) { ssStream ss = objStream.GetStreamById(StreamId); ss.title = gTitle; ss.description = gDesc; ss.isPublic = Convert.ToBoolean(gIsPublic); //Format address string StreetAddress1 = string.Empty; string City1 = string.Empty; string ZipCode1 = string.Empty; string StateCode1 = string.Empty; if (!string.IsNullOrEmpty(seedLocationStreamMini)) { string[] splitAddress = seedLocationStreamMini.Split(','); if (splitAddress.Length > 4) { StreetAddress1 = splitAddress[0].ToString() + ", " + splitAddress[1].ToString(); City1 = splitAddress[2].ToString().Trim(); string[] splitZipRegion = splitAddress[3].ToString().Trim().Split(' '); ZipCode1 = splitZipRegion[1].ToString().Trim(); StateCode1 = splitZipRegion[0].ToString().Trim(); } else { StreetAddress1 = splitAddress[0].ToString(); City1 = splitAddress[1].ToString().Trim(); string[] splitZipRegion = splitAddress[2].ToString().Trim().Split(' '); ZipCode1 = splitZipRegion[1].ToString().Trim(); StateCode1 = splitZipRegion[0].ToString().Trim(); } //End formatting address LocationAction objLocation = new LocationAction(); SeedAction objSeed = new SeedAction(); string latLong = seedCoordinatesStreamMini; string[] strSplitLatLong = latLong.Split(','); string lat = strSplitLatLong[0].ToString(); string longt = strSplitLatLong[1].ToString(); string crossStreet = StreetAddress1.Trim(); string cityId = objLocation.GetCityIdByCityName(City1, StateCode1); if (string.IsNullOrEmpty(cityId)) cityId = objSeed.AddCity(City1, StateCode1); Location loc = objLocation.CreateLocation(cityId, ZipCode1, Convert.ToDouble(lat), Convert.ToDouble(longt), crossStreet); ss.locationId = loc.id; } ss = objStream.UpdateStream1(ss); if (txtCategoryStreamMini != null) { string catIds = string.Empty; string[] splitCategories = txtCategoryStreamMini.Split(','); for (int i = 0; i < splitCategories.Length; i++) { CategoryAction objCatg = new CategoryAction(); string idCatg = objCatg.GetCategoryIdByCategoryName(splitCategories[i].ToString()); if (!string.IsNullOrEmpty(idCatg)) { if (string.IsNullOrEmpty(catIds)) catIds = idCatg; else catIds = catIds + "," + idCatg; } } if (!string.IsNullOrEmpty(catIds)) { string[] arrCatIds = catIds.Split(','); objStream.AddFeedCategories(Convert.ToString(ss.id), arrCatIds); } } if (!string.IsNullOrEmpty(Convert.ToString(ss.id))) { return RedirectToAction("ManageMyFeeds", "SeedStream"); } return RedirectToAction("UnexpectedError", "Error"); } ssStream stream = new ssStream(); stream.title = gTitle; stream.description = gDesc; if (streamType == SystemStatements.STREAM_FEED) { string defaultFeed = (string)SessionStore.GetSessionValue(SessionStore.DefaultFeed); if (!string.IsNullOrEmpty(defaultFeed)) stream.criteria = defaultFeed; stream.streamType = streamType; } else if (streamType == SystemStatements.STREAM_HANDPICKED) { stream.streamType = streamType; } stream.ownerId = memberData.id; //Format address string StreetAddress = string.Empty; string City = string.Empty; string ZipCode = string.Empty; string StateCode = string.Empty; if (!string.IsNullOrEmpty(seedLocationStreamMini)) { string[] splitAddress = seedLocationStreamMini.Split(','); if (splitAddress.Length > 4) { StreetAddress = splitAddress[0].ToString() + ", " + splitAddress[1].ToString(); City = splitAddress[2].ToString().Trim(); string[] splitZipRegion = splitAddress[3].ToString().Trim().Split(' '); ZipCode = splitZipRegion[1].ToString().Trim(); StateCode = splitZipRegion[0].ToString().Trim(); } else { StreetAddress = splitAddress[0].ToString(); City = splitAddress[1].ToString().Trim(); string[] splitZipRegion = splitAddress[2].ToString().Trim().Split(' '); ZipCode = splitZipRegion[1].ToString().Trim(); StateCode = splitZipRegion[0].ToString().Trim(); } //End formatting address LocationAction objLocation = new LocationAction(); SeedAction objSeed = new SeedAction(); string latLong = seedCoordinatesStreamMini; string[] strSplitLatLong = latLong.Split(','); string lat = strSplitLatLong[0].ToString(); string longt = strSplitLatLong[1].ToString(); string crossStreet = StreetAddress.Trim(); string cityId = objLocation.GetCityIdByCityName(City, StateCode); if (string.IsNullOrEmpty(cityId)) cityId = objSeed.AddCity(City, StateCode); Location loc = objLocation.CreateLocation(cityId, ZipCode, Convert.ToDouble(lat), Convert.ToDouble(longt), crossStreet); stream.locationId = loc.id; } stream.isPublic = Convert.ToBoolean(gIsPublic); stream = objStream.CreateStream1(stream); if (txtCategoryStreamMini != null) { string catIds = string.Empty; string[] splitCategories = txtCategoryStreamMini.Split(','); for (int i = 0; i < splitCategories.Length; i++) { CategoryAction objCatg = new CategoryAction(); string idCatg = objCatg.GetCategoryIdByCategoryName(splitCategories[i].ToString()); if (!string.IsNullOrEmpty(idCatg)) { if (string.IsNullOrEmpty(catIds)) catIds = idCatg; else catIds = catIds + "," + idCatg; } } if (!string.IsNullOrEmpty(catIds)) { string[] arrCatIds = catIds.Split(','); objStream.AddFeedCategories(Convert.ToString(stream.id), arrCatIds); } } if (!string.IsNullOrEmpty(Convert.ToString(stream.id))) { return RedirectToAction("ManageMyFeeds", "SeedStream"); } return RedirectToAction("UnexpectedError", "Error"); } catch (Exception ex) { SessionStore.SetSessionValue("PlantError", "Error occurred while creating list#" + ex.Message.ToString()); return RedirectToAction("PlantError", "Seed"); } #endregion }
public string AddSeedData(AddSeed objAddSeedModel) { #region bool actionCompleted = false; Seed seedData = null; SeedAction objSeed = new SeedAction(); Seed objSeedEntity = new Seed(); Member memberData = new Member(); Tag objTagEntity = new Tag(); objSeedEntity.title = objAddSeedModel.SeedName; if (!string.IsNullOrEmpty(objAddSeedModel.rootSeedId)) objSeedEntity.rootSeedID = new Guid(objAddSeedModel.rootSeedId); if (!string.IsNullOrEmpty(objAddSeedModel.parentSeedId)) objSeedEntity.parentSeedID = new Guid(objAddSeedModel.parentSeedId); string s = Regex.Replace(objAddSeedModel.Description, @"<(.|\n)*?>", string.Empty); s = s.Replace(" ", " "); s = Regex.Replace(s, @"\s+", " "); s = Regex.Replace(s, @"\r\n", "\n"); s = Regex.Replace(s, @"\n+", "\n"); string description = s; if (description.Length > 999) description = description.Substring(0, 995); badWordsFilter objWords = new badWordsFilter(); string filePath = Server.MapPath("~/utils/badWords.xml"); List<string> lstBadWords = badWordsFilter.BadWordList(ref filePath); description = objWords.FilterBadWords(lstBadWords, description); objSeedEntity.description = description; LocationAction objLocation = new LocationAction(); string cityid = objLocation.GetCityIdByCityName(objAddSeedModel.City, objAddSeedModel.StateCode); if (string.IsNullOrEmpty(cityid)) cityid = objSeed.AddCity(objAddSeedModel.City, objAddSeedModel.StateCode); if (string.IsNullOrEmpty(cityid)) throw new Exception("Please select associated state and city"); string latLong = objAddSeedModel.LongLat; char[] separator = new char[] { ',' }; string[] strSplitLatLong = latLong.Split(separator); string lat = strSplitLatLong[0].ToString(); string longt = strSplitLatLong[1].ToString(); string crossStreet = objAddSeedModel.StreetAddress.Trim(); Location objLoc = objLocation.CreateLocation(cityid, (objAddSeedModel.ZipCode).ToString(), Convert.ToDouble(lat), Convert.ToDouble(longt), crossStreet); objSeedEntity.locationId = new Guid(objLoc.id.ToString()); if (SeedSpeak.Util.SessionStore.GetSessionValue(SeedSpeak.Util.SessionStore.Memberobject) != null) memberData = (Member)SeedSpeak.Util.SessionStore.GetSessionValue(SeedSpeak.Util.SessionStore.Memberobject); objSeedEntity.ownerId = memberData.id; seedData = objSeed.AddSeed(objSeedEntity); if (objSeedEntity.id != null) { if (!string.IsNullOrEmpty(objAddSeedModel.Tag)) { objTagEntity.name = objAddSeedModel.Tag; objTagEntity.seedId = objSeedEntity.id; actionCompleted = objSeed.ManageTag(objTagEntity); } } if (actionCompleted == false) { ModelState.AddModelError("", "Error while seed planting."); RedirectToAction("AddSeed", "Seed"); } return seedData.id.ToString(); #endregion }
public ActionResult AddStreamFeed(string gFeedTitle, string gFeedDesc, string gIsPublic, string seedLocationStreamFeed, string seedCoordinatesStreamFeed, string txtCategoryStreamFeed, string feedLocation, string profileLocValue, string NewLocValue, string LocationRadius, string CoordinatesRadius, string gIsMedia, string txtIncludeTerms, string txtExcludeTerms, string isEdit, string StreamId) { #region Front Logic try { Member memberData = (Member)SessionStore.GetSessionValue(SessionStore.Memberobject); StreamAction objStream = new StreamAction(); ssStream stream = new ssStream(); stream.title = gFeedTitle; stream.description = gFeedDesc; string feedQuery = "Select Seed.* from Seed where (seed.[status] = 'New' or seed.[status] = 'Growing')"; #region add location in query if (!string.IsNullOrEmpty(feedLocation)) { if (feedLocation != "AllLocations") { string radius = string.Empty; string radiusZipList = string.Empty; string ZipCodeFeed = string.Empty; if (feedLocation == "ProfileLocation") { radius = profileLocValue; if (memberData.MemberProfiles != null) { if (memberData.MemberProfiles.FirstOrDefault().Location.zipcode != null) ZipCodeFeed = Convert.ToString(memberData.MemberProfiles.FirstOrDefault().Location.zipcode); } else ZipCodeFeed = "85027"; } if (feedLocation == "NewLocation") { radius = NewLocValue; //Format address string[] splitAddressFeed = LocationRadius.Split(','); if (splitAddressFeed.Length > 4) { string[] splitZipRegion = splitAddressFeed[3].ToString().Trim().Split(' '); ZipCodeFeed = splitZipRegion[1].ToString().Trim(); } else { string[] splitZipRegion = splitAddressFeed[2].ToString().Trim().Split(' '); ZipCodeFeed = splitZipRegion[1].ToString().Trim(); } //End formatting address } //Get zip codes according to radius CommonMethods objCommon = new CommonMethods(); radiusZipList = objCommon.GetZipByRadius(radius, ZipCodeFeed); //End get zip codes according to radius if (string.IsNullOrEmpty(radiusZipList)) radiusZipList = ZipCodeFeed; feedQuery += " and locationId in (Select id from Location where zipcode in (" + radiusZipList + "))"; } } #endregion #region include terms in query if (!string.IsNullOrEmpty(txtIncludeTerms)) { string inCondition = string.Empty; string[] includeTerms = txtIncludeTerms.Split(','); for (int i = 0; i < includeTerms.Length; i++) { if (i == 0) inCondition = "'" + includeTerms[i].ToString() + "'"; else inCondition += ",'" + includeTerms[i].ToString() + "'"; } feedQuery += " 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(txtExcludeTerms)) { string exCondition = string.Empty; string[] excludeTerms = txtExcludeTerms.Split(','); for (int i = 0; i < excludeTerms.Length; i++) { if (i == 0) exCondition = "'" + excludeTerms[i].ToString() + "'"; else exCondition += ",'" + excludeTerms[i].ToString() + "'"; } feedQuery += " 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(gIsMedia)) { switch (gIsMedia) { case "All": feedQuery += " and Seed.id in (Select m.seedId from Media m)"; break; case "NoMedia": feedQuery += " and Seed.id not in (Select m.seedId from Media m)"; break; case "PhotosOnly": feedQuery += " and Seed.id in (Select m.seedId from Media m where m.[type]='" + SystemStatements.MEDIA_IMAGE + "')"; break; case "VideosOnly": feedQuery += " and Seed.id in (Select m.seedId from Media m where m.[type]='" + SystemStatements.MEDIA_VIDEO + "')"; break; default: break; } } #endregion stream.criteria = feedQuery; stream.streamType = SystemStatements.STREAM_FEED; stream.ownerId = memberData.id; if (isEdit == "Yes" && !string.IsNullOrEmpty(StreamId)) { ssStream ss = objStream.GetStreamById(StreamId); ss.title = gFeedTitle; ss.description = gFeedDesc; ss.criteria = feedQuery; ss.isPublic = Convert.ToBoolean(gIsPublic); if (!string.IsNullOrEmpty(seedLocationStreamFeed)) { //Format address string StreetAddress = string.Empty; string City = string.Empty; string ZipCode = string.Empty; string StateCode = string.Empty; string[] splitAddress = seedLocationStreamFeed.Split(','); string feedCountry = string.Empty; if (splitAddress.Length > 4) { StreetAddress = splitAddress[0].ToString() + ", " + splitAddress[1].ToString(); City = splitAddress[2].ToString().Trim(); string[] splitZipRegion = splitAddress[3].ToString().Trim().Split(' '); ZipCode = splitZipRegion[1].ToString().Trim(); StateCode = splitZipRegion[0].ToString().Trim(); feedCountry = splitAddress[4].ToString(); } else { StreetAddress = splitAddress[0].ToString(); City = splitAddress[1].ToString().Trim(); string[] splitZipRegion = splitAddress[2].ToString().Trim().Split(' '); ZipCode = splitZipRegion[1].ToString().Trim(); StateCode = splitZipRegion[0].ToString().Trim(); feedCountry = splitAddress[3].ToString(); } //End formatting address if (feedCountry.Trim().Equals("USA") || feedCountry.Trim().Equals("US")) feedCountry = feedCountry.Trim(); else throw new Exception("Feeds can not be created outside region of United States"); LocationAction objLocation = new LocationAction(); SeedAction objSeed = new SeedAction(); string latLong = seedCoordinatesStreamFeed; string[] strSplitLatLong = latLong.Split(','); string lat = strSplitLatLong[0].ToString(); string longt = strSplitLatLong[1].ToString(); string crossStreet = StreetAddress.Trim(); string cityId = objLocation.GetCityIdByCityName(City, StateCode); if (string.IsNullOrEmpty(cityId)) cityId = objSeed.AddCity(City, StateCode); Location loc = objLocation.CreateLocation(cityId, ZipCode, Convert.ToDouble(lat), Convert.ToDouble(longt), crossStreet); ss.locationId = loc.id; } ss = objStream.UpdateStream1(ss); if (txtCategoryStreamFeed != null) { string catIds = string.Empty; string[] splitCategories = txtCategoryStreamFeed.Split(','); for (int i = 0; i < splitCategories.Length; i++) { CategoryAction objCatg = new CategoryAction(); string idCatg = objCatg.GetCategoryIdByCategoryName(splitCategories[i].ToString()); if (!string.IsNullOrEmpty(idCatg)) { if (string.IsNullOrEmpty(catIds)) catIds = idCatg; else catIds = catIds + "," + idCatg; } } if (!string.IsNullOrEmpty(catIds)) { string[] arrCatIds = catIds.Split(','); objStream.AddFeedCategories(Convert.ToString(ss.id), arrCatIds); } } if (!string.IsNullOrEmpty(Convert.ToString(ss.id))) { return RedirectToAction("ManageMyFeeds", "SeedStream"); } return RedirectToAction("UnexpectedError", "Error"); } if (!string.IsNullOrEmpty(seedLocationStreamFeed)) { //Format address string StreetAddress = string.Empty; string City = string.Empty; string ZipCode = string.Empty; string StateCode = string.Empty; string[] splitAddress = seedLocationStreamFeed.Split(','); string feedCountry = string.Empty; if (splitAddress.Length > 4) { StreetAddress = splitAddress[0].ToString() + ", " + splitAddress[1].ToString(); City = splitAddress[2].ToString().Trim(); string[] splitZipRegion = splitAddress[3].ToString().Trim().Split(' '); ZipCode = splitZipRegion[1].ToString().Trim(); StateCode = splitZipRegion[0].ToString().Trim(); feedCountry = splitAddress[4].ToString(); } else { StreetAddress = splitAddress[0].ToString(); City = splitAddress[1].ToString().Trim(); string[] splitZipRegion = splitAddress[2].ToString().Trim().Split(' '); ZipCode = splitZipRegion[1].ToString().Trim(); StateCode = splitZipRegion[0].ToString().Trim(); feedCountry = splitAddress[3].ToString(); } //End formatting address if (feedCountry.Trim().Equals("USA") || feedCountry.Trim().Equals("US")) feedCountry = feedCountry.Trim(); else throw new Exception("Feeds can not be created outside region of United States"); LocationAction objLocation = new LocationAction(); SeedAction objSeed = new SeedAction(); string latLong = seedCoordinatesStreamFeed; string[] strSplitLatLong = latLong.Split(','); string lat = strSplitLatLong[0].ToString(); string longt = strSplitLatLong[1].ToString(); string crossStreet = StreetAddress.Trim(); string cityId = objLocation.GetCityIdByCityName(City, StateCode); if (string.IsNullOrEmpty(cityId)) cityId = objSeed.AddCity(City, StateCode); Location loc = objLocation.CreateLocation(cityId, ZipCode, Convert.ToDouble(lat), Convert.ToDouble(longt), crossStreet); stream.locationId = loc.id; } stream.isPublic = Convert.ToBoolean(gIsPublic); stream = objStream.CreateStream1(stream); if (txtCategoryStreamFeed != null) { string catIds = string.Empty; string[] splitCategories = txtCategoryStreamFeed.Split(','); for (int i = 0; i < splitCategories.Length; i++) { CategoryAction objCatg = new CategoryAction(); string idCatg = objCatg.GetCategoryIdByCategoryName(splitCategories[i].ToString()); if (!string.IsNullOrEmpty(idCatg)) { if (string.IsNullOrEmpty(catIds)) catIds = idCatg; else catIds = catIds + "," + idCatg; } } if (!string.IsNullOrEmpty(catIds)) { string[] arrCatIds = catIds.Split(','); objStream.AddFeedCategories(Convert.ToString(stream.id), arrCatIds); } } if (!string.IsNullOrEmpty(Convert.ToString(stream.id))) { return RedirectToAction("ManageMyFeeds", "SeedStream"); } return RedirectToAction("UnexpectedError", "Error"); } catch (Exception ex) { SessionStore.SetSessionValue("PlantError", "Error occurred while creating feed#" + ex.Message.ToString()); return RedirectToAction("PlantError", "Seed"); } #endregion }
/// <summary> /// Method to Manage Member Profile. /// </summary> /// <param name="cityName"></param> /// <param name="zipcode"></param> /// <param name="localLat"></param> /// <param name="localLong"></param> /// <param name="regionName"></param> /// <param name="sex"></param> /// <param name="dob"></param> /// <returns></returns> public bool ManageMemberProfile(Member member, string cityId, string zipcode, double localLat, double localLong, string sex, DateTime dob, string url, string bio) { #region Business Logic bool actionCompleted = false; try { LocationAction lrepo = new LocationAction(); //Get the location Location location = lrepo.CreateLocation(cityId, zipcode, localLat, localLong, ""); //Updates the member profile this.UpdateMemberProfile(member, sex, dob, location, url, bio); actionCompleted = true; } catch (Exception ex) { WriteError(ex); } return actionCompleted; #endregion }