示例#1
0
 public PostsComments AddPostComment(PostsComments newPostComment)
 {
     if (newPostComment.post_id != null && newPostComment.post_id != 0 && newPostComment.text.Trim() != "")
     {
         PostsCommentsContext _db = new PostsCommentsContext();
         _db.posts_comments.Add(newPostComment);
         _db.SaveChanges();
         var postCommentId = _db.posts_comments.Select(id => id.id).Max();
         newPostComment.id = postCommentId;
         return newPostComment;
     }
     return null;
 }
示例#2
0
        public ActionResult AddComment()
        {
            if (Session == null || Session["isAuth"] == null || (bool)Session["isAuth"] == false) return RedirectToAction("Login", "Account");

            IPostsContext postsContext = new PostsContext();
            IPostsCommentsContext postsCommentsContext = new PostsCommentsContext();
            IUsersContext usersContext = new UsersContext();
            PostsComments comment = new PostsComments();
            int postId = Convert.ToInt32(Request.Form["postId"]);
            if (postId == 0) return RedirectToAction("Index", "Home");
            comment.post_id = postId;
            comment.user_id = Convert.ToInt32(Request.Form["userId"]);
            comment.text = Request.Form["commentText"];
            string url = Request.Form["postURL"];
            if (Request.Form["commentText"] == null)
                if (url != null)
                    return Redirect(url);
                else
                    return RedirectToAction("Index", "Home");

            comment = postsCommentsContext.AddPostComment(comment);

            return Redirect(url);
        }
示例#3
0
 public bool DellComment(int id)
 {
     PostsCommentsContext _db = new PostsCommentsContext();
     var comment = _db.posts_comments.Where(p => p.id == id).FirstOrDefault();
     if (comment != null)
     {
         _db.posts_comments.Remove(comment);
         _db.SaveChanges();
     }
     return false;
 }
示例#4
0
        public ActionResult PostPage()
        {
            if (Request.QueryString["post"] == null) RedirectToAction("Index", "Home");
            ICategoriesContext catContext = new CategoriesContext();
            IPostsContext postsContext = new PostsContext();
            IPostsCommentsContext postsCommentsContext = new PostsCommentsContext();
            IUsersContext usersContext = new UsersContext();
            User currentUser = new User();
            if (Session != null && Session["isAuth"] != null && (bool)Session["isAuth"] != false)
                currentUser = usersContext.GetUserByLogin(Session["login"].ToString());
            else
                currentUser = null;
            ViewBag.currentUser = currentUser;
            ViewBag.usersContext = usersContext;
            Post post = new Post();
            if (Request.QueryString["post"] == null) return RedirectToAction("Index", "Home");
            post = postsContext.GetPostById(Convert.ToInt32(Request.QueryString["post"]));
            if (post == null) return RedirectToAction("Index", "Home");
            User postUser = usersContext.GetUserById(post.id_user);
            ViewBag.postUser = postUser;
            ViewBag.categories = catContext.GetAllCategories().ToList();
            ViewBag.catContext = catContext;

            IPostImageContext postImageContext = new PostImageContext();
            if (postImageContext.GetImageByPostId(post.id) != null)
                ViewBag.postImage = postImageContext.GetImageByPostId(post.id).image_path;
            ViewBag.post = post;
            IEnumerable<PostsComments> postComments = postsCommentsContext.GetPostsCommentsByPostId(post.id);

            int page = 1;
            if (Request.QueryString["page"] != null)
                page = Convert.ToInt32(Request.QueryString["page"]);

            if (postComments != null)
            {
                List<PostsComments> _postsComments = new List<PostsComments>();
                _postsComments = postComments.ToList();
                List<PostsComments> currComments = new List<PostsComments>(Config.pageItems);
                int pagination = GetPagination(_postsComments.Count);
                int start = 0, end = 0;

                start = (page - 1) * Config.pageItems;
                if (_postsComments.Count == 1) end = 0;
                else
                    if (_postsComments.Count < Config.pageItems) end = _postsComments.Count - 1;
                    else
                        if (page == pagination && _postsComments.Count % Config.pageItems > 0)
                            end = _postsComments.Count - 1;
                        else
                            end = page * Config.pageItems - 1;

                for (int i = start; i <= end; i++)
                {
                    currComments.Add(_postsComments[i]);
                }
                ViewBag.currentPage = page;
                ViewBag.pagination = pagination;
                ViewBag.postComments = currComments;
            }
            else
            {
                page = 0;
            }
            return View();
        }
示例#5
0
        public ActionResult DellPost()
        {
            if (Session == null || Session["isAuth"] == null || (bool)Session["isAuth"] == false) return RedirectToAction("Login", "Account");

            IPostsContext postsContext = new PostsContext();
            IPostsCommentsContext postsCommentsContext = new PostsCommentsContext();
            IUsersContext usersContext = new UsersContext();
            Post post = new Post();
            post = postsContext.GetPostById(Convert.ToInt32(Request.Form["postId"]));
            if (post == null || post.id_user != usersContext.GetUserByLogin(Session["login"].ToString()).id) return RedirectToAction("Index", "Home");
            postsContext.DellPost(post.id);
            string url = "~/Post/PostPage?post=" + post.id;
            return RedirectToAction("Index", "Home");
        }
示例#6
0
        public ActionResult DellComment()
        {
            if (Session == null || Session["isAuth"] == null || (bool)Session["isAuth"] == false) return RedirectToAction("Login", "Account");

            IPostsContext postsContext = new PostsContext();
            IPostsCommentsContext postsCommentsContext = new PostsCommentsContext();
            IUsersContext usersContext = new UsersContext();
            PostsComments comment = new PostsComments();
            comment = postsCommentsContext.GetPostCommentById(Convert.ToInt32(Request.Form["commentId"]));
            if (comment == null) return RedirectToAction("Index", "Home");
            postsCommentsContext.DellComment(comment.id);
            string url = "~/Post/PostPage?post=" + comment.post_id;
            return RedirectToAction("Index", "Home");
        }