Skip to content

Commit 45eb13c

Browse files
committed
Update syntax
1 parent 68a3bae commit 45eb13c

32 files changed

+2791
-2824
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
namespace X.PagedList.Mvc.Example.Core.Controllers
1+
namespace X.PagedList.Mvc.Example.Core.Controllers;
2+
3+
public class Bootstrap41Controller : HomeController
24
{
3-
public class Bootstrap41Controller : HomeController
4-
{
55

6-
}
76
}
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,60 @@
11
using Microsoft.AspNetCore.Mvc;
22
using System.Collections.Generic;
33

4-
namespace X.PagedList.Mvc.Example.Core.Controllers
4+
namespace X.PagedList.Mvc.Example.Core.Controllers;
5+
6+
public class HomeController : Controller
57
{
6-
public class HomeController : Controller
8+
public IActionResult Index(int page = 1)
9+
{
10+
ViewBag.Names = GetPagedNames(page);
11+
return View();
12+
}
13+
14+
public IActionResult AjaxIndex(int page = 1)
15+
{
16+
var listPaged = GetPagedNames(page);
17+
ViewBag.Names = listPaged;
18+
return View();
19+
}
20+
21+
public IActionResult GetOnePageOfNames(int page = 1)
22+
{
23+
var listPaged = GetPagedNames(page);
24+
ViewBag.Names = listPaged;
25+
return PartialView("_NameListPartial", ViewBag.Names);
26+
}
27+
28+
public IActionResult Error()
29+
{
30+
return View();
31+
}
32+
33+
protected IPagedList<string> GetPagedNames(int? page)
34+
{
35+
// return a 404 if user browses to before the first page
36+
if (page.HasValue && page < 1)
37+
return null;
38+
39+
// retrieve list from database/whereverand
40+
var listUnpaged = GetStuffFromDatabase();
41+
42+
// page the list
43+
const int pageSize = 20;
44+
var listPaged = listUnpaged.ToPagedList(page ?? 1, pageSize);
45+
46+
// return a 404 if user browses to pages beyond last page. special case first page if no items exist
47+
if (listPaged.PageNumber != 1 && page.HasValue && page > listPaged.PageCount)
48+
return null;
49+
50+
return listPaged;
51+
}
52+
53+
// in this case we return IEnumerable<string>, but in most
54+
// - DB situations you'll want to return IQueryable<string>
55+
protected IEnumerable<string> GetStuffFromDatabase()
756
{
8-
public IActionResult Index(int page = 1)
9-
{
10-
ViewBag.Names = GetPagedNames(page);
11-
return View();
12-
}
13-
14-
public IActionResult AjaxIndex(int page = 1)
15-
{
16-
var listPaged = GetPagedNames(page);
17-
ViewBag.Names = listPaged;
18-
return View();
19-
}
20-
21-
public IActionResult GetOnePageOfNames(int page = 1)
22-
{
23-
var listPaged = GetPagedNames(page);
24-
ViewBag.Names = listPaged;
25-
return PartialView("_NameListPartial", ViewBag.Names);
26-
}
27-
28-
public IActionResult Error()
29-
{
30-
return View();
31-
}
32-
33-
protected IPagedList<string> GetPagedNames(int? page)
34-
{
35-
// return a 404 if user browses to before the first page
36-
if (page.HasValue && page < 1)
37-
return null;
38-
39-
// retrieve list from database/whereverand
40-
var listUnpaged = GetStuffFromDatabase();
41-
42-
// page the list
43-
const int pageSize = 20;
44-
var listPaged = listUnpaged.ToPagedList(page ?? 1, pageSize);
45-
46-
// return a 404 if user browses to pages beyond last page. special case first page if no items exist
47-
if (listPaged.PageNumber != 1 && page.HasValue && page > listPaged.PageCount)
48-
return null;
49-
50-
return listPaged;
51-
}
52-
53-
// in this case we return IEnumerable<string>, but in most
54-
// - DB situations you'll want to return IQueryable<string>
55-
protected IEnumerable<string> GetStuffFromDatabase()
56-
{
57-
var sampleData = System.IO.File.ReadAllText("Names.txt");
58-
return sampleData.Split('\n');
59-
}
57+
var sampleData = System.IO.File.ReadAllText("Names.txt");
58+
return sampleData.Split('\n');
6059
}
6160
}

examples/X.PagedList.Mvc.Example.Core/Program.cs

+13-14
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,19 @@
77
using Microsoft.Extensions.Hosting;
88
using Microsoft.Extensions.Logging;
99

10-
namespace X.PagedList.Mvc.Example.Core
10+
namespace X.PagedList.Mvc.Example.Core;
11+
12+
public class Program
1113
{
12-
public class Program
14+
public static void Main(string[] args)
1315
{
14-
public static void Main(string[] args)
15-
{
16-
CreateHostBuilder(args).Build().Run();
17-
}
18-
19-
public static IHostBuilder CreateHostBuilder(string[] args) =>
20-
Host.CreateDefaultBuilder(args)
21-
.ConfigureWebHostDefaults(webBuilder =>
22-
{
23-
webBuilder.UseStartup<Startup>();
24-
});
16+
CreateHostBuilder(args).Build().Run();
2517
}
26-
}
18+
19+
public static IHostBuilder CreateHostBuilder(string[] args) =>
20+
Host.CreateDefaultBuilder(args)
21+
.ConfigureWebHostDefaults(webBuilder =>
22+
{
23+
webBuilder.UseStartup<Startup>();
24+
});
25+
}

examples/X.PagedList.Mvc.Example.Core/Startup.cs

+36-37
Original file line numberDiff line numberDiff line change
@@ -9,49 +9,48 @@
99
using Microsoft.Extensions.DependencyInjection;
1010
using Microsoft.Extensions.Hosting;
1111

12-
namespace X.PagedList.Mvc.Example.Core
12+
namespace X.PagedList.Mvc.Example.Core;
13+
14+
public class Startup
1315
{
14-
public class Startup
16+
public Startup(IConfiguration configuration)
1517
{
16-
public Startup(IConfiguration configuration)
17-
{
18-
Configuration = configuration;
19-
}
18+
Configuration = configuration;
19+
}
2020

21-
public IConfiguration Configuration { get; }
21+
public IConfiguration Configuration { get; }
22+
23+
// This method gets called by the runtime. Use this method to add services to the container.
24+
public void ConfigureServices(IServiceCollection services)
25+
{
26+
services.AddControllersWithViews();
27+
}
2228

23-
// This method gets called by the runtime. Use this method to add services to the container.
24-
public void ConfigureServices(IServiceCollection services)
29+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
30+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
31+
{
32+
if (env.IsDevelopment())
2533
{
26-
services.AddControllersWithViews();
34+
app.UseDeveloperExceptionPage();
2735
}
28-
29-
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
30-
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
36+
else
3137
{
32-
if (env.IsDevelopment())
33-
{
34-
app.UseDeveloperExceptionPage();
35-
}
36-
else
37-
{
38-
app.UseExceptionHandler("/Home/Error");
39-
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
40-
app.UseHsts();
41-
}
42-
app.UseHttpsRedirection();
43-
app.UseStaticFiles();
44-
45-
app.UseRouting();
46-
47-
app.UseAuthorization();
48-
49-
app.UseEndpoints(endpoints =>
50-
{
51-
endpoints.MapControllerRoute(
52-
name: "default",
53-
pattern: "{controller=Home}/{action=Index}/{id?}");
54-
});
38+
app.UseExceptionHandler("/Home/Error");
39+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
40+
app.UseHsts();
5541
}
42+
app.UseHttpsRedirection();
43+
app.UseStaticFiles();
44+
45+
app.UseRouting();
46+
47+
app.UseAuthorization();
48+
49+
app.UseEndpoints(endpoints =>
50+
{
51+
endpoints.MapControllerRoute(
52+
name: "default",
53+
pattern: "{controller=Home}/{action=Index}/{id?}");
54+
});
5655
}
57-
}
56+
}

0 commit comments

Comments
 (0)