-
Notifications
You must be signed in to change notification settings - Fork 7
/
HomeController.cs
104 lines (75 loc) · 2.62 KB
/
HomeController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using MvcPagedList.Core.Example.Service.Users.Dto;
using MvcPagedList.Core.Example.Enums;
using MvcPagedList.Core.Example.Service.Users;
namespace MvcPagedList.Core.Example.Controllers
{
public class HomeController : Controller
{
private readonly IUserService _userService;
private int page;
private int pageSize;
private int recordsPerPage;
private int totalItemCount;
public HomeController()
{
_userService = new UserService();
page = 1;
pageSize = 0;
recordsPerPage = 5;
totalItemCount = 0;
AddFakeUsers();
}
/// <summary>
///
/// </summary>
public ActionResult Index()
{
var users = _userService.Search(page: page, recordsPerPage: recordsPerPage, term: "", sortBy: SortBy.AddDate, sortOrder: SortOrder.Desc, pageSize: out pageSize, TotalItemCount: out totalItemCount);
//Provide some data by ViewBags to use in _UsersPagedList.cshtml
#region ViewBags
ViewBag.PageSize = pageSize;
ViewBag.CurrentPage = page;
ViewBag.TotalItemCount = totalItemCount;
#endregion
return View(users);
}
/// <summary>
///
/// </summary>
[HttpGet]
public ActionResult Search(int page = 1, string term = "", SortBy sortBy = SortBy.AddDate, SortOrder sortOrder = SortOrder.Desc)
{
Thread.Sleep(700);
var users = _userService.Search(page: page, recordsPerPage: recordsPerPage, term: term, sortBy: sortBy, sortOrder: sortOrder, pageSize: out pageSize, TotalItemCount: out totalItemCount);
//Provide some data by ViewBags to use in _UsersPagedList.cshtml
#region ViewBags
ViewBag.PageSize = pageSize;
ViewBag.CurrentPage = page;
ViewBag.TotalItemCount = totalItemCount;
#endregion
return PartialView("_UsersList", users);
}
/// <summary>
///
/// </summary>
void AddFakeUsers()
{
for (int i = 0; i < 400; i++)
{
_userService.Create(new UserInput
{
Id = i,
Name = "Name " + i,
Family = "Family " + i,
AddDate = DateTime.Now.AddDays(-i),
});
}
}
}
}