Commit 681b375f authored by TTrueBenji's avatar TTrueBenji

refactor: вынес значение количества записей на странице пользователей в файл appsettings.json.

parent a2934765
......@@ -17,10 +17,9 @@ namespace PhoneStore.Controllers
[HttpGet]
public async Task<IActionResult> Index(string filterByName, Order order = Order.AgeAsc, int page = 1)
{
int pageSize = 2;
ViewBag.NameSort = order == Order.NameAsc ? Order.NameDesc : Order.NameAsc;
ViewBag.AgeSort = order == Order.AgeAsc ? Order.AgeDesc : Order.AgeAsc;
var model = await _userService.GetAll(order, filterByName, pageSize, page);
var model = await _userService.GetAll(order, filterByName, page);
return View(model);
}
......
......@@ -6,6 +6,6 @@ namespace PhoneStore.Services.Abstractions
{
public interface IUserService
{
Task<UsersViewModel> GetAll(Order order, string filterByName, int pageSize, int page);
Task<UsersViewModel> GetAll(Order order, string filterByName, int page);
}
}
\ No newline at end of file
......@@ -12,7 +12,5 @@ namespace PhoneStore.Services
int count = await elements.CountAsync();
return (elements.Skip((page - 1) * pageSize).Take(pageSize), count);
}
}
}
\ No newline at end of file
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using PhoneStore.Helpers;
using PhoneStore.Models;
using PhoneStore.Services.Abstractions;
......@@ -13,27 +14,31 @@ namespace PhoneStore.Services
private readonly IUsersSortService _sortService;
private readonly IUsersFilter _usersFilter;
private readonly IPaginationService<User> _paginationService;
private readonly IConfiguration _configuration;
public UserService(
MobileContext db,
IUsersSortService sortService,
IUsersFilter usersFilter,
IPaginationService<User> paginationService)
IPaginationService<User> paginationService,
IConfiguration configuration)
{
_db = db;
_sortService = sortService;
_usersFilter = usersFilter;
_paginationService = paginationService;
_configuration = configuration;
}
public async Task<UsersViewModel> GetAll(Order order, string filterByName, int pageSize, int page)
public async Task<UsersViewModel> GetAll(Order order, string filterByName, int page)
{
var pageSize = int.Parse(_configuration["UsersPageSize"]); //Размер страницы берется из appsettings.json
var users = _db.Users.AsQueryable();
var filteredUsers = _usersFilter.FilterByName(users, filterByName);
var sortedUsers = _sortService.Sort(filteredUsers, order);
var paginationData = await _paginationService.GetABatchOfData(sortedUsers, page, pageSize);
var (queryable, count) = await _paginationService.GetABatchOfData(sortedUsers, page, pageSize);
return paginationData.Item1.MapToUsersViewModel(filterByName, page, paginationData.Item2, pageSize);
return queryable.MapToUsersViewModel(filterByName, page, count, pageSize);
}
}
}
\ No newline at end of file
......@@ -12,5 +12,6 @@
"AllowedHosts": "*",
"PathToDefaultAvatar": {
"Path": "images\\phoneImages\\default.jpg"
}
},
"UsersPageSize" : 2
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment