public ActionResult DeleteComment(int id) { SuggestionComment comment = db.SuggestionComments.Find(id); int suggestionId = comment.SuggestionId; db.SuggestionComments.Remove(comment); db.SaveChanges(); return(RedirectToAction("Details", new { id = suggestionId })); }
public virtual SuggestionCommentResource BuildCommentResource(SuggestionComment comment) { var resource = new SuggestionCommentResource(); resource.CommentId = comment.Id; resource.Comment = comment.Comment; resource.DateTimeText = comment.LastUpdateDateTimeUtc.ToString("s"); resource.PublicNameOfCommentAuthor = comment.CommentingMember.PublicName; resource.IsSupportive = comment.CommentIsSupportingSuggestion; resource.Censored = comment.IsCensored; resource.PictureUrl = comment.CommentingMember.MemberAuth0Users.First().Auth0User.PictureUrl; return(resource); }
public ActionResult EditComment([Bind(Include = "SuggestionId, Description, CreatingTime, UserId, CommentId")] SuggestionCommentView comment) { SuggestionComment suggestionComment = db.SuggestionComments.Find(comment.CommentId); suggestionComment.Description = comment.Description; if (ModelState.IsValid) { db.Entry(suggestionComment).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Details", new { id = comment.SuggestionId })); } return(RedirectToAction("Details", new { id = comment.SuggestionId, message = "Your comment is not editted successfully" })); }
public ActionResult CreateComment([Bind(Include = "SuggestionId, Description")] SuggestionComment comment) { comment.CreatingTime = DateTime.Now; comment.UserId = db.users.Where(u => u.Email == User.Identity.Name).Single().Id;; if (ModelState.IsValid) { db.SuggestionComments.Add(comment); db.SaveChanges(); return(RedirectToAction("Details", new { id = comment.SuggestionId })); } return(RedirectToAction("Details", new { id = comment.SuggestionId, message = "Your comment is not submitted successfully" })); }
public void WhenUserIsNotOwnerOfTheSuggestionComment_ShouldThrowAUnauthorizedException() => ShouldThrowDuringTheValidation <UnauthorizedException>(() => { AddTheValidSuggestion(); var suggestion = _dbContext.Suggestions.First(); var comment = suggestion.Comments.First(); var newComment = new SuggestionComment { Id = comment.Id, CreatedBy = "other user id" }; _repository.RemoveUserComment(suggestion.Id, comment.Id, comment.CreatedBy); _repository.AddComment(suggestion.Id, newComment); _dbContext.SaveChanges(); });
public ResponseResource CommentOnSuggestion(IPrincipal principal, CreateSugestionCommentRequest request) { var suggestion = GetGuaranteedSuggestion(request.SuggestionId); var member = _dependencies.OrganisationService.GetGuaranteedMember(principal, suggestion.AuthorMember.OrganisationId); var comment = new SuggestionComment(); comment.CommentingMemberId = member.Id; comment.Comment = request.Comment; comment.CommentIsSupportingSuggestion = request.Supporting; comment.CommentingMember = member; comment.LastUpdateDateTimeUtc = DateTime.UtcNow; comment.Suggestion = suggestion; comment.IsCensored = member.Moderated; comment.SuggestionId = suggestion.Id; _dependencies.StorageService.SetOf <SuggestionComment>().Add(comment); _dependencies.StorageService.SaveChanges(); return(new ResponseResource()); }