Exemplo n.º 1
0
        public ActionResult <PostModel> DeletePostByIf(DeletePostModel postModel)
        {
            interfaceOperation = true;
            var creator = usersApi.FindIdUserByName(postModel.Creator);

            if (creator == -1)
            {
                return(RedirectToAction(nameof(MessagePage), new { message = "No such user!" }));
            }
            var post = postsApi.GetPostById(postModel.Id);

            if (post == null)
            {
                return(RedirectToAction(nameof(MessagePage), new { message = "No such post!" }));
            }
            if (post.Author != creator)
            {
                var permission = permissionsApi.GetPermissionForUserByGroup(creator, post.Group);
                if (permission == null)
                {
                    return(RedirectToAction(nameof(MessagePage), new { message = "No information about permission for this group!" }));
                }
                if (permission.Operation != Operation.Admin)
                {
                    return(RedirectToAction(nameof(MessagePage), new { message = "No permission!" }));
                }
            }
            var result = postsApi.DeletePost(postModel.Id);

            return(RedirectToAction(nameof(PartOfPosts), new { name = postModel.Group, page = 0 }));
        }
Exemplo n.º 2
0
        public IActionResult ConfirmDelete(DeletePostModel model)
        {
            var post = _postService.GetById(model.PostId);

            _postService.Delete(model.PostId);

            return(RedirectToAction("Index", "Forum", new { id = post.Forum.Id }));
        }
Exemplo n.º 3
0
        public ActionResult DeletePostIf(int id, string group)
        {
            interfaceOperation = true;
            var post = new DeletePostModel {
                Id = id, Group = group
            };

            return(View(post));
        }
        public IActionResult Delete(int id)
        {
            var post  = _postService.GetById(id);
            var model = new DeletePostModel
            {
                PostId      = post.Id,
                PostAuthor  = post.User.UserName,
                PostContent = post.Content
            };

            return(View(model));
        }
Exemplo n.º 5
0
        public async Task <string> DeleteTruckstogo([FromBody] DeletePostModel deleteModel)
        {
            var headers        = new Dictionary <string, string>();
            var tokenGenerated = HttpContext.Session.GetHmacToken();

            headers.Add("X-Hmac", tokenGenerated);
            headers.Add("X-PublicKey", HttpContext.Session.GetUserPublicKey());
            string queryStr = _queryCreater.GetQueryStringFromObject(deleteModel);
            var    response = await HttpClientRequestFactory.Get("http://proxy.mansis.co.za:18443/SlimProxyBoot.php?" + queryStr, headers);

            var data = response.Content.ReadAsStringAsync().Result;

            return(data.ToString());
        }
Exemplo n.º 6
0
        public ActionResult DeletePost(long?id)
        {
            if (!id.HasValue)
            {
                return(View("NotAvailable"));
            }

            if (CurrentUser == null)
            {
                return(View("NotAuthorized"));
            }

            Post p = this.Forums.GetPost(id.Value);

            if (p == null || p.IsDeleted)
            {
                return(View("NotFound"));
            }

            Thread t = p.Thread;

            long firstPostId = t.Posts.Where(post => post.IsDeleted == false).OrderBy(post => post.CreateDate).FirstOrDefault().PostID;
            long lastPostId  = t.Posts.Where(post => post.IsDeleted == false).OrderByDescending(post => post.CreateDate).FirstOrDefault().PostID;

            Forum f = t.Forum;

            ForumAccess access = this.Security.GetUserForumAccess(CurrentUser, f);

            if (!access.CanPost || (!access.CanModerate && p.PostID != lastPostId))
            {
                return(View("NotAuthorized"));
            }

            var del = new DeletePostModel
            {
                Post       = p,
                UserAccess = access,
                FirstPost  = (p.PostID == firstPostId),
            };

            return(View("DeletePost", del));
        }