public async Task <ActionResult <CommentReport> > AddCommentReport(CommentReport commentReport) { await _ICommentReportsUI.AddCommentReport(commentReport); return(Ok()); }
public async Task <int> ReportComment(int?id, string text) { if (id == null) { return(0); } Comment comment = await _db.Comments.FindAsync(id); User currentUser = await _userManager.GetUserAsync(User); if (comment == null || currentUser.Id == comment.UserId || string.IsNullOrEmpty(text.Trim())) { return(0); } CommentReport report = new CommentReport() { Date = DateTime.Now, ReportFromId = currentUser.Id, CommentId = (int)id, Reason = text }; _db.CommentReports.Add(report); await _db.SaveChangesAsync(); return(1); }
public void ReportComment(CommentReport report) { string query = @"INSERT INTO CommentReports (CommentID, ReporterID, Reason, DateCreated) values(@CommentID, @ReporterID, @Reason, @DateCreated)"; _connection.Execute(query, new { report.CommentID, report.ReporterID, report.Reason, report.DateCreated }); }
public ActionResult ReportComment([FromBody] ReportCommand model) { if (_context.Users.Find(model.SenderId) == null) { return(NotFound("Could not find sender user with this id")); } if (_context.Comments.Find(model.ReportObjectId) == null) { return(NotFound("Could not find comment with this id")); } var commentReport = new CommentReport(); commentReport.Reason = model.Reason; commentReport.Explanation = model.Explanation; commentReport.DateTime = DateTime.Now.AddHours(2); commentReport.CommentId = model.ReportObjectId; commentReport.SenderId = model.SenderId; try { _context.CommentReports.Add(commentReport); _context.SaveChanges(); return(Ok()); } catch (Exception) { return(BadRequest("An error occured while trying to add comment report.")); } }
protected void btnReportComment_Click(object sender, EventArgs e) { var currentUser = _authenticationService.GetAuthenticatedUser(); var commentId = int.Parse(commentID.Value); if (currentUser == null) { redirectToLogin(Request.RawUrl); } var reason = ""; if (listReportComment.SelectedIndex != -1) { reason = listReportComment.SelectedItem.Value; } if (txtOtherReason.Text.Length > 0) { reason = txtOtherReason.Text; } var report = new CommentReport(commentId, currentUser.Id, reason, DateTime.Now); _commentService.ReportComment(report); listReportComment.SelectedIndex = -1; txtOtherReason.Text = ""; }
public async Task <bool> RemoveCommentReport(string reportId) { CommentReport report = (await this.commentReportReposetory.Get(report => report.Id == reportId).ConfigureAwait(false)).SingleOrDefault(); if (report == null) { return(false); } await this.commentReportReposetory.Remove(report).ConfigureAwait(false); return(true); }
public async Task AddCommentReport(CommentReport commentReport) { try { _context.CommentReports.Add(commentReport); await _context.SaveChangesAsync(); } catch (Exception) { throw; } }
public CommentReport IsCommentReported(int id, string email) { CommentReport commentReport = new CommentReport() { CommentId = id, Email = email, Reported = true }; _commentReportRepository.SaveReport(commentReport); return(commentReport); }
public async Task <int> AddressCommentReport(CommentReport postReport) { var query = $@"UPDATE juniro.CommentReports SET AddressedById = '{postReport.AddressedById}', AddressedMessage = '{postReport.AddressedMessage}', AddresDateTime = '{postReport.AddresDateTime}' WHERE Id = {postReport.Id} AND PostId = '{postReport.PostId}"; using (var connection = new MySqlConnection(_mysqlConnectionString)) { return(await connection.ExecuteAsync(query, new { postReport })); } }
public async Task <bool> CommentReportDecision(string reportId, bool isHideComment, bool isDeleteComment, bool isBanUser, bool isDeletePost, bool isHidePost) { CommentReport report = (await this.commentReportReposetory.Get(report => report.Id == reportId, new string[] { "Comment", "Comment.Post" }).ConfigureAwait(false)).SingleOrDefault(); if (report == null || report.Comment == null || report.Comment.Post == null) { return(false); } if (isBanUser) { bool result = await this.accountService.SetBanRole(report.Comment.UserId).ConfigureAwait(false); if (!result) { return(false); } } if (isDeletePost) { await this.postService.DeletePost(report.Comment.Post.Id, report.Comment.Post).ConfigureAwait(false); return(true); } if (isHidePost) { bool result = await this.postService.HidePost(report.Comment.Post.Id).ConfigureAwait(false); if (!result) { return(false); } } if (isDeleteComment) { await this.postService.RemoveComment(report.CommentId).ConfigureAwait(false); return(true); } if (isHideComment) { bool result = await this.postService.HideComment(report.CommentId).ConfigureAwait(false); if (!result) { return(false); } } return(true); }
public async Task <IActionResult> DeleteCommentReport(int?id) { if (id == null) { return(NotFound()); } CommentReport report = await _db.CommentReports.FindAsync(id); if (report == null) { return(NotFound()); } _db.CommentReports.Remove(report); await _db.SaveChangesAsync(); return(RedirectToAction("CommentReports")); }
public async Task <int> ReportComment(CommentReport reportEntity) { using (var connection = new MySqlConnection(_mysqlConnectionString)) { reportEntity.Id = await connection.QuerySingleAsync <int>( $@"INSERT INTO juniro.CommentReports( EntityId, Message, ReportedByUserId, CreatedDate) VALUES ( @{nameof(reportEntity.EntityId)}, @{nameof(reportEntity.Message)}, @{nameof(reportEntity.AddressedMessage)}, @{nameof(reportEntity.CreatedDate)}); SELECT LAST_INSERT_ID();", reportEntity); } return(reportEntity.Id); }
public ActionResult Create(CommentReportInputModel inputModel) { if (inputModel != null && this.ModelState.IsValid) { var userid = this.User.Identity.GetUserId(); var report = new CommentReport { AuthorId = userid, CommentId = inputModel.CommentId, Description = inputModel.Description }; this.Data.CommentReports.Add(report); this.Data.SaveChanges(); return(this.JsonSuccess("Successfully created report.")); } return(this.JsonError("Description is required")); }
public async Task <HttpResponseMessage> InitiateCommentReport( [FromBody] InitiateCommentReportViewModel parameters) { try { #region Parameters validation // Parameters haven't been initialized. if (parameters == null) { parameters = new InitiateCommentReportViewModel(); Validate(parameters); } // Parameters are invalid. if (!ModelState.IsValid) { return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState)); } #endregion #region Comment find // Comment find conditions build. var findCommentViewModel = new SearchCommentViewModel(); findCommentViewModel.Id = parameters.CommentIndex; // Search all comments from database. var comments = UnitOfWork.RepositoryComments.Search(); comments = UnitOfWork.RepositoryComments.Search(comments, findCommentViewModel); // Search the first matched comment. var comment = await comments.FirstOrDefaultAsync(); if (comment == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, HttpMessages.CommentNotFound)); } #endregion #region Request identity search // Search account which sends the current request. var account = _identityService.FindAccount(Request.Properties); if (account == null) { throw new Exception("No account information is attached into current request."); } #endregion #region Record initialization var commentReport = new CommentReport(); commentReport.CommentIndex = comment.Id; commentReport.CommentOwnerIndex = comment.OwnerIndex; commentReport.CommentReporterIndex = account.Id; commentReport.Body = comment.Content; commentReport.Reason = parameters.Reason; commentReport.Created = _timeService.DateTimeUtcToUnix(DateTime.UtcNow); // Save record into database. commentReport = UnitOfWork.RepositoryCommentReports.Insert(commentReport); // Commit changes to database. await UnitOfWork.CommitAsync(); #endregion return(Request.CreateResponse(HttpStatusCode.OK, commentReport)); } catch (Exception exception) { _log.Error(exception.Message, exception); return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } }
public Task AddCommentReport(CommentReport commentReport) { return(_ICommentReportsBL.AddCommentReport(commentReport)); }
public CommentReport SaveReport(CommentReport commentReport) { _db.CommentReports.Add(commentReport); _db.SaveChanges(); return(commentReport); }