public async Task <Comment> CreateComment(string text, string userId, Guid taskId, DateTime?reminderDate, int typeCommentId) { ValidationComment.ValidateCommentTextIfIsNullOrEmpty(text); Entities.Task findTask = await this.taskService.FindTaskById(taskId); var currentUser = await this.context.Users .FirstOrDefaultAsync(u => u.Id == userId); Guid commentId = Guid.NewGuid(); var comment = new Comment { Id = commentId, Text = text, UserId = userId, Task = findTask, TaskId = taskId, CreatedOn = DateTime.Now, TypeCommentId = typeCommentId, User = currentUser, ReminderDate = reminderDate }; if (reminderDate != null) { comment.Task.NextActionDate = reminderDate; } await this.context.Comments.AddAsync(comment); await this.context.SaveChangesAsync(); return(comment); }
public IActionResult CommentSubmit(ValidationComment commenting) { if (ModelState.IsValid) { RegisterCommentModel comment = new RegisterCommentModel() { comment = commenting.Comment, user_id = commenting.user_id_comment, quote_id = commenting.quote_id, created_at = DateTime.Now, updated_at = DateTime.Now }; _dbConnector.Execute($"INSERT INTO Comments (comment, quote_id, user_id, created_at, updated_at) VALUES ('{comment.comment}', '{comment.quote_id}', '{comment.user_id}', '{comment.created_at.ToString("yyyy-MM-dd HH:mm:ss")}', '{comment.updated_at.ToString("yyyy-MM-dd HH:mm:ss")}')"); return(RedirectToAction("Quotes")); } else { return(RedirectToAction("Quotes")); } }
public async Task <Comment> EditComment(Guid commentId, string text, string userId, int commentTypeId, DateTime?reminderDate) { ValidationComment.ValidateCommentTextIfIsNullOrEmpty(text); var comment = await this.context.Comments.Include(x => x.Task).FirstOrDefaultAsync(c => c.Id == commentId); if (comment == null) { throw new ArgumentException("Comment does not exist"); } comment.Text = text; comment.TypeCommentId = commentTypeId; comment.ModifiedOn = DateTime.Now; comment.ReminderDate = reminderDate; if (reminderDate != null && comment.ReminderDate != reminderDate) { comment.Task.NextActionDate = reminderDate; } this.context.Update(comment); await this.context.SaveChangesAsync(); return(comment); }