public IActionResult AddComment([FromBody] JObject json) { string authorId = json.GetValue("authorId").ToString(); string linkId = json.GetValue("linkId").ToString(); string body = json.GetValue("body").ToString(); Link l = _context.Link.Where(link => link.Id == linkId).FirstOrDefault(); ApplicationUser user = _context.ApplicationUser.Where(u => u.Id == authorId).FirstOrDefault(); try { CommentLink result = _commentLinkRepo.AddComment(new CommentLink() { Body = body, Date = DateTime.Now, AuthorId = authorId, LinkId = linkId, Rate = 0 }); return(new JsonResult(new CommentLinkViewModel { Id = result.Id, Body = result.Body, Date = result.Date, Rating = result.Rate, AuthorId = result.AuthorId, LinkId = result.LinkId, AuthorName = _context.ApplicationUser.Where(au => au.Id == result.AuthorId).FirstOrDefault().UserName })); } catch { return(new JsonResult(new { error = "Error" })); } }
public static List <CommentLink> GetLinks(this CommentLink commentLink) { var links = new List <CommentLink>(); CommentLinkType.GetTypes(commentLink.CommentStatus).ForEach(t => links.Add(new CommentLink { CommentID = commentLink.CommentID, PostID = commentLink.PostID, LinkText = t.Description, ActionMethod = "CommentPartial", CommentStatus = t.Status })); return(links); }
public string CommentPartialReplacer(CommentLink commentLink) { if (Request.IsAjaxRequest()) { _commentRepository.UpdateCommentStatus(commentLink.CommentID, commentLink.CommentStatus); return("Comment status has been updated"); } throw new NotSupportedException("Not an ajax request"); }
public ActionResult CommentPartial(CommentLink commentLink) { if (Request.IsAjaxRequest()) { _commentRepository.UpdateCommentStatus(commentLink.CommentID, commentLink.CommentStatus); var links = commentLink.GetLinks(); return(PartialView("CommentPartial", links)); } throw new NotSupportedException("Not an ajax request"); }
public IActionResult DeleteComment(string id) { CommentLink comment = _commentLinkRepo.GetComment(id); if (comment != null) { return(new JsonResult(_commentLinkRepo.Delete(comment))); } return(null); }
internal Uri Create(string title, string content) { CommentLink.Click(); return(new Uri(CommentLink.GetAttribute("href"))); Comment.SendKeys("lsdkkhfjsdhfudshf"); Author.SendKeys("melilia"); Email.SendKeys("*****@*****.**"); MoveToElement(_browser, By.CssSelector("nav.navigation")); Submit.Click(); }
public CommentLink AddComment(CommentLink c) { try { _context.CommentLink.Add(c); _context.SaveChanges(); return(c); } catch { return(null); } }
public string Delete(CommentLink comment) { _context.CommentLink.Remove(comment); _context.SaveChanges(); return(comment.Id); }