public void AddPost(Post post) { // Parse Tags into separate hash tags if (post.Tags != null) { var hashtags = post.Tags.Replace("#", "").Split(','); foreach (var hashtag in hashtags) { if (hashtag != "") { var p = new HashTag(); p.ActualHashTag = hashtag; post.HashTags.Add(p); } } } var create = new Create(); var postID = create.AddPost(post); // Check if post add was successful and returned the new postID if (postID != null && post.HashTags.Count() != 0) { foreach (var tag in post.HashTags) { create.AddTag((int)postID, tag); } } }
protected HashSet <HashTag> GetTagsFromContent(string content, IEnumerable <HashTag> tags) { MatchCollection m = Regex.Matches(content, HashTagRegex); HashSet <HashTag> hashTags = new HashSet <HashTag>(); foreach (var match in m) { string tagName = match.ToString(); var tag = tags.FirstOrDefault(t => t.Name.ToLower() == tagName.ToLower()); if (tag == null) { tag = new HashTag() { Name = tagName }; } if (!hashTags.Contains(tag)) { hashTags.Add(tag); } } return(hashTags); }
public void AddTag(int postID, HashTag hashTag) { using (SqlConnection cn = new SqlConnection(Settings.ConnectionString)) { var p = new DynamicParameters(); try { p.Add("PostID", postID); p.Add("ActualHashTag", hashTag.ActualHashTag); cn.Execute("AddTag", p, commandType: CommandType.StoredProcedure); } //catch (Exception e) //{ // // Write failure to database // var ep = new DynamicParameters(); // ep.Add("ExceptionType", e.GetType()); // ep.Add("ExceptionMessage", e.Message); // cn.Execute("AddError", ep, commandType: CommandType.StoredProcedure); //} finally { cn.Close(); } } }
public EditHashTagResponse EditHashTag(HashTag hash) { var response = new EditHashTagResponse(); var hashTags = repo.GetAllHashtags(); if (hash == null) { response.Success = false; response.Message = $"{hash} does not exist."; } else if (!hash.HashTagName.Contains("#")) { response.Success = false; response.Message = $"{hash.HashTagName} needs to contain a #."; } else { response.HashTag = repo.EditHashTag(hash); if (response.HashTag == null) { response.Success = false; response.Message = $"{response.HashTag} does not exist."; } else { response.Success = true; } } return(response); }
public int AddHashTag(string hashTagContent) { int hashTagId = 0; try { var hashTag = db.HashTags.Where(x => x.HashTagContent == hashTagContent).FirstOrDefault(); if (hashTag != null) { hashTag.Count = hashTag.Count + 1; hashTagId = hashTag.HashTagId; Save(); } else { HashTag hashTagObj = new HashTag(); hashTagObj.HashTagContent = hashTagContent; hashTagObj.Count = 1; db.HashTags.Add(hashTagObj); Save(); hashTagId = db.HashTags.Where(x => x.HashTagContent == hashTagContent).FirstOrDefault().HashTagId; } } catch (Exception) { Console.WriteLine("Exception in database connectivity"); } return(hashTagId); }
public async Task <IActionResult> AddHashTag(int linkId, [FromBody] HashTag tag) { var link = await _context.SiteLinks .Include(l => l.SiteLinkHashTags) .FirstOrDefaultAsync(l => l.Id == linkId); if (link is null) { return(NotFound()); } // TODO: maybe it's better to match tag by name rather then id. MR var tagAlreadyExists = link.SiteLinkHashTags .Select(lt => lt.HashTagId) .Contains(tag.Id); if (tagAlreadyExists) { return(Ok()); } _context.Attach(link); _context.Update(new SiteLinkHashTag { SiteLinkId = linkId, HashTag = tag, }); await _context.SaveChangesAsync(); return(Ok()); }
public IHttpActionResult CreateMemes([FromBody] MemHashTagsViewModel createMem) { if (createMem != null) { Memes mem = new Memes() { MemName = createMem.MemName, Image = createMem.Image, UserId = createMem.UserId }; db.Memes.Add(mem); db.SaveChanges(); foreach (var item in createMem.HashTags) { var hashTag = new HashTag() { Name = item, MemesId = mem.Id }; db.HashTags.Add(hashTag); db.SaveChanges(); } return(Ok()); } else { return(NotFound()); } }
public ActionResult UserPosts(string hashtag) { using (ApplicationDbContext db = new ApplicationDbContext()) { var manager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db)); var currentUser = manager.FindById(User.Identity.GetUserId()); ViewBag.username = currentUser.user; IEnumerable <CodePost> list = null; if (hashtag != null) { HashTag searchtag = db.tags.ToList().Find(t => t.tag == hashtag); list = db.hashTags. Where(t => t.Hash.tag == (hashtag)). Select(t => t.Post). ToList(); } else { list = from code in db.posts.ToList() where code.user_id == currentUser.Id select code; } return(View(list)); } }
public HashTag execute(CreateHashTagRequest request) { Guard.IsNotNull(request, "request"); if (string.IsNullOrWhiteSpace(request.hash_tag_name)) { throw new Exception("Hash tag cannot be empty"); } request.hash_tag_name = request.hash_tag_name.TrimStart('#'); var hash_tag = hash_tag_repository.Entities.SingleOrDefault(h => h.HashTagName == request.hash_tag_name); if (hash_tag == null) { hash_tag = new HashTag() { HashTagName = request.hash_tag_name, DateTimeFirstCreated = Resources.current_date_time }; hash_tag_repository.add(hash_tag); } return hash_tag; }
public ActionResult Create(BlogPost blogPost, HttpPostedFileBase photo, string[] tags) { ViewBag.Tags = new MultiSelectList(db.HashTags.ToList(), "Id", "Name"); PhototErrorControls(photo); if (blogPost != null && photo != null) { var allTags = tags[1]; string[] tagFinal = allTags.Split(','); for (int i = 0; i < tagFinal.Length; i++) { var oneTag = tagFinal[i]; if (!db.HashTags.Any(x => x.Name == oneTag)) { HashTag addedTag = new HashTag() { Name = tagFinal[i] }; db.HashTags.Add(addedTag); blogPost.Tags.Add(addedTag); } else { HashTag tagAlreadyCreated = db.HashTags.FirstOrDefault(x => x.Name == oneTag); blogPost.Tags.Add(tagAlreadyCreated); } } blogPost.CreatingTime = DateTime.Now; blogPost.PhotoPath = PhotoUpdate(photo); db.BlogPosts.Add(blogPost); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(blogPost)); }
public ActionResult RequestNewHashTag(HashTag hashTag) { hashTag.HashTagName = "#" + hashTag.HashTagName; hashTag.Approved = false; hashRepo.AddHashTag(hashTag); return(RedirectToAction("Index", "Home")); }
public async Task <IHttpActionResult> PutHashTag(int id, HashTag hashTag) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != hashTag.ID_Matter) { return(BadRequest()); } db.Entry(hashTag).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!HashTagExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
private void filterPostHashtags(Post post) { var regex = new Regex(@"(?<=#)\w+"); var matches = regex.Matches(post.Content) .OfType <Match>() .Distinct(); foreach (Match m in matches) { HashTag newHT; newHT = db.HashTags.Where(ht => ht.Name == m.Value).FirstOrDefault(); if (newHT == null) { newHT = new HashTag() { Name = m.Value, Id = Guid.NewGuid() }; db.HashTags.Add(newHT); db.SaveChanges(); } post.HashTags.Add(newHT); } }
public HashTag GetHashTag(int id) { HashTag hashTag = new HashTag(); var hashtags = GetAllHashtags(); hashTag = hashtags.Where(h => h.HashTagId == id).SingleOrDefault(); return(hashTag); }
public void GetStringTest(string fileName, HashTag testTag, string expectedString) { MediaFile testMediaFile = new MediaFile(GetTestDataFilePath(fileName)); string actualString = testTag.GetString(TestRenamer, testMediaFile); Assert.AreEqual(expectedString, actualString); }
public ActionResult DeleteConfirmed(int id) { HashTag hashTag = db.HashTags.Find(id); db.HashTags.Remove(hashTag); db.SaveChanges(); return(RedirectToAction("Index")); }
public void ParseNone() { const string text = "This text does not contain any HashTags."; var hashTags = HashTag.Parse(text).ToArray(); var length = hashTags.Length; Assert.Equal(0, length); }
public void IsMatch(string input, Token expectedValue) { var Result = new HashTag().IsMatch(new TokenizableStream <char>(input?.ToCharArray() ?? Array.Empty <char>())); Assert.Equal(expectedValue?.EndPosition, Result?.EndPosition); Assert.Equal(expectedValue?.StartPosition, Result?.StartPosition); Assert.Equal(expectedValue?.TokenType, Result?.TokenType); Assert.Equal(expectedValue?.Value, Result?.Value); }
public void ParseSingle() { const string text = "This text contains a #Single HashTag."; var hashTags = HashTag.Parse(text).ToArray(); var length = hashTags.Length; Assert.Equal(1, length); Assert.Equal("Single", hashTags[0].Id); }
public HashTag ParseHashTag(JObject obj) { var hashtag = new HashTag { Indices = ParseIndices(obj["indices"].ToObject <JArray>()), Text = obj["text"].ToString() }; return(hashtag); }
public ActionResult Edit([Bind(Include = "Id,Name")] HashTag hashTag) { if (ModelState.IsValid) { db.Entry(hashTag).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(hashTag)); }
protected string ParseTagToAction(HashTag tag) { StringBuilder sb = new StringBuilder(); var url = Url.Action("Search", "Tags", new { id = tag.Id }); sb.Append("<a href=\""); sb.Append(url); sb.Append("\" >" + HttpUtility.HtmlEncode(tag.Name) + "</a>"); return(sb.ToString()); }
public ActionResult Create([Bind(Include = "Id,Name")] HashTag hashTag) { if (ModelState.IsValid) { db.HashTags.Add(hashTag); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(hashTag)); }
public HashTag EditHashTag(HashTag hash) { var oldHashTag = GetHashTag(hash.HashTagId); HashTag newHashTag = new HashTag(); newHashTag.HashTagId = oldHashTag.HashTagId; newHashTag.HashTagName = oldHashTag.HashTagName; newHashTag.Approved = oldHashTag.Approved; return(newHashTag); }
public async Task <IHttpActionResult> GetHashTag(int id) { HashTag hashTag = await db.HashTags.FindAsync(id); if (hashTag == null) { return(NotFound()); } return(Ok(hashTag)); }
public void ParseMultiple() { const string text = "This text contains #Multiple #HashTags!."; var hashTags = HashTag.Parse(text).ToArray(); var length = hashTags.Length; Assert.Equal(2, length); Assert.Equal("Multiple", hashTags[0].Id); Assert.Equal("HashTags", hashTags[1].Id); }
public HashTag AddHashTag(HashTag hashtag) { hashtag.HashTagId = 5; hashtag.HashTagName = "#fart"; hashtag.Approved = false; var hashtags = GetAllHashtags(); hashtags.Add(hashtag); return(hashtag); }
//finds all the hashtags in the post, stores the new ones, updates the existing ones private bool updateHashTags(CodePost post) { bool added = false; using (ApplicationDbContext db = new ApplicationDbContext()) { //extracts all the tags List <string> tags = new List <string>(); var regex = new Regex(@"(?<=#)\w+"); var matches = regex.Matches(post.content); foreach (Match m in matches) { tags.Add(m.ToString()); } //find and updates, not optimised should try O(1) access for every tag, for now this works foreach (string postTag in tags) { HashTag result = db.tags.ToList().Find(t => t.tag == postTag); //this is a new tag if (result == null) { HashTag newTag = new HashTag(); newTag.count = 0; newTag.tag = postTag; db.posts.Add(post); db.hashTags.Add(new HashTagPost() { Hash = newTag, Post = post }); added = true; continue; } result.count++; db.hashTags.Add(new HashTagPost() { Hash = result, Post = post }); db.posts.Add(post); added = true; } db.SaveChanges(); } return(added); }
public void CanAddHashTag() { HashTag hashtag = new HashTag(5, "#fart", false); var manager = HashTagManagerFactory.Create(); var response = manager.AddHashTag(hashtag); Assert.IsNotNull(response.Hashtag); Assert.IsTrue(response.Success); Assert.AreEqual(5, response.Hashtag.HashTagId); Assert.AreEqual("#fart", response.Hashtag.HashTagName); Assert.IsFalse(response.Hashtag.Approved); }
public Article(string title, string content) { Title = title; Content = content; foreach (var hashTag in HashTag.Parse(content)) { _hashTags.Add(hashTag); } AddDomainEvent(new ArticleCreatedEvent(Title, HashTags.Select(ht => ht.Id))); }
public void Update(string title, string content) { Title = title; Content = content; _hashTags.Clear(); foreach (var hashTag in HashTag.Parse(content)) { _hashTags.Add(hashTag); } }
private void TagItemClick(object sender, ItemClickEventArgs e) { HashTag tagViewModel = new HashTag(((Tag)e.ClickedItem).name); tagViewModel.Init(); this.Frame.Navigate(typeof(ListPage), tagViewModel); }