Example #1
0
        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"));
        }
Example #2
0
        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());
        }
Example #3
0
        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"));
        }
Example #4
0
        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));
            }
        }
Example #5
0
 public HttpResponseMessage Delete(int Id)
 {
     using (repo)
         repo.Delete(Id);
     return(Request.CreateResponse(HttpStatusCode.OK));
 }
Example #6
0
 public IActionResult Delete(int id)
 {
     _postRepo.Delete(id);
     return(RedirectToAction(nameof(Manage)));
 }
Example #7
0
 public void Delete(int id)
 {
     _post.Delete(id);
 }