Пересмотрена место выполнение пагинации в проекте
This commit is contained in:
parent
57aecf6cb6
commit
72a1f2e75d
@ -45,18 +45,5 @@ namespace ConfectioneryBusinessLogic
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel>? ReadPage(int page, int pageSize)
|
||||
{
|
||||
_logger.LogInformation("ReadPage. page: {page}, pageSize: {pageSize} ", page, pageSize);
|
||||
var list = _messageInfoStorage.GetListOnPage(page, pageSize);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadPage. Uncorrect range messages for page");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadPage. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,23 +24,17 @@ namespace ConfectioneryFileImplement
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel>? GetListOnPage(int page, int pageSize)
|
||||
{
|
||||
if (page * pageSize >= _source.Messages.Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _source.Messages.Skip((page - 1) * pageSize).Take(pageSize)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
||||
{
|
||||
return _source.Messages
|
||||
.Where(x => x.ClientId == model.ClientId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
var res = _source.Messages
|
||||
.Where(x => !model.ClientId.HasValue || x.ClientId == model.ClientId)
|
||||
.Select(x => x.GetViewModel);
|
||||
if (!(model.Page.HasValue && model.PageSize.HasValue))
|
||||
{
|
||||
return res.ToList();
|
||||
}
|
||||
return res.Skip((model.Page.Value - 1) * model.PageSize.Value).Take(model.PageSize.Value).ToList();
|
||||
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFullList()
|
||||
|
@ -3,6 +3,7 @@ using ConfectioneryContracts.SearchModels;
|
||||
using ConfectioneryContracts.StoragesContract;
|
||||
using ConfectioneryContracts.ViewModels;
|
||||
using ConfectioneryListImplement.Models;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ConfectioneryListImplement
|
||||
{
|
||||
@ -24,20 +25,6 @@ namespace ConfectioneryListImplement
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel>? GetListOnPage(int page, int pageSize)
|
||||
{
|
||||
if (page * pageSize >= _source.Messages.Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
List<MessageInfoViewModel> result = new();
|
||||
for (var i = (page - 1) * pageSize; i < page * pageSize; i++)
|
||||
{
|
||||
result.Add(_source.Messages[i].GetViewModel);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
||||
{
|
||||
List<MessageInfoViewModel> result = new();
|
||||
@ -48,7 +35,21 @@ namespace ConfectioneryListImplement
|
||||
result.Add(item.GetViewModel);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
if (!(model.Page.HasValue && model.PageSize.HasValue))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
if (model.Page * model.PageSize >= result.Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
List<MessageInfoViewModel> filteredResult = new();
|
||||
for (var i = (model.Page.Value - 1) * model.PageSize.Value; i < model.Page.Value * model.PageSize.Value; i++)
|
||||
{
|
||||
filteredResult.Add(result[i]);
|
||||
}
|
||||
return filteredResult;
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFullList()
|
||||
|
@ -38,7 +38,11 @@ namespace ConfectioneryView
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadPage(currentPage, pageSize);
|
||||
var list = _logic.ReadList(new()
|
||||
{
|
||||
Page = currentPage,
|
||||
PageSize = pageSize,
|
||||
});
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
|
@ -14,7 +14,5 @@ namespace ConfectioneryContracts.BusinessLogicsContracts
|
||||
List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model);
|
||||
|
||||
bool Create(MessageInfoBindingModel model);
|
||||
|
||||
public List<MessageInfoViewModel>? ReadPage(int page, int pageSize);
|
||||
}
|
||||
}
|
||||
|
@ -11,5 +11,9 @@ namespace ConfectioneryContracts.SearchModels
|
||||
public int? ClientId { get; set; }
|
||||
|
||||
public string? MessageId { get; set; }
|
||||
|
||||
public int? Page { get; set; }
|
||||
|
||||
public int? PageSize { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -13,8 +13,6 @@ namespace ConfectioneryContracts.StoragesContract
|
||||
{
|
||||
List<MessageInfoViewModel> GetFullList();
|
||||
|
||||
List<MessageInfoViewModel>? GetListOnPage(int page, int pageSize);
|
||||
|
||||
List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model);
|
||||
|
||||
MessageInfoViewModel? GetElement(MessageInfoSearchModel model);
|
||||
|
@ -19,28 +19,17 @@ namespace ConfectioneryDatabaseImplement
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel>? GetListOnPage(int page, int pageSize)
|
||||
{
|
||||
using var context = new ConfectioneryDatabase();
|
||||
try
|
||||
{
|
||||
return context.Messages.Skip((page - 1) * pageSize).Take(pageSize)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
||||
{
|
||||
using var context = new ConfectioneryDatabase();
|
||||
return context.Messages
|
||||
.Where(x => x.ClientId == model.ClientId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
var res = context.Messages
|
||||
.Where(x => !model.ClientId.HasValue || x.ClientId == model.ClientId)
|
||||
.Select(x => x.GetViewModel);
|
||||
if (!(model.Page.HasValue && model.PageSize.HasValue))
|
||||
{
|
||||
return res.ToList();
|
||||
}
|
||||
return res.Skip((model.Page.Value - 1) * model.PageSize.Value).Take(model.PageSize.Value).ToList();
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFullList()
|
||||
|
Loading…
Reference in New Issue
Block a user