Skip to content

Commit

Permalink
Update syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
a-gubskiy committed Apr 25, 2022
1 parent 68a3bae commit 45eb13c
Show file tree
Hide file tree
Showing 32 changed files with 2,791 additions and 2,824 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace X.PagedList.Mvc.Example.Core.Controllers
namespace X.PagedList.Mvc.Example.Core.Controllers;

public class Bootstrap41Controller : HomeController
{
public class Bootstrap41Controller : HomeController
{

}
}
107 changes: 53 additions & 54 deletions examples/X.PagedList.Mvc.Example.Core/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -1,61 +1,60 @@
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;

namespace X.PagedList.Mvc.Example.Core.Controllers
namespace X.PagedList.Mvc.Example.Core.Controllers;

public class HomeController : Controller
{
public class HomeController : Controller
public IActionResult Index(int page = 1)
{
ViewBag.Names = GetPagedNames(page);
return View();
}

public IActionResult AjaxIndex(int page = 1)
{
var listPaged = GetPagedNames(page);
ViewBag.Names = listPaged;
return View();
}

public IActionResult GetOnePageOfNames(int page = 1)
{
var listPaged = GetPagedNames(page);
ViewBag.Names = listPaged;
return PartialView("_NameListPartial", ViewBag.Names);
}

public IActionResult Error()
{
return View();
}

protected IPagedList<string> GetPagedNames(int? page)
{
// return a 404 if user browses to before the first page
if (page.HasValue && page < 1)
return null;

// retrieve list from database/whereverand
var listUnpaged = GetStuffFromDatabase();

// page the list
const int pageSize = 20;
var listPaged = listUnpaged.ToPagedList(page ?? 1, pageSize);

// return a 404 if user browses to pages beyond last page. special case first page if no items exist
if (listPaged.PageNumber != 1 && page.HasValue && page > listPaged.PageCount)
return null;

return listPaged;
}

// in this case we return IEnumerable<string>, but in most
// - DB situations you'll want to return IQueryable<string>
protected IEnumerable<string> GetStuffFromDatabase()
{
public IActionResult Index(int page = 1)
{
ViewBag.Names = GetPagedNames(page);
return View();
}

public IActionResult AjaxIndex(int page = 1)
{
var listPaged = GetPagedNames(page);
ViewBag.Names = listPaged;
return View();
}

public IActionResult GetOnePageOfNames(int page = 1)
{
var listPaged = GetPagedNames(page);
ViewBag.Names = listPaged;
return PartialView("_NameListPartial", ViewBag.Names);
}

public IActionResult Error()
{
return View();
}

protected IPagedList<string> GetPagedNames(int? page)
{
// return a 404 if user browses to before the first page
if (page.HasValue && page < 1)
return null;

// retrieve list from database/whereverand
var listUnpaged = GetStuffFromDatabase();

// page the list
const int pageSize = 20;
var listPaged = listUnpaged.ToPagedList(page ?? 1, pageSize);

// return a 404 if user browses to pages beyond last page. special case first page if no items exist
if (listPaged.PageNumber != 1 && page.HasValue && page > listPaged.PageCount)
return null;

return listPaged;
}

// in this case we return IEnumerable<string>, but in most
// - DB situations you'll want to return IQueryable<string>
protected IEnumerable<string> GetStuffFromDatabase()
{
var sampleData = System.IO.File.ReadAllText("Names.txt");
return sampleData.Split('\n');
}
var sampleData = System.IO.File.ReadAllText("Names.txt");
return sampleData.Split('\n');
}
}
27 changes: 13 additions & 14 deletions examples/X.PagedList.Mvc.Example.Core/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace X.PagedList.Mvc.Example.Core
namespace X.PagedList.Mvc.Example.Core;

public class Program
{
public class Program
public static void Main(string[] args)
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
CreateHostBuilder(args).Build().Run();
}
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
73 changes: 36 additions & 37 deletions examples/X.PagedList.Mvc.Example.Core/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,48 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace X.PagedList.Mvc.Example.Core
namespace X.PagedList.Mvc.Example.Core;

public class Startup
{
public class Startup
public Startup(IConfiguration configuration)
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
Configuration = configuration;
}

public IConfiguration Configuration { get; }
public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
}

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
services.AddControllersWithViews();
app.UseDeveloperExceptionPage();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
else
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
Loading

0 comments on commit 45eb13c

Please sign in to comment.