public ActionResult Create([Bind(Include = "Post_Id,Content,User_Id,ID,AddingDate,Votes,EditingDate")] Comment comment) { comment.Votes = 0; comment.AddingDate = DateTime.Now; //load from users: var nullableUserID = _user.GetIDOfCurrentlyLoggedUser(); if (nullableUserID == null) { return(RedirectToAction("LogIn", "User")); } else { //int? to int comment.User_Id = nullableUserID.GetValueOrDefault(); } comment.EditingDate = null; var result = new { result = true }; if (ModelState.IsValid) { _comm.Add(comment); _comm.SaveChanges(); MatchCollection matches = Regex.Matches(comment.Content, @"\B(\#[a-zA-Z0-9-,_]+\b)"); //wpis ID first important foreach (var tagName in matches) { var tag = _tag.GetTagByName(tagName.ToString()); if (tag == null) { tag = new Tag(); tag.TagName = tagName.ToString().ToLower(); //id radnom _tag.Add(tag); _tag.SaveChanges(); } var commTag = new CommentTag() { Tag_Id = tag.Tag_Id, Comment_Id = comment.Comment_Id }; _comm.Add(commTag); _comm.SaveChanges(); } return(RedirectToAction("Index", "Post")); } return(RedirectToAction("Index", "Post")); }
private Tag Create(TagViewModel item) { Tag t = Mapper.Map <TagViewModel, Tag>(item); _repository.Add(t); return(t); }
public int Add(Tag tag) { if (_tagrepo.Exist(tag.Name)) { return(0); } return(_tagrepo.Add(tag)); }
public ActionResult Create([Bind(Include = "Content")] Post post) { post.AddingDate = DateTime.Now; var loggedUserId = _user.GetIDOfCurrentlyLoggedUser(); post.User_Id = loggedUserId.Value; if (ModelState.IsValid) { _post.Add(post); _post.SaveChanges(); MatchCollection matches = Regex.Matches(post.Content, @"\B(\#[a-zA-Z0-9-,_]+\b)"); //postId first important foreach (var tagName in matches) { var tag = _tag.GetTagByName(tagName.ToString().ToLower()); if (tag == null) { tag = new Tag(); tag.TagName = tagName.ToString().ToLower(); _tag.Add(tag); _tag.SaveChanges(); } var postTag = new PostTag() { Tag_Id = tag.Tag_Id, Post_Id = post.Post_Id }; _post.Add(postTag); _post.SaveChanges(); } return(RedirectToAction("Index")); } return(RedirectToAction("Index")); }
public IActionResult Post(string value) { _tagRepo.Add(value); return(Ok()); }