public ActionResult Create(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var post = this.Data.Posts.GetById(id); if (post == null || post.IsDeleted) { return(this.HttpNotFound()); } var userId = this.User.Identity.GetUserId(); if (post.AuthorId == userId) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var inputModel = new PostReportInputModel { PostId = post.Id }; return(this.PartialView(inputModel)); }
public void AddPostReport_returns_correct_result() { var model = new PostReportInputModel { Description = TestsConstants.TestDescription, PostId = TestsConstants.TestId1, Title = TestsConstants.TestTitle }; var expectedResult = model; var actualResult = this.postReportService.AddPostReport(model, TestsConstants.TestId); Assert.Equal(expectedResult, actualResult); }
public IActionResult Add(PostReportInputModel model) { var post = this.postService.GetPost(model.PostId, 0, this.User, this.ModelState); if (this.ModelState.IsValid) { string authorId = this.accountService.GetUser(this.User).Id; this.postReportService.AddPostReport(model, authorId); return(this.Redirect($"/Post/Details?id={post.Id}")); } else { var result = this.View("Error", this.ModelState); result.StatusCode = (int)HttpStatusCode.BadRequest; return(result); } }
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")); }