public async Task<int> AddComment(int authorId, string text, int idImage) { var imageToAddCommentTo = this.images.GetById(idImage); var author = this.users.GetById(authorId); if (imageToAddCommentTo == null || author == null) { return GlobalConstants.ItemNotFoundReturnValue; } var newComment = new Comment() { Author = author, Dislikes = 0, Likes = 0, PostedOn = DateTime.Now, Text = text }; imageToAddCommentTo.Comments.Add(newComment); await this.images.SaveChangesAsync(); return newComment.Id; }
public static void CommentApproveDeclineToPerson(Models.Comment comment) { // send the email to the person string address = comment.CommenterEmail; if (comment.PersonID != null) { // try and load the person - they may have been deleted var p = Models.Person.LoadByPersonID(comment.PersonID.Value); if (p != null) { address = p.Email; } } if (address.IsBlank()) { return; // no email - cancel this } string body = comment.DeclineReason.FmtPlainTextAsHtml(); string subject = ""; if (comment.Status == Models.Comment.CommentStatus.Approved.ToString()) { subject = "Your New World Auction comment has been approved"; } if (comment.Status == Models.Comment.CommentStatus.Declined.ToString()) { subject = "Your New World Auction comment has been declined"; } SendEmail(address, subject, subject, body); }
/// <summary> /// Populates defaults and opens edit form to add new record /// GET: /Admin/Comment/Create /// </summary> public ActionResult Create() { Breadcrumbs.Current.AddBreadcrumb(3, "Add Comment"); var record = new Models.Comment(); // any default values can be set here or in partial class Comment.InitDefaults() return(View("CommentEdit", record)); }
public Comment AddNew(Comment comment) { this.comments.Add(comment); this.comments.SaveChanges(); return comment; }
public Comment AddComment(Comment toAdd) { toAdd.DateCreated = DateTime.UtcNow; this.comments.Add(toAdd); this.comments.SaveChanges(); return toAdd; }
public CommentViewModel(Comment model, bool isActive) { _model = model; _isActive = isActive; CompositeDisposable.Add( Observable.Merge( Observable.Return(Unit.Default), Observable.FromEventPattern<EventHandler, EventArgs>( handler => _model.Refreshed += handler, handler => _model.Refreshed -= handler).Select(info => Unit.Default)) .Subscribe(unit => Task.Run(() => Refresh(_isActive)))); }
public int Add(string userFromId, string userToId, string comment) { var commentToAdd = new Comment { UserFromId = userFromId, UserToId = userToId, Content = comment, CreatedOn = DateTime.Now }; this.commentsRepo.Add(commentToAdd); this.commentsRepo.SaveChanges(); return commentToAdd.Id; }
public static WhatsNewImageCommentDTO ToWhatsNewComment(Comment comment, User uploadedBy, string filename) { var author = (comment.Deleted) ? null : ToUserDTO(comment.Author); var uploader = ToUserDTO(uploadedBy); return new WhatsNewImageCommentDTO { Author = author, Deleted = comment.Deleted, ID = comment.ID, ImageID = comment.ContextID, ImageUploadedBy = uploader, Text = comment.Text, Filename = filename, }; }
public int AddNew(string comment, string userId, string authorId) { var newComment = new Comment() { Content = comment, CreatedOn = DateTime.UtcNow, FreelancerId = userId, EmployerId = authorId }; this.comments.Add(newComment); this.comments.SaveChanges(); return newComment.Id; }
public Comment CreateComment(int realEstateId, string content, string username, string userId) { var newComment = new Comment() { Content = content, UserName = username, UserId = userId, RealEstateId = realEstateId }; this.comments.Add(newComment); this.comments.SaveChanges(); return newComment; }
public ActionResult CommentsCreate([DataSourceRequest]DataSourceRequest request, CommentEditModel comment) { if (this.ModelState.IsValid) { var newComment = new Comment { Content = comment.Content, ArticleId = comment.ArticleId }; newComment.AuthorId = this.User.Identity.GetUserId(); this.comments.Create(newComment); } return this.Json(new[] { comment }.ToDataSourceResult(request, this.ModelState)); }
public string AddComment(int issueId, string issueText) { if (this.Data.LoggedUser == null) { return Message.NoOneLogged; } if (!this.Data.Issues.ContainsKey(issueId)) { return string.Format(Message.IssueNotFound, issueId); } var comment = new Comment(this.Data.LoggedUser, issueText); this.Data.AddComment(issueId, comment); return string.Format(Message.CommentAddedToIssue, issueId); }
private string Save(Models.Comment record, bool isNew) { bool moveOnToNextItem = false; // send emails (only if DeclineReason has been changed): if (record.Fields.DeclineReason.IsDirty && (record.Status == Comment.CommentStatus.Approved.ToString() || record.Status == Comment.CommentStatus.Declined.ToString())) { if (record.Status == Comment.CommentStatus.Approved.ToString()) { // mark as Approved record.ApprovedByPersonID = Security.LoggedInUserID; record.ApprovedDate = DateTime.Now; } // user email: //Beweb.SiteCustom.Emails.CommentApproveDeclineToPerson(record); moveOnToNextItem = true; } // add any code to update other fields/tables here record.Save(); //record.RebuildCachedComments(); // save subform or related checkboxes here eg record.Lines.Save(); // regardless of what button they clicked - move on to the next item if they declined or approved something if (moveOnToNextItem) { // find the next item var nextCommentId = BewebData.GetValue(new Sql("SELECT TOP(1) CommentId FROM Comment WHERE Status=", Comment.CommentStatus.Submitted.ToString().SqlizeText() , "AND CommentID < ", record.CommentID, " ORDER BY CommentID DESC")); if (nextCommentId.IsBlank()) { nextCommentId = BewebData.GetValue(new Sql("SELECT TOP(1) CommentId FROM Comment WHERE Status=", Comment.CommentStatus.Submitted.ToString().SqlizeText() , "AND CommentID < ", record.CommentID, " ORDER BY CommentID ASC")); if (nextCommentId.IsBlank()) { return("~/Admin/CommentAdmin/Moderate"); } } return("~/Admin/CommentAdmin/Edit/" + nextCommentId); } return(""); }
public static ImageCommentDTO ToImageCommentDTO(Comment comment) { var replies = comment.Replies ?? new List<Comment>(); var replyDtos = replies.Select(ToImageCommentDTO).ToList(); var author = (comment.Deleted) ? null : ToUserDTO(comment.Author); return new ImageCommentDTO { ID = comment.ID, ImageID = comment.ContextID, Author = author, Deleted = comment.Deleted, PostedOn = comment.PostedOn, Replies = replyDtos, Text = comment.Text, Edited = comment.Edited }; }
public Comment Add(int id, string content, string userName) { var userId = this.users.UserIdByUsername(userName); var comment = new Comment { TimePosted = DateTime.Now, PostId = id, Content = content, UserId = userId }; this.comments.Add(comment); this.comments.SaveChanges(); return comment; }
public string AddComment(int issueId, string text) { if (this.Data.CurrentUser == null) { return string.Format("There is no currently logged in user"); } if (!this.Data.IssueById.ContainsKey(issueId)) { return string.Format("There is no issue with ID {0}", issueId); } var issue = this.Data.IssueById[issueId]; var comment = new Comment(this.Data.CurrentUser, text); issue.AddComment(comment); this.Data.CommentByUser[this.Data.CurrentUser].Add(comment); return string.Format("Comment added successfully to issue {0}", issue.Id); }
public IHttpActionResult CreateCommentsByBugId(int id, [FromBody] CommentInputModel commentInputData) { if (commentInputData == null) { return BadRequest("Missing comment data."); } var bug = db.Bugs.Find(id); if (bug == null) { return this.NotFound(); } if (!ModelState.IsValid) { return BadRequest(ModelState); } var currentUserId = User.Identity.GetUserId(); var currentUser = this.db.Users.Find(currentUserId); var comment = new Comment() { BugId = bug.Id, Text = commentInputData.Text, Author = currentUser, PublishDate = DateTime.Now, }; db.Comments.Add(comment); db.SaveChanges(); if (bug.Author == null) { return this.Ok( new { bug.Id, Message = "Added anonymous comment for bug #" + bug.Id + '"' }); } return this.Ok( new { bug.Id, Author = bug.Author.UserName, Message = "Added anonymous comment for bug #" + bug.Id + '"' }); }
protected ActionResult ProcessForm(Models.Comment record) { try { record.UpdateFromRequest(); // read subform or related checkboxes here eg record.Lines.UpdateFromRequest(); Validate(record); if (ModelState.IsValid) { var returnUrl = Save(record, record.IsNewRecord); TempData["info"] = "Comment " + record.GetName() + " saved."; if (returnUrl.IsNotBlank()) { return(Redirect(returnUrl)); } } } catch (UserErrorException e) { ModelState.AddModelError("Record", e.Message); } if (!ModelState.IsValid) { // invalid so redisplay form with validation message(s) return(View("CommentEdit", record)); } else if (Web.Request["SaveAndRefreshButton"] != null) { return(RedirectToEdit(record.ID)); } else if (Web.Request["DuplicateButton"] != null) { var newRecord = new Models.Comment(); newRecord.UpdateFrom(record); newRecord.Save(); TempData["info"] = "Copy of Comment " + record.GetName() + " created. You are now editing the new copy."; return(RedirectToEdit(newRecord.ID)); } else { return(RedirectToReturnPage()); } }
public bool AddComment(int issueId, string userId, string text) { var comment = new Comment() { IssueId = issueId, UserId = userId, Text = text }; try { this.commentsRepository .Add(comment); } catch { return false; } return true; }
public int AddSubComment(int commentId, Comment model, string username) { var currentUserId = this.users.All() .Where(u => u.UserName == username) .Select(u => u.Id) .First(); model.AuthorId = currentUserId; var comment = this.comments.GetById(commentId); if (comment == null) { throw new ArgumentException("Comment cannot be found!"); } comment.SubComments.Add(model); this.SaveChanges(); return model.Id; }
public int Add(Comment model, string username) { var currentUserId = this.users.All() .Where(u => u.UserName == username) .Select(u => u.Id) .First(); model.AuthorId = currentUserId; this.comments.Add(model); this.comments.SaveChanges(); var article = this.newsArticles .All() .FirstOrDefault(a => a.Id == model.NewsArticleId); article.Comments.Add(model); this.newsArticles.Update(article); return model.Id; }
public int Add(int newsArticleId, Comment model, string username) { var currentUserId = this.users.All() .Where(u => u.UserName == username) .Select(u => u.Id) .First(); model.AuthorId = currentUserId; var article = this.newsArticles.GetById(newsArticleId); if (article == null) { throw new ArgumentException("News article cannot be found!"); } this.comments.Add(model); article.Comments.Add(model); this.SaveChanges(); return model.Id; }
public void Update(Comment comment) { this.comments.Update(comment); this.comments.SaveChanges(); }
public void MarkAsDeleted(Comment comment) { this.comments.MarkAsDeleted(comment); this.comments.SaveChanges(); }
public ActionResult Comment(DealComments commentWrapper) { Comment comment = new Comment { CommentString = commentWrapper.NewComment, Date = DateTime.Now, DealId = commentWrapper.Deal.DealID, UserName = userName }; log.Trace("Saving comment {0} for deal {1} from user {2}", commentWrapper.NewComment, commentWrapper.Deal.Title, userName); try { commentDataAccess.SaveDealComment(comment); } catch (CommentDatabaseException) { log.Warn("Could not save comment to database"); } return RedirectToAction("Index", "Home"); }
public string AddComment(int issueId, string commentText) { if (this.Data.LoggedInUser == null) { return NoLoggedInUserMessage; } if (!this.Data.Issues.ContainsKey(issueId)) { return string.Format("There is no issue with ID {0}", issueId + 1); } var issue = this.Data.Issues[issueId]; var comment = new Comment(this.Data.LoggedInUser, commentText); issue.AddComment(comment); this.Data.UserComments[this.Data.LoggedInUser].Add(comment); return string.Format("Comment added successfully to issue {0}", issue.Id); }
public void Delete(Comment toDelete) { this.comments.Delete(toDelete); this.comments.SaveChanges(); }
private void Validate(Models.Comment record) { // add any code to check for validity //ModelState.AddModelError("Record", "Suchandsuch cannot be whatever."); }
public static ThreadPostTitleDTO ToThreadPostTitleDTO(ThreadPostTitle threadTitle, Comment latest, int commentCount = 0) { var author = ToUserDTO(threadTitle.Author); var viewedBy = threadTitle.ViewedBy == null ? new List<UserDTO>() : threadTitle.ViewedBy.Select(ToUserDTO).ToList(); return new ThreadPostTitleDTO { Author = author, CommentCount = commentCount, Deleted = threadTitle.Deleted, ID = threadTitle.ThreadID, IsModified = threadTitle.IsModified, IsPublished = threadTitle.IsPublished, Sticky = threadTitle.Sticky, LatestComment = latest, LastModified = threadTitle.LastModified, CreatedOn = threadTitle.CreatedOn, Title = threadTitle.Title, ViewedBy = viewedBy }; }
public static ThreadPostContentDTO ToThreadPostContentDTO(ThreadPostContent threadContent, Comment latest, int commentCount) { var header = ToThreadPostTitleDTO(threadContent.Header, latest, commentCount); return new ThreadPostContentDTO { Text = threadContent.Text, ThreadID = threadContent.ThreadID, Header = header }; }
public void SeedPostsWithComments(List<User> users, List<PostCategory> categories, List<Pet> pets, List<Region> regions) { for (int i = 0; i < 20; i++) { var post = new Post { Title = $"Post title {i}", Content = $"Some Post content... {i}", User = users[rand.Next(0, users.Count)], PostCategory = categories[rand.Next(0, categories.Count)], Pet = pets[rand.Next(0, pets.Count)], EventTime = DateTime.Now.AddDays(-(rand.Next(0, 15))), Region = regions[rand.Next(0, regions.Count)] }; var commentsCount = rand.Next(0, 10); for (int j = 0; j < commentsCount; j++) { var comment = new Comment { Content = $"Comment content {j}", User = users[rand.Next(0, users.Count)], Post = post }; post.Comments.Add(comment); } this.context.Posts.Add(post); } this.context.SaveChanges(); }
public static ThreadPostCommentDTO ToThreadPostCommentDTO(Comment threadComment) { var replies = threadComment.Replies ?? new List<Comment>(); var repliesDto = replies.Select(ToThreadPostCommentDTO).ToList(); var author = (threadComment.Deleted) ? null : ToUserDTO(threadComment.Author); return new ThreadPostCommentDTO { Author = author, Deleted = threadComment.Deleted, Edited = threadComment.Edited, ID = threadComment.ID, PostedOn = threadComment.PostedOn, Replies = repliesDto, Text = threadComment.Text, ThreadID = threadComment.ContextID }; }
public void Create(Comment comment) { this.comments.Add(comment); this.comments.SaveChanges(); }
public async Task <dynamic> CommentById(string id, [FromBody] CreateCommentRequest requestBody) { var postCollection = MongoWrapper.Database.GetCollection <Models.Post>(nameof(Models.Post)); var postFilterBuilder = new FilterDefinitionBuilder <Models.Post>(); var postFilter = postFilterBuilder.And ( postFilterBuilder.Eq(u => u._id, new ObjectId(id)), GeneralUtils.NotDeactivated(postFilterBuilder) ); var userId = new ObjectId(this.GetCurrentUserId()); var userCollection = MongoWrapper.Database.GetCollection <Models.User>(nameof(Models.User)); var userFilterBuilder = new FilterDefinitionBuilder <Models.User>(); var userFilter = userFilterBuilder.And( GeneralUtils.NotDeactivated(userFilterBuilder), userFilterBuilder.Eq(user => user._id, userId) ); var userProjectionBuilder = new ProjectionDefinitionBuilder <Models.User>(); var userProjection = userProjectionBuilder .Include(m => m._id) .Include(m => m.FullName) .Include(m => m.Avatar) .Include("_t"); var userTask = userCollection.FindAsync(userFilter, new FindOptions <Models.User> { Limit = 1, AllowPartialResults = false, Projection = userProjection }); Models.Comment newComment = new Models.Comment { _id = ObjectId.GenerateNewId(), Commenter = (await userTask).Single(), Likes = new HashSet <ObjectId>(), Text = requestBody.Comentario, }; var postUpdateBuilder = new UpdateDefinitionBuilder <Models.Post>(); var postUpdate = postUpdateBuilder.Push(p => p.Comments, newComment); var updateResult = await postCollection.UpdateOneAsync( postFilter, postUpdate ); if (updateResult.MatchedCount == 0) { Response.StatusCode = (int)HttpStatusCode.NotFound; return(new ResponseBody { Code = ResponseCode.NotFound, Success = false, Message = "Post não encontrado!", }); } return(new ResponseBody { Code = ResponseCode.GenericSuccess, Success = true, Message = "Comentário criado e vinculado com sucesso!", Data = newComment._id, }); }
public string AddComment(int issueId, string commentText) { if (!this.IsUserLogged()) { return Messages.NotLogged; } if (!this.Data.IssuesById.ContainsKey(issueId)) { return string.Format(Messages.NonExistingIssue, issueId); } var issue = this.Data.IssuesById[issueId]; var comment = new Comment(this.Data.LoggedUser, commentText); issue.AddComment(comment); this.Data.CommentsByUser[this.Data.LoggedUser].Add(comment); return string.Format(Messages.CommendAdded, issue.Id); }
/// <summary> /// Save deal comment /// </summary> /// <param name="comment">Comment to save</param> public void SaveDealComment(Comment comment) { string connectionString = ConfigurationManager.ConnectionStrings["ReadWriteDatabase"].ConnectionString; try { using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); using (SqlCommand command = connection.CreateCommand()) { command.CommandText = SaveCommentQuery; command.Parameters.AddWithValue("@dealId", comment.DealId); command.Parameters.AddWithValue("@commentString", comment.CommentString); command.Parameters.AddWithValue("@userName", comment.UserName); command.Parameters.AddWithValue("@date", comment.Date); command.ExecuteNonQuery(); } } } catch (Exception e) { log.Warn(e, "Could not save comment - {0} for user", comment.CommentString, comment.UserName); } }