public ActionResult DeleteConfirmed(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Post post = _post.GetPostByID(id); _post.Delete(post); _post.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <IActionResult> DeletePost(int id) { int userId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); var post = await _repo.GetPostById(id); if (post == null) { return(NotFound()); } if (post.UserId == userId) { _repo.Delete(post); await _tagRepo.TagAmmountDecrementationByPostId(id); await _repo.SaveAll(); return(Ok()); } return(Unauthorized()); }
public async Task <ActionResult> Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } try { var post = await _postRepo.GetPostAsync(id); _postRepo.Delete(post); _postRepo.SaveChanges(); } catch (Exception e) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TempData["deleteError"] = "false"; return(RedirectToAction("Index", "Home")); }
protected override async Task <PostView?> HandleInput(PostDeleteParams input) { using (var connection = database.GetConnection()) { IPostRepo postRepo = database.GetRepo <IPostRepo>(connection); Post?p = await postRepo.FindById(input.PostId); if (p == null) { throw new InvalidOperationException(); } if (!(await this.permissionHandler.HasPermission(input.User, PermissionAction.DeletePost, p))) { throw new AuthorizationException(); } await postRepo.Delete(p); return(postMapper.Map(p)); } }
public HttpResponseMessage Delete(int Id) { using (repo) repo.Delete(Id); return(Request.CreateResponse(HttpStatusCode.OK)); }
public IActionResult Delete(int id) { _postRepo.Delete(id); return(RedirectToAction(nameof(Manage))); }
public void Delete(int id) { _post.Delete(id); }