Beispiel #1
0
 // DELETE: api/Post/5
 public void Delete(int id)
 {
     _postManager.DeletePost(id);
     //if (!r.Success)
     //{
     //    SetErrorTempData(r.Message);
     //}
 }
        public ActionResult Delete(int id)
        {
            _postManager.DeletePost(id);

            if (Request.IsAjaxRequest())
            {
                var posts = Mapper.Map <IEnumerable <PostViewModel> >(_postManager.GetPosts());
                return(PartialView("_PostsList", posts));
            }

            return(RedirectToAction("Index"));
        }
Beispiel #3
0
 public IActionResult Delete(int id)
 {
     try
     {
         _postManager.DeletePost(id);
         return(Ok());
     }
     catch (ArgumentException ex)
     {
         return(BadRequest(ex));
     }
 }
Beispiel #4
0
        /// <summary>
        /// This method Deletes post.
        /// </summary>
        /// <param name="postId">PostId.</param>
        /// <param name="context">CurrentUserId.</param>
        /// <returns>DeleteResponse.</returns>
        public async Task <DeletePostResponse> DeletePost(string postId, string context)
        {
            var user = await _userManager.GetUser(context);

            var post = await _postManager.GetPostById(postId);

            if (post == null)
            {
                return(new DeletePostResponse()
                {
                    StatusCode = StatusCode.NotFound, ErrorMessage = "Post not found",
                });
            }

            if (user.Id != post.Author.Id)
            {
                return(new DeletePostResponse()
                {
                    StatusCode = StatusCode.PermissionDenied, ErrorMessage = "Unauthorized user to delete post",
                });
            }

            var deleted = await _postManager.DeletePost(post.Id);

            if (!deleted)
            {
                return(new DeletePostResponse()
                {
                    StatusCode = StatusCode.Internal, ErrorMessage = "Internal Error! Couldn't delete post",
                });
            }

            var singleCached = await _cacheProcessor.DeletePostStringAsync(post.Id);

            var cached = await _cacheProcessor.DeleteUserPostStringAsync(user.Id, post);

            if (!cached || !singleCached)
            {
                return(new DeletePostResponse()
                {
                    StatusCode = StatusCode.Internal, ErrorMessage = "Internal Error! Couldn't Cache post"
                });
            }

            return(new DeletePostResponse()
            {
                StatusCode = StatusCode.Ok, Post = ConvertToPostResponse(post),
            });
        }
Beispiel #5
0
        public JsonResult DeletePost(int postId)
        {
            var childIds = new List <int>();

            GetChildPostIds(postId, _postManager.GetAllPost(CurrentTenant.TenantId), childIds);
            if (childIds.Count > 0)
            {
                return(Json(new { result = 0, content = RetechWing.LanguageResources.TenantUI.TenantPost.SubForDelete }, JsonRequestBehavior.AllowGet));
            }
            //SysPost post = _postManager.GetPostById(postId);
            //post.Status = 1;
            //_postManager.UpdatePost(post);
            _postManager.DeletePost(new int[] { postId });
            return(Json(new { result = 1 }, JsonRequestBehavior.AllowGet));
        }
Beispiel #6
0
        public IActionResult Delete(string id)
        {
            if (!ObjectId.TryParse(id, out var objectId))
            {
                return(BadRequest("'Id' parameter is ivalid ObjectId"));
            }

            var oldPost = _postManager.GetPostById(objectId);

            if (oldPost == null)
            {
                return(NotFound());
            }

            _postManager.DeletePost(objectId);
            return(Ok(id));
        }
 public async Task Delete(int id)
 {
     await _posts.DeletePost(id);
 }
Beispiel #8
0
        public async Task <IActionResult> ConfirmDeletePost(PostViewModel post)
        {
            await _postManager.DeletePost(post.Id);

            return(RedirectToAction("Index", "Home"));
        }