public async Task <ActionResult <PostReport> > AddPostReport(PostReport postReport) { await _iPostReportUI.AddPostReport(postReport); return(Ok()); }
private void SeedDb() { this.TruncatePostReportsTable(); this.TruncateReplyReportsTable(); this.TruncateUsersTable(); this.TruncateQuoteReportsTable(); var user = new ForumUser { Id = TestsConstants.TestId, UserName = TestsConstants.TestUsername1 }; this.dbService.DbContext.Users.Add(user); this.dbService.DbContext.SaveChanges(); var replyReport = new ReplyReport { Author = user, AuthorId = user.Id }; var postReport = new PostReport { Author = user, AuthorId = user.Id }; var quoteReport = new QuoteReport { Author = user, AuthorId = user.Id }; this.dbService.DbContext.ReplyReports.Add(replyReport); this.dbService.DbContext.PostReports.Add(postReport); this.dbService.DbContext.QuoteReports.Add(quoteReport); this.dbService.DbContext.SaveChanges(); }
public async Task <int> ReportPost(int?id, string text) { if (id == null) { return(0); } Post post = await _db.Posts.FindAsync(id); User currentUser = await _userManager.GetUserAsync(User); if (post == null || currentUser.Id == post.UserId || string.IsNullOrEmpty(text.Trim())) { return(0); } PostReport report = new PostReport() { Date = DateTime.Now, ReportFromId = currentUser.Id, PostId = (int)id, Reason = text }; _db.PostReports.Add(report); await _db.SaveChangesAsync(); return(1); }
public ActionResult ReportPost([FromBody] ReportCommand model) { if (_context.Users.Find(model.SenderId) == null) { return(NotFound("Could not find sender user with this id")); } if (_context.Posts.Find(model.ReportObjectId) == null) { return(NotFound("Could not find post with this id")); } var postReport = new PostReport(); postReport.Reason = model.Reason; postReport.Explanation = model.Explanation; postReport.DateTime = DateTime.Now.AddHours(2); postReport.PostId = model.ReportObjectId; postReport.SenderId = model.SenderId; try { _context.PostReports.Add(postReport); _context.SaveChanges(); return(Ok()); } catch (Exception) { return(BadRequest("An error occured while trying to add post report.")); } }
public async Task <bool> PostReportDecision(string reportId, bool isBanUser, bool isDeletePost, bool isHidePost) { PostReport report = (await this.adminReposetry.Get(report => report.Id == reportId, new string[] { "Post.User" }).ConfigureAwait(false)).SingleOrDefault(); if (report == null || report.Post == null) { return(false); } if (isBanUser) { bool result = await this.accountService.SetBanRole(report.Post.UserId, report.Post.User).ConfigureAwait(false); if (!result) { return(false); } } if (isDeletePost) { await this.postService.DeletePost(report.PostId, report.Post).ConfigureAwait(false); return(true); } if (isHidePost) { bool result = await this.postService.HidePost(report.Post.Id).ConfigureAwait(false); if (!result) { return(false); } } return(true); }
private void SeedDb() { this.TruncatePostReportsTable(); this.TruncatePostsTable(); this.TruncateUsersTable(); var author = new ForumUser { Id = TestsConstants.TestId }; this.dbService.DbContext.Users.Add(author); this.dbService.DbContext.SaveChanges(); var post = new Models.Post { Id = TestsConstants.TestId1, Author = author, AuthorId = author.Id }; this.dbService.DbContext.Posts.Add(post); this.dbService.DbContext.SaveChanges(); var firstPostReport = new PostReport { Id = TestsConstants.TestId, Author = author, AuthorId = author.Id }; this.dbService.DbContext.PostReports.Add(firstPostReport); this.dbService.DbContext.SaveChanges(); for (int i = 0; i < 5; i++) { var postReport = new PostReport(); this.dbService.DbContext.PostReports.Add(postReport); this.dbService.DbContext.SaveChanges(); } }
public async Task CreateMethodShouldAddRightPostReportInDatabase(string description, int postId) { var options = new DbContextOptionsBuilder <ForumDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var db = new ForumDbContext(options); var dateTimeProvider = new Mock <IDateTimeProvider>(); dateTimeProvider.Setup(dtp => dtp.Now()).Returns(new DateTime(2020, 3, 27)); var postReportsService = new PostReportsService(db, null, dateTimeProvider.Object); var authorId = Guid.NewGuid().ToString(); await postReportsService.CreateAsync(description, postId, authorId); var expected = new PostReport { Id = 1, Description = description, PostId = postId, AuthorId = authorId, CreatedOn = dateTimeProvider.Object.Now(), }; var actual = await db.PostReports.FirstOrDefaultAsync(); actual.Should().BeEquivalentTo(expected); }
public ActionResult DeleteConfirmed(int id) { PostReport postReport = db.PostReport.Find(id); db.PostReport.Remove(postReport); db.SaveChanges(); return(RedirectToAction("Index")); }
void OnClick() { GameObject g = GameObject.Find("warning_block"); g.transform.position = new Vector3(0, 0, 0); PostReport Report = g.GetComponentInChildren <PostReport> (); Report.Post_Id = Post_Id; }
public async Task <ActionResult <PostReport> > PostPostReport(PostReport postReport) { postReport.ReportedAt = DateTime.Now; _context.PostReports.Add(postReport); await _context.SaveChangesAsync(); return(CreatedAtAction("GetPostReport", new { id = postReport.Id }, postReport)); }
public ActionResult Edit([Bind(Include = "ReportID,PetPostID,Report")] PostReport postReport) { if (ModelState.IsValid) { db.Entry(postReport).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PetPostID = new SelectList(db.PetPost, "PetPostID", "PetDetails", postReport.PetPostID); return(View(postReport)); }
public async Task <bool> RemovePostReport(string reportId) { PostReport report = (await this.adminReposetry.Get(report => report.Id == reportId).ConfigureAwait(false)).SingleOrDefault(); if (report == null) { return(false); } await this.adminReposetry.Remove(report).ConfigureAwait(false); return(true); }
public async Task AddPostReport(PostReport postReport) { try { _context.PostReports.Add(postReport); await _context.SaveChangesAsync(); } catch (Exception) { throw; } }
public ActionResult Create([Bind(Include = "ReportID,PetPostID,Report")] PostReport postReport) { if (ModelState.IsValid) { db.PostReport.Add(postReport); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PetPostID = new SelectList(db.PetPost, "PetPostID", "PetDetails", postReport.PetPostID); return(View(postReport)); }
public async Task AddReport(string authorId, string postId, ReportReason reason) { var report = new PostReport() { AuthorId = authorId, PostId = postId, ReportReason = reason, }; await this.dbContext.PostReports.AddAsync(report); await this.dbContext.SaveChangesAsync(); }
public async Task <int> AddressPostReport(PostReport postReport) { var query = $@"UPDATE juniro.PostReports SET AddressedById = '{postReport.AddressedById}', AddressedMessage = '{postReport.AddressedMessage}', AddresDateTime = '{postReport.AddresDateTime}' WHERE Id = {postReport.Id}"; using (var connection = new MySqlConnection(_mysqlConnectionString)) { return(await connection.ExecuteAsync(query, new { postReport })); } }
public void AddReport(string authorId, string postId, ReportReason reason) { var report = new PostReport() { AuthorId = authorId, PostId = postId, ReportReason = reason, }; var post = this.postRepository.All().FirstOrDefault(x => x.Id == postId); post?.PostReports.Add(report); this.postRepository.SaveChangesAsync().GetAwaiter().GetResult(); }
// GET: PostReports/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PostReport postReport = db.PostReport.Find(id); if (postReport == null) { return(HttpNotFound()); } return(View(postReport)); }
public async Task CreateAsync(string description, int postId, string authorId) { var postReport = new PostReport { Description = description, CreatedOn = this.dateTimeProvider.Now(), PostId = postId, AuthorId = authorId }; await this.db.PostReports.AddAsync(postReport); await this.db.SaveChangesAsync(); }
// GET: PostReports/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PostReport postReport = db.PostReport.Find(id); if (postReport == null) { return(HttpNotFound()); } ViewBag.PetPostID = new SelectList(db.PetPost, "PetPostID", "PetDetails", postReport.PetPostID); return(View(postReport)); }
public async Task <IActionResult> DeletePostReport(int?id) { if (id == null) { return(NotFound()); } PostReport report = await _db.PostReports.FindAsync(id); if (report == null) { return(NotFound()); } _db.PostReports.Remove(report); await _db.SaveChangesAsync(); return(RedirectToAction("PostReports")); }
public ActionResult Create(PostReportInputModel input) { if (input != null && this.ModelState.IsValid) { var userId = this.User.Identity.GetUserId(); var report = new PostReport { PostId = input.PostId, AuthorId = userId, Description = input.Description }; this.Data.PostReports.Add(report); this.Data.SaveChanges(); return(this.JsonSuccess("Successfully created report.")); } return(this.JsonError("Description is required")); }
public async Task <int> ReportPost(PostReport reportEntity) { using (var connection = new MySqlConnection(_mysqlConnectionString)) { var queryResult = await connection.QueryAsync <CommentReport>(@"SELECT * FROM juniro.commentreports where ReportedByUserId = @userId"); reportEntity.Id = await connection.QuerySingleAsync <int>( $@"INSERT INTO juniro.PostReports( 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 PostReport get_draft_report(string user) { var drafts = new PostReport(); return(drafts.GetDraftReport(user)); }
public IHttpActionResult CreateReport(PostReport report) { var postReport = new PostReport(); return(Ok(postReport.CreateReport(report))); }
/// <summary> /// Initiate a post report with given information. /// </summary> /// <returns></returns> public async Task <HttpResponseMessage> InitiatePostReport([FromBody] InitiatePostReportViewModel parameters) { try { #region Parameters validation // Parameters haven't been initialized.. if (parameters == null) { // Initiate the parameters. parameters = new InitiatePostReportViewModel(); Validate(parameters); } // Parameters are invalid. if (!ModelState.IsValid) { return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState)); } #endregion #region Search post report // Search all posts. var posts = UnitOfWork.RepositoryPosts.Search(); // Conditions construction. var findPostViewModel = new SearchPostViewModel(); findPostViewModel.Id = parameters.PostIndex; // Search the post information. var post = await UnitOfWork.RepositoryPosts.Search(posts, findPostViewModel).FirstOrDefaultAsync(); // Post is not found. if (post == null) { _log.Error($"There is no post (ID: {parameters.PostIndex}) has been found in database"); return(Request.CreateErrorResponse(HttpStatusCode.NotFound, HttpMessages.PostNotFound)); } #endregion #region Requester search. // Search the request sender. var requester = _identityService.FindAccount(Request.Properties); // Requester is not found. if (requester == null) { _log.Error("No requester is found in the request."); return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, HttpMessages.RequestIsUnauthenticated)); } #endregion #region Report initialization. var postReport = new PostReport(); postReport.PostIndex = post.Id; postReport.PostOwnerIndex = post.OwnerIndex; postReport.PostReporterIndex = requester.Id; postReport.Body = post.Body; postReport.Reason = parameters.Reason; postReport.Created = _timeService.DateTimeUtcToUnix(DateTime.UtcNow); // Initiate post report into database. postReport = UnitOfWork.RepositoryPostReports.Insert(postReport); // Commit changes. #endregion // Tell the client about the post report. return(Request.CreateResponse(HttpStatusCode.OK, postReport)); } catch (Exception exception) { _log.Error(exception.Message, exception); return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } }
public Task AddPostReport(PostReport postReport) { return(_iPostReportDAL.AddPostReport(postReport)); }