Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
CafeCritic
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yevgeniy Agrafenin
CafeCritic
Commits
1e11eb19
Commit
1e11eb19
authored
Nov 18, 2023
by
Yevgeniy Agrafenin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#3
Добавил пагинацию.
parent
310d343a
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
86 additions
and
18 deletions
+86
-18
CafeCritic.csproj
CafeCritic/CafeCritic.csproj
+4
-0
CafeController.cs
CafeCritic/Controllers/CafeController.cs
+14
-4
CafeViewModel.cs
CafeCritic/ViewModels/CafeViewModel.cs
+2
-1
IndexViewModel.cs
CafeCritic/ViewModels/IndexViewModel.cs
+13
-0
PageViewModel.cs
CafeCritic/ViewModels/PageViewModel.cs
+29
-0
Index.cshtml
CafeCritic/Views/Cafe/Index.cshtml
+24
-13
No files found.
CafeCritic/CafeCritic.csproj
View file @
1e11eb19
...
...
@@ -20,4 +20,8 @@
<_ContentIncludedByDefault Remove="Views\Home\Privacy.cshtml" />
</ItemGroup>
<ItemGroup>
<Folder Include="wwwroot\uploads" />
</ItemGroup>
</Project>
CafeCritic/Controllers/CafeController.cs
View file @
1e11eb19
...
...
@@ -7,6 +7,7 @@ using CafeCritic.ViewModels;
using
Microsoft.AspNetCore.Authorization
;
using
Microsoft.AspNetCore.Identity
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.EntityFrameworkCore
;
namespace
CafeCritic.Controllers
;
...
...
@@ -23,11 +24,20 @@ public class CafeController : Controller
}
[
HttpGet
]
public
IActionResult
Index
(
)
public
async
Task
<
IActionResult
>
Index
(
int
page
=
1
)
{
List
<
Cafe
>
models
=
_db
.
Cafes
.
ToList
();
int
pageSize
=
10
;
IQueryable
<
Cafe
>
source
=
_db
.
Cafes
;
var
count
=
await
source
.
CountAsync
();
var
items
=
await
source
.
Skip
((
page
-
1
)
*
pageSize
).
Take
(
pageSize
).
ToListAsync
();
PageViewModel
pageViewModel
=
new
PageViewModel
(
count
,
page
,
pageSize
);
CafeViewModel
viewModel
=
new
CafeViewModel
{
PageViewModel
=
pageViewModel
,
Cafes
=
items
};
return
View
(
models
);
return
View
(
viewModel
);
}
[
HttpGet
]
...
...
CafeCritic/ViewModels/CafeViewModel.cs
View file @
1e11eb19
...
...
@@ -4,7 +4,8 @@ namespace CafeCritic.ViewModels;
public
class
CafeViewModel
{
public
List
<
Cafe
>
Cafes
{
get
;
set
;
}
=
new
();
public
IEnumerable
<
Cafe
>
Cafes
{
get
;
set
;
}
public
PageViewModel
PageViewModel
{
get
;
set
;
}
public
int
Id
{
get
;
set
;
}
public
string
Title
{
get
;
set
;
}
public
string
Image
{
get
;
set
;
}
...
...
CafeCritic/ViewModels/IndexViewModel.cs
0 → 100644
View file @
1e11eb19
using
CafeCritic.Models
;
namespace
CafeCritic.ViewModels
;
public
class
IndexViewModel
{
public
IEnumerable
<
Cafe
>
Cafes
{
get
;
set
;
}
public
PageViewModel
PageViewModel
{
get
;
set
;
}
public
int
Id
{
get
;
set
;
}
public
string
Title
{
get
;
set
;
}
public
string
Image
{
get
;
set
;
}
public
string
?
Description
{
get
;
set
;
}
}
\ No newline at end of file
CafeCritic/ViewModels/PageViewModel.cs
0 → 100644
View file @
1e11eb19
namespace
CafeCritic.ViewModels
;
public
class
PageViewModel
{
public
int
PageNumber
{
get
;
set
;
}
public
int
TotalPages
{
get
;
set
;
}
public
PageViewModel
(
int
count
,
int
pageNumber
,
int
pageSize
)
{
PageNumber
=
pageNumber
;
TotalPages
=
(
int
)
Math
.
Ceiling
(
count
/
(
double
)
pageSize
);
}
public
bool
HasPreviousPage
{
get
{
return
(
PageNumber
>
1
);
}
}
public
bool
HasNextPage
{
get
{
return
(
PageNumber
<
TotalPages
);
}
}
}
\ No newline at end of file
CafeCritic/Views/Cafe/Index.cshtml
View file @
1e11eb19
@model
List<Cafe>
@model
CafeCritic.ViewModels.CafeViewModel
@{
ViewBag.Title = "title";
Layout = "_Layout";
}
@if (Model.C
ount
== 0)
@if (Model.C
afes.Count()
== 0)
{
<h2 class="display-4">Заведения еще не добавлены.</h2>
}
else
{
<h2 class="display-4 mb-5">Список заведений</h2>
@foreach (var m in Model)
<table class="table">
@foreach (var m in Model.Cafes)
{
<div class="card d-flex mb-3 col-3" style="width: 18
rem;">
<div class="card float-start m-3 col-4" style="width: 22
rem;">
<a asp-action="Details" asp-route-id="@m.Id">
<img src="@m.Image" class="card-img-top" alt="PhotoCafe">
</a>
...
...
@@ -23,5 +24,15 @@ else
</div>
</div>
}
</table>
@if (Model.PageViewModel.HasPreviousPage)
{
<a asp-action="Index" asp-route-page="@(Model.PageViewModel.PageNumber - 1)"
class="btn btn-default btn"><i class="glyphicon glyphicon-chevron-left"></i>Назад</a>
}
@if (Model.PageViewModel.HasNextPage)
{
<a asp-action="Index" asp-route-page="@(Model.PageViewModel.PageNumber + 1)"
class="btn btn-default btn">Вперёд<i class="glyphicon glyphicon-chevron-right"></i></a>
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment