Esempio n. 1
0
        public ActionResult ToPage(String postID)
        {
            SQLServerConnector sqlServerConnector = new SQLServerConnector();
            //PageBean pageBean = new PageBean();
            List <PostDataObject> listPosts;
            List <PageBean>       pageNumberList;
            //listPosts = sqlServerConnector.GetPostsList();
            int pageTotalCount = sqlServerConnector.GetTotalCount();

            PageOperation pageOperation = new PageOperation(pageTotalCount);
            int           currentPage   = int.Parse(postID);

            pageNumberList = pageOperation.GetPageNumberList();
            int pageCount          = pageOperation.GetPageCount();
            int startPageNum       = pageOperation.GetStartNumber(currentPage);
            int endPageNum         = pageOperation.GetEndNumber();
            int previousPageNumber = 1;
            int nextPageNumber     = previousPageNumber + int.Parse(postID);

            if (currentPage == 1)
            {
                startPageNum = 0;
            }
            listPosts = sqlServerConnector.GetLimitPostsList(startPageNum.ToString(), "5");

            PostDataViewModel postDataViewModel = new PostDataViewModel();

            postDataViewModel.PostDataList       = listPosts;
            postDataViewModel.PageNumberList     = pageNumberList;
            postDataViewModel.PageCount          = pageCount;
            postDataViewModel.CurrentPage        = currentPage;
            postDataViewModel.StrPageNum         = startPageNum;
            postDataViewModel.EndPageNum         = endPageNum;
            postDataViewModel.PreviousPageNumber = previousPageNumber;
            postDataViewModel.NextPageNumber     = nextPageNumber;
            if (startPageNum == 0)
            {
                postDataViewModel.FirstPage = true;
            }
            else
            {
                postDataViewModel.FirstPage = false;
            }
            if (currentPage == pageNumberList.Count)
            {
                postDataViewModel.LastPage = true;
            }
            else
            {
                postDataViewModel.LastPage = false;
            }


            TempData["postDataViewModel"] = postDataViewModel;

            return(Redirect("BackToAddNewPost"));
        }
Esempio n. 2
0
        public ActionResult AddNewPost()
        {
            SQLServerConnector sqlServerConnector = new SQLServerConnector();
            //PageBean pageBean = new PageBean();
            List <PostDataObject> listPosts;
            List <PageBean>       pageNumberList;
            //listPosts = sqlServerConnector.GetPostsList();
            int pageTotalCount = sqlServerConnector.GetTotalCount();


            PageOperation pageOperation = new PageOperation(pageTotalCount);
            int           currentPage   = 1;

            pageNumberList = pageOperation.GetPageNumberList();
            int pageCount          = pageOperation.GetPageCount();
            int startPageNum       = pageOperation.GetStartNumber(currentPage);
            int endPageNum         = pageOperation.GetEndNumber();
            int previousPageNumber = 1;
            int nextPageNumber     = previousPageNumber + 1;

            listPosts = sqlServerConnector.GetLimitPostsList("0", "5");

            PostDataViewModel postDataViewModel = new PostDataViewModel();

            postDataViewModel.PostDataList       = listPosts;
            postDataViewModel.PageNumberList     = pageNumberList;
            postDataViewModel.PageCount          = pageCount;
            postDataViewModel.CurrentPage        = currentPage;
            postDataViewModel.StrPageNum         = startPageNum;
            postDataViewModel.EndPageNum         = endPageNum;
            postDataViewModel.PreviousPageNumber = previousPageNumber;
            postDataViewModel.NextPageNumber     = nextPageNumber;
            postDataViewModel.FirstPage          = true;
            postDataViewModel.LastPage           = false;

            //ViewBag.ListOfPosts = listPosts;
            //return View(listPosts);
            return(View(postDataViewModel));
        }