/// <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; }
/// <summary> /// Method to Update seed. /// </summary> /// <param name="seedId"></param> /// <param name="seedName"></param> /// <param name="seedDescription"></param> /// <returns></returns> public string UpdateSeed(string seedId, string seedName, string seedDescription, string SeedTags, string categories, string imageName, string ownerId) { string isCompleted = "Error in Update Action"; SeedAction objSeed = new SeedAction(); try { Seed seedData = objSeed.GetSeedBySeedId(seedId); seedData.title = seedName.Replace("|", "&"); seedData.description = seedDescription.Replace("|", "&"); objSeed.UpdateSeed(seedData); if (!string.IsNullOrEmpty(imageName)) { if (!imageName.Equals("No Image")) { AddMedia("Iphone Image1", imageName, seedData.id.ToString(), "Image", ownerId); } } if (!string.IsNullOrEmpty(categories)) { if (!categories.Equals("Select Category")) { bool isPlanted = false; string[] arrCategoryIds; string[] arrCategoryNames; string ids = string.Empty; arrCategoryNames = categories.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 (categories.Trim().ToString() != "" && arrCategoryIds.Length > 0) { isPlanted = objSeed.AddCategories(seedData.id.ToString(), arrCategoryIds); } } } Tag objTagEntity = new Tag(); if (!string.IsNullOrEmpty(SeedTags)) { if (!SeedTags.Equals("(null)")) { objTagEntity.name = SeedTags; objTagEntity.seedId = new Guid(seedId); objSeed.ManageTag(objTagEntity); } } //isCompleted = "Seed Update Successfully"; if (imageName.Length > 1 && imageName != "No Image") { imageName = System.Configuration.ConfigurationManager.AppSettings["RootURL"].ToString() + "/UploadedMedia/" + imageName; } else { imageName = "No Image"; } isCompleted = seedData.id.ToString() + "||" + seedData.title + "||" + seedData.Location.City.name + "||" + seedData.Location.City.Region.code + "||" + seedData.Location.zipcode + "||" + imageName; //isCompleted = "SeedId: " + seedId + ", Seed Name: " + seedName + ", Seed Description: " + seedDescription; } catch { } return isCompleted; }
public ActionResult EditSeed(string SeedId, string SeedTitle, string SeedDescription, string SeedTags, string categoryIds) { #region SeedAction objSeed = new SeedAction(); Seed seed = objSeed.GetSeedBySeedId(SeedId); seed.title = SeedTitle; badWordsFilter objWords = new badWordsFilter(); string filePath = Server.MapPath("~/utils/badWords.xml"); List<string> lstBadWords = badWordsFilter.BadWordList(ref filePath); string description = objWords.FilterBadWords(lstBadWords, SeedDescription); if (description.Length > 999) description = description.Substring(0, 995); seed.description = description; seed = objSeed.UpdateSeed(seed); string[] arrCategoryIds; char[] separator = new char[] { ',' }; categoryIds = categoryIds.TrimStart(','); arrCategoryIds = categoryIds.Split(','); bool isPlanted = false; if (categoryIds.Trim().ToString() != "") { isPlanted = objSeed.AddCategories(SeedId, arrCategoryIds); } Tag objTagEntity = new Tag(); if (!string.IsNullOrEmpty(SeedTags)) { objTagEntity.name = SeedTags; objTagEntity.seedId = new Guid(SeedId); objSeed.ManageTag(objTagEntity); } if (seed.id != null) { //send automated email - content of email will be decided later // Creating array list for token ArrayList arrTokens = new ArrayList(); arrTokens.Add(seed.Member.firstName + " " + seed.Member.lastName); arrTokens.Add(seed.title); // Filling mail object SendMail objSendMail = new SendMail(); objSendMail.ToEmailId = seed.Member.username; objSendMail.Subject = "email.editSeed.subject.content"; objSendMail.MsgBody = "email.editSeed.body.content"; objSendMail.ChangesInMessage = arrTokens; objSendMail.SendEmail(objSendMail); } Response.Redirect("/Seed/SeedDetails/" + SeedId); return View(); #endregion }
/// <summary> /// Method to manage tag for seed. /// </summary> /// <param name="tag"></param> /// <returns></returns> public bool ManageTag(Tag tag) { #region Business Logic bool actionCompleted = false; try { //see if tag exists Guid tempId = new Guid(tag.seedId.ToString()); Tag tagData = repoObj.List<Tag>(x => x.Seed.id.Equals(tempId)).FirstOrDefault(); if (tagData != null) { tagData.name = tag.name; repoObj.Update<Tag>(tagData); } else { tag.id = Guid.NewGuid(); repoObj.Create<Tag>(tag); } actionCompleted = true; } catch (Exception ex) { WriteError(ex); } return actionCompleted; #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 }