Skip to content

Commit 57a1c8e

Browse files
committed
Add project files.
1 parent 59f52fc commit 57a1c8e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+40262
-0
lines changed

MVCCore.Paging.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31515.178
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MVCCore.Paging", "MVCCore.Paging\MVCCore.Paging.csproj", "{D702CE82-9568-423B-9113-D682FC9C005D}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{D702CE82-9568-423B-9113-D682FC9C005D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{D702CE82-9568-423B-9113-D682FC9C005D}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{D702CE82-9568-423B-9113-D682FC9C005D}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{D702CE82-9568-423B-9113-D682FC9C005D}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {2B76E15F-7F57-41F0-A5E2-2703B88FC60D}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using MVCCore.Paging.Models;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
8+
namespace MVCCore.Paging.Context
9+
{
10+
public class DatabaseContext : DbContext
11+
{
12+
public DatabaseContext(DbContextOptions<DatabaseContext> options) : base(options)
13+
{
14+
}
15+
16+
public DbSet<Customer> customers { get; set; }
17+
}
18+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.Extensions.Logging;
3+
using MVCCore.Paging.Context;
4+
using MVCCore.Paging.Models;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Diagnostics;
8+
using System.Linq;
9+
using System.Threading.Tasks;
10+
11+
namespace MVCCore.Paging.Controllers
12+
{
13+
public class HomeController : Controller
14+
{
15+
private readonly ILogger<HomeController> _logger;
16+
private DatabaseContext Context { get; }
17+
public HomeController(ILogger<HomeController> logger, DatabaseContext _context)
18+
{
19+
_logger = logger;
20+
this.Context = _context;
21+
}
22+
23+
public IActionResult Index()
24+
{
25+
return View(this.GetCustomers(1));
26+
}
27+
[HttpPost]
28+
public IActionResult Index(int currentPageIndex)
29+
{
30+
return View(this.GetCustomers(currentPageIndex));
31+
}
32+
33+
private CustomerModel GetCustomers(int currentPage)
34+
{
35+
int maxRows = 10;
36+
var customers = this.Context.customers.Take(200).ToList();
37+
38+
CustomerModel customerModel = new CustomerModel();
39+
customerModel.Customers = customers.OrderBy(customer => customer.customer_id)
40+
.Skip((currentPage - 1) * maxRows)
41+
.Take(maxRows).ToList();
42+
43+
double pageCount = (double)((decimal)customers.Count() / Convert.ToDecimal(maxRows));
44+
customerModel.PageCount = (int)Math.Ceiling(pageCount);
45+
46+
customerModel.CurrentPageIndex = currentPage;
47+
48+
return customerModel;
49+
}
50+
public IActionResult Privacy()
51+
{
52+
return View();
53+
}
54+
55+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
56+
public IActionResult Error()
57+
{
58+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
59+
}
60+
}
61+
}

MVCCore.Paging/MVCCore.Paging.csproj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
<CopyRefAssembliesToPublishDirectory>false</CopyRefAssembliesToPublishDirectory>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="5.0.9" />
10+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.1" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel.DataAnnotations;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
7+
namespace MVCCore.Paging.Models
8+
{
9+
public class CustomerModel
10+
{
11+
///<summary>
12+
/// Gets or sets Customers.
13+
///</summary>
14+
public List<Customer> Customers { get; set; }
15+
16+
///<summary>
17+
/// Gets or sets CurrentPageIndex.
18+
///</summary>
19+
public int CurrentPageIndex { get; set; }
20+
21+
///<summary>
22+
/// Gets or sets PageCount.
23+
///</summary>
24+
public int PageCount { get; set; }
25+
}
26+
public class Customer
27+
{
28+
[Key]
29+
public int customer_id { get; set; }
30+
public string first_name { get; set; }
31+
public string last_name { get; set; }
32+
public string phone { get; set; }
33+
public string email { get; set; }
34+
public string street { get; set; }
35+
public string city { get; set; }
36+
public string state { get; set; }
37+
public string zip_code { get; set; }
38+
}
39+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace MVCCore.Paging.Models
4+
{
5+
public class ErrorViewModel
6+
{
7+
public string RequestId { get; set; }
8+
9+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
10+
}
11+
}

MVCCore.Paging/Program.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Microsoft.AspNetCore.Hosting;
2+
using Microsoft.Extensions.Configuration;
3+
using Microsoft.Extensions.Hosting;
4+
using Microsoft.Extensions.Logging;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Threading.Tasks;
9+
10+
namespace MVCCore.Paging
11+
{
12+
public class Program
13+
{
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+
});
25+
}
26+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:15474",
7+
"sslPort": 44322
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName": "IISExpress",
13+
"launchBrowser": true,
14+
"environmentVariables": {
15+
"ASPNETCORE_ENVIRONMENT": "Development",
16+
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation"
17+
}
18+
},
19+
"MVCCore.Paging": {
20+
"commandName": "Project",
21+
"dotnetRunMessages": "true",
22+
"launchBrowser": true,
23+
"applicationUrl": "https://localhost:5001;http://localhost:5000",
24+
"environmentVariables": {
25+
"ASPNETCORE_ENVIRONMENT": "Development",
26+
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation"
27+
}
28+
}
29+
}
30+
}

