// GET: Home public ActionResult ViewText(int blocksPerPage = 6, int stringsPerBlock = 3) { if (blocksPerPage <= 0 || stringsPerBlock <= 0) { ViewBag.ErrorMessage = "Parameters can not be negative!"; return(View("_Error", new ViewTextLayoutParameters { BlockPerPage = blocksPerPage, StringsPerBlock = stringsPerBlock } )); } var path = HostingEnvironment.MapPath("~/Content/data.txt"); var strings = FileStringsGetter.GetStrings(path); //last parameter is zero to return first page. var page = PageBuilder.GetPage(strings, blocksPerPage, stringsPerBlock, 0); var pagesCount = PagesCounter.GetPagesCount(strings, blocksPerPage, stringsPerBlock); var viewModel = new ViewTextViewModel() { Page = page, PagesCount = pagesCount, ViewTextLayoutParameters = new ViewTextLayoutParameters { BlockPerPage = blocksPerPage, StringsPerBlock = stringsPerBlock } }; return(View(viewModel)); }
public IHttpActionResult Get([FromUri] PagesViewModel viewModel) { //pages are zero-based and it CAN be equal zero if (viewModel.blocksPerPage <= 0 || viewModel.stringsPerBlock <= 0 || viewModel.pageNumber < 0) { return(BadRequest("Parameters can not be negative!")); } var path = HostingEnvironment.MapPath("~/Content/data.txt"); var strings = FileStringsGetter.GetStrings(path); var page = PageBuilder.GetPage( strings, viewModel.blocksPerPage, viewModel.stringsPerBlock, viewModel.pageNumber); return(Json(page)); }