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
34e9f927
Commit
34e9f927
authored
Aug 08, 2022
by
Пасько Виталий
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Добавил функционал поиска пользователей по имени, мылу и логину.
parent
ec9df425
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
126 additions
and
9 deletions
+126
-9
AccountController.cs
PhoneStore/Controllers/AccountController.cs
+7
-1
ServiceConnector.cs
PhoneStore/Helpers/ServiceConnector.cs
+1
-0
IAccountService.cs
PhoneStore/Services/Abstractions/IAccountService.cs
+3
-0
IUsersSearcher.cs
PhoneStore/Services/Abstractions/IUsersSearcher.cs
+12
-0
AccountService.cs
PhoneStore/Services/AccountService.cs
+23
-2
UsersSearcher.cs
PhoneStore/Services/UsersSearcher.cs
+30
-0
SearchResultPartial.cshtml
...ore/Views/Account/PartialViews/SearchResultPartial.cshtml
+33
-0
About.cshtml
PhoneStore/Views/Phones/About.cshtml
+1
-1
_Layout.cshtml
PhoneStore/Views/Shared/_Layout.cshtml
+4
-0
appsettings.json
PhoneStore/appsettings.json
+1
-1
site.js
PhoneStore/wwwroot/js/site.js
+11
-4
No files found.
PhoneStore/Controllers/AccountController.cs
View file @
34e9f927
...
...
@@ -3,7 +3,6 @@ using System.Threading.Tasks;
using
Microsoft.AspNetCore.Mvc
;
using
PhoneStore.Enums
;
using
PhoneStore.Helpers
;
using
PhoneStore.Models
;
using
PhoneStore.Services.Abstractions
;
using
PhoneStore.ViewModels.Account
;
...
...
@@ -74,5 +73,12 @@ namespace PhoneStore.Controllers
await
_accountService
.
LogOf
();
return
RedirectToAction
(
"Index"
,
"Phones"
);
}
[
HttpGet
]
public
IActionResult
SearchAccounts
(
string
searchTerm
)
{
var
users
=
_accountService
.
SearchUsersByAnyTerm
(
searchTerm
);
return
PartialView
(
"PartialViews/SearchResultPartial"
,
users
);
}
}
}
\ No newline at end of file
PhoneStore/Helpers/ServiceConnector.cs
View file @
34e9f927
...
...
@@ -22,6 +22,7 @@ namespace PhoneStore.Helpers
services
.
AddTransient
<
IUsersFilter
,
UsersFilter
>();
services
.
AddTransient
<
IPaginationService
<
User
>,
PaginationService
<
User
>>();
services
.
AddTransient
<
IAccountService
,
AccountService
>();
services
.
AddTransient
<
IUsersSearcher
,
UsersSearcher
>();
}
}
}
\ No newline at end of file
PhoneStore/Services/Abstractions/IAccountService.cs
View file @
34e9f927
using
System.Collections.Generic
;
using
System.Threading.Tasks
;
using
PhoneStore.DataObjects
;
using
PhoneStore.Models
;
using
PhoneStore.ViewModels.Account
;
namespace
PhoneStore.Services.Abstractions
...
...
@@ -9,5 +11,6 @@ namespace PhoneStore.Services.Abstractions
Task
<
IdentityResult
>
Register
(
RegisterViewModel
model
);
Task
<
IdentityResult
>
LogIn
(
LoginViewModel
model
);
Task
LogOf
();
IEnumerable
<
User
>
SearchUsersByAnyTerm
(
string
searchTerm
);
}
}
\ No newline at end of file
PhoneStore/Services/Abstractions/IUsersSearcher.cs
0 → 100644
View file @
34e9f927
using
System.Collections.Generic
;
using
PhoneStore.Models
;
namespace
PhoneStore.Services.Abstractions
{
public
interface
IUsersSearcher
{
IEnumerable
<
User
>
SearchByName
(
string
searchTerm
);
IEnumerable
<
User
>
SearchByLogin
(
string
searchTerm
);
IEnumerable
<
User
>
SearchByEmail
(
string
searchTerm
);
}
}
\ No newline at end of file
PhoneStore/Services/AccountService.cs
View file @
34e9f927
...
...
@@ -2,11 +2,13 @@ using System.Collections.Generic;
using
System.Linq
;
using
System.Threading.Tasks
;
using
Microsoft.AspNetCore.Identity
;
using
Microsoft.AspNetCore.Mvc
;
using
PhoneStore.Enums
;
using
PhoneStore.Models
;
using
PhoneStore.Services.Abstractions
;
using
PhoneStore.ViewModels.Account
;
using
IdentityResult
=
PhoneStore
.
DataObjects
.
IdentityResult
;
using
SignInResult
=
Microsoft
.
AspNetCore
.
Identity
.
SignInResult
;
namespace
PhoneStore.Services
{
...
...
@@ -14,13 +16,16 @@ namespace PhoneStore.Services
{
private
readonly
UserManager
<
User
>
_userManager
;
private
readonly
SignInManager
<
User
>
_signInManager
;
private
readonly
IUsersSearcher
_usersSearcher
;
public
AccountService
(
UserManager
<
User
>
userManager
,
SignInManager
<
User
>
signInManager
)
SignInManager
<
User
>
signInManager
,
IUsersSearcher
usersSearcher
)
{
_userManager
=
userManager
;
_signInManager
=
signInManager
;
_usersSearcher
=
usersSearcher
;
}
public
async
Task
<
IdentityResult
>
Register
(
RegisterViewModel
model
)
...
...
@@ -34,7 +39,9 @@ namespace PhoneStore.Services
User
user
=
new
User
{
Email
=
model
.
Email
,
UserName
=
model
.
Email
UserName
=
model
.
Email
,
Age
=
model
.
Age
,
Name
=
model
.
Name
};
var
result
=
await
_userManager
.
CreateAsync
(
user
,
model
.
Password
);
if
(
result
.
Succeeded
)
...
...
@@ -74,5 +81,19 @@ namespace PhoneStore.Services
public
async
Task
LogOf
()
=>
await
_signInManager
.
SignOutAsync
();
[
HttpGet
]
public
IEnumerable
<
User
>
SearchUsersByAnyTerm
(
string
searchTerm
)
{
var
resultByName
=
_usersSearcher
.
SearchByName
(
searchTerm
);
var
resultByLogin
=
_usersSearcher
.
SearchByLogin
(
searchTerm
);
var
resultByEmail
=
_usersSearcher
.
SearchByEmail
(
searchTerm
);
var
users
=
resultByName
.
Concat
(
resultByLogin
)
.
Concat
(
resultByEmail
)
.
ToHashSet
();
return
users
;
}
}
}
\ No newline at end of file
PhoneStore/Services/UsersSearcher.cs
0 → 100644
View file @
34e9f927
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
PhoneStore.Models
;
using
PhoneStore.Services.Abstractions
;
namespace
PhoneStore.Services
{
public
class
UsersSearcher
:
IUsersSearcher
{
private
readonly
MobileContext
_db
;
public
UsersSearcher
(
MobileContext
db
)
{
_db
=
db
;
}
public
IEnumerable
<
User
>
SearchByName
(
string
searchTerm
)
=>
_db
.
Users
.
Where
(
u
=>
u
.
Name
.
ToLower
()
.
Contains
(
searchTerm
.
ToLower
()));
public
IEnumerable
<
User
>
SearchByLogin
(
string
searchTerm
)
=>
_db
.
Users
.
Where
(
u
=>
u
.
UserName
.
ToLower
().
Contains
(
searchTerm
.
ToLower
()));
public
IEnumerable
<
User
>
SearchByEmail
(
string
searchTerm
)
=>
_db
.
Users
.
Where
(
u
=>
u
.
Email
.
ToLower
().
Contains
(
searchTerm
.
ToLower
()));
}
}
\ No newline at end of file
PhoneStore/Views/Account/PartialViews/SearchResultPartial.cshtml
0 → 100644
View file @
34e9f927
@model IEnumerable<User>
@if (Model.Any())
{
var i = 1;
<table class="table table-striped">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Email</th>
<th scope="col">UserName</th>
<th scope="col">Age</th>
</tr>
</thead>
<tbody>
@foreach (var user in Model)
{
<tr>
<th scope="row" id="@user.Id">@(i++)</th>
<td>@user.Name</td>
<td>@user.Email</td>
<td>@user.UserName</td>
<td>@user.Age</td>
</tr>
}
</tbody>
</table>
}
else
{
<p>Список пуст</p>
}
\ No newline at end of file
PhoneStore/Views/Phones/About.cshtml
View file @
34e9f927
@model Phone
@model Phone
ViewModel
@{
ViewBag.Title = "Подробная информация";
...
...
PhoneStore/Views/Shared/_Layout.cshtml
View file @
34e9f927
...
...
@@ -27,6 +27,9 @@
<li
class=
"nav-item"
>
<a
class=
"nav-link text-dark"
asp-area=
""
asp-controller=
"Brands"
asp-action=
"Create"
>
Добавить бренд
</a>
</li>
<li
class=
"nav-item"
>
<input
type=
"text"
id=
"search"
class=
"form-control"
placeholder=
"Критерии для поиска"
>
</li>
</ul>
</div>
<div
class=
"login_group"
>
...
...
@@ -49,6 +52,7 @@
</header>
<div
class=
"container"
>
<main
role=
"main"
class=
"pb-3"
>
<div
id=
"results"
></div>
@RenderBody()
</main>
</div>
...
...
PhoneStore/appsettings.json
View file @
34e9f927
{
"ConnectionStrings"
:
{
"DefaultConnection"
:
"Server=localhost;Port=54320;database=lesson
58
;Username=postgres;Password=postgres;"
"DefaultConnection"
:
"Server=localhost;Port=54320;database=lesson
63
;Username=postgres;Password=postgres;"
},
"Logging"
:
{
"LogLevel"
:
{
...
...
PhoneStore/wwwroot/js/site.js
View file @
34e9f927
// Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
// for details on configuring this project to bundle and minify static web assets.
// Write your JavaScript code.
$
(
document
).
ready
(
function
(){
$
(
'#search'
).
on
(
'keyup'
,
function
(
e
){
e
.
preventDefault
();
let
searchTerm
=
$
(
this
).
val
();
console
.
log
(
searchTerm
)
searchTerm
=
encodeURIComponent
(
searchTerm
);
console
.
log
(
searchTerm
)
$
(
'#results'
)
.
load
(
`https://localhost:5001/Account/SearchAccounts?searchTerm=
${
searchTerm
}
`
);
})
});
\ No newline at end of file
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