Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
Lesson49
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
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
Пасько Виталий
Lesson49
Commits
681b375f
Commit
681b375f
authored
Jul 18, 2022
by
TTrueBenji
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: вынес значение количества записей на странице пользователей в файл appsettings.json.
parent
a2934765
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
13 additions
and
10 deletions
+13
-10
UsersController.cs
PhoneStore/Controllers/UsersController.cs
+1
-2
IUserService.cs
PhoneStore/Services/Abstractions/IUserService.cs
+1
-1
PaginationService.cs
PhoneStore/Services/PaginationService.cs
+0
-2
UserService.cs
PhoneStore/Services/UserService.cs
+9
-4
appsettings.json
PhoneStore/appsettings.json
+2
-1
No files found.
PhoneStore/Controllers/UsersController.cs
View file @
681b375f
...
...
@@ -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
,
page
Size
,
page
);
var
model
=
await
_userService
.
GetAll
(
order
,
filterByName
,
page
);
return
View
(
model
);
}
...
...
PhoneStore/Services/Abstractions/IUserService.cs
View file @
681b375f
...
...
@@ -6,6 +6,6 @@ namespace PhoneStore.Services.Abstractions
{
public
interface
IUserService
{
Task
<
UsersViewModel
>
GetAll
(
Order
order
,
string
filterByName
,
int
page
Size
,
int
page
);
Task
<
UsersViewModel
>
GetAll
(
Order
order
,
string
filterByName
,
int
page
);
}
}
\ No newline at end of file
PhoneStore/Services/PaginationService.cs
View file @
681b375f
...
...
@@ -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
PhoneStore/Services/UserService.cs
View file @
681b375f
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
page
Size
,
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
PhoneStore/appsettings.json
View file @
681b375f
...
...
@@ -12,5 +12,6 @@
"AllowedHosts"
:
"*"
,
"PathToDefaultAvatar"
:
{
"Path"
:
"images
\\
phoneImages
\\
default.jpg"
}
},
"UsersPageSize"
:
2
}
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