MVCCore.Paging/Startup.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.AspNetCore.Hosting;
3+
using Microsoft.AspNetCore.HttpsPolicy;
4+
using Microsoft.EntityFrameworkCore;
5+
using Microsoft.Extensions.Configuration;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using Microsoft.Extensions.Hosting;
8+
using MVCCore.Paging.Context;
9+
using System;
10+
using System.Collections.Generic;
11+
using System.Linq;
12+
using System.Threading.Tasks;
13+
14+
namespace MVCCore.Paging
15+
{
16+
public class Startup
17+
{
18+
public Startup(IConfiguration configuration)
19+
{
20+
Configuration = configuration;
21+
}
22+
23+
public IConfiguration Configuration { get; }
24+
25+
// This method gets called by the runtime. Use this method to add services to the container.
26+
public void ConfigureServices(IServiceCollection services)
27+
{
28+
services.AddControllersWithViews();
29+
string conStr = this.Configuration.GetConnectionString("DBConnection");
30+
services.AddDbContext<DatabaseContext>(options => options.UseSqlServer(conStr));
31+
}
32+
33+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
34+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
35+
{
36+
if (env.IsDevelopment())
37+
{
38+
app.UseDeveloperExceptionPage();
39+
}
40+
else
41+
{
42+
app.UseExceptionHandler("/Home/Error");
43+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
44+
app.UseHsts();
45+
}
46+
app.UseHttpsRedirection();
47+
app.UseStaticFiles();
48+
49+
app.UseRouting();
50+
51+
app.UseAuthorization();
52+
53+
app.UseEndpoints(endpoints =>
54+
{
55+
endpoints.MapControllerRoute(
56+
name: "default",
57+
pattern: "{controller=Home}/{action=Index}/{id?}");
58+
});
59+
}
60+
}
61+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
@addTagHelper*, Microsoft.AspNetCore.Mvc.TagHelpers
2+
@using MVCCore.Paging.Models
3+
@model CustomerModel
4+
@{
5+
ViewData["Title"] = "Home Page";
6+
}
7+
8+
<div class="text-center">
9+
<form asp-action="Index" asp-controller="Home" method="post">
10+
<table class="table table-responsive">
11+
<tr>
12+
<th>CustomerID</th>
13+
<th>First Name</th>
14+
<th>Last Name</th>
15+
<th>Street</th>
16+
<th>City</th>
17+
<th>State</th>
18+
<th>Zip Code</th>
19+
</tr>
20+
@foreach (Customer customer in Model.Customers)
21+
{
22+
<tr>
23+
<td>@customer.customer_id</td>
24+
<td>@customer.first_name</td>
25+
<td>@customer.last_name</td>
26+
<td>@customer.street</td>
27+
<td>@customer.city</td>
28+
<td>@customer.state</td>
29+
<td>@customer.zip_code</td>
30+
</tr>
31+
}
32+
</table>
33+
34+
<table class="table table-responsive">
35+
<tr>
36+
@for (int i = 1; i <= Model.PageCount; i++)
37+
{
38+
<td>
39+
@if (i != Model.CurrentPageIndex)
40+
{
41+
<a href="javascript:PagerClick(@i);">@i</a>
42+
}
43+
else
44+
{
45+
<span>@i</span>
46+
}
47+
</td>
48+
}
49+
</tr>
50+
</table>
51+
<input type="hidden" id="hfCurrentPageIndex" name="currentPageIndex" />
52+
</form>
53+
54+
<script type="text/javascript">
55+
function PagerClick(index) {
56+
document.getElementById("hfCurrentPageIndex").value = index;
57+
document.forms[0].submit();
58+
}
59+
</script>
60+
61+
</div>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@{
2+
ViewData["Title"] = "Privacy Policy";
3+
}
4+
<h1>@ViewData["Title"]</h1>
5+
6+
<p>Use this page to detail your site's privacy policy.</p>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@model ErrorViewModel
2+
@{
3+
ViewData["Title"] = "Error";
4+
}
5+
6+
<h1 class="text-danger">Error.</h1>
7+
<h2 class="text-danger">An error occurred while processing your request.</h2>
8+
9+
@if (Model.ShowRequestId)
10+
{
11+
<p>
12+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
13+
</p>
14+
}
15+
16+
<h3>Development Mode</h3>
17+
<p>
18+
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
19+
</p>
20+
<p>
21+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
22+
It can result in displaying sensitive information from exceptions to end users.
23+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
24+
and restarting the app.
25+
</p>

0 commit comments

Comments
 (0)