Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
lesson64Blogs
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
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
Юнусов Ибрагим
lesson64Blogs
Commits
cb7ddf60
Commit
cb7ddf60
authored
Aug 08, 2022
by
Юнусов Ибрагим
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Добавил поиск пользователя через ajax
parent
9ef1712a
Show whitespace changes
Inline
Side-by-side
Showing
27 changed files
with
179 additions
and
25 deletions
+179
-25
AccountController.cs
PhoneStore/Controllers/AccountController.cs
+19
-2
BasketsController.cs
PhoneStore/Controllers/BasketsController.cs
+1
-1
PhonesController.cs
PhoneStore/Controllers/PhonesController.cs
+1
-1
ServiceConnector.cs
PhoneStore/Helpers/ServiceConnector.cs
+3
-1
PhoneStore.csproj
PhoneStore/PhoneStore.csproj
+1
-0
AccountService.cs
PhoneStore/Services/AccountService.cs
+1
-1
BasketService.cs
PhoneStore/Services/BasketService.cs
+1
-1
DefaultPhoneImagePathProvider.cs
PhoneStore/Services/DefaultPhoneImagePathProvider.cs
+1
-1
IAccountService.cs
PhoneStore/Services/Interfaces/IAccountService.cs
+1
-3
IBasketService.cs
PhoneStore/Services/Interfaces/IBasketService.cs
+1
-1
ICreatable.cs
PhoneStore/Services/Interfaces/ICreatable.cs
+1
-1
IDefaultPhoneImagePathProvider.cs
...ore/Services/Interfaces/IDefaultPhoneImagePathProvider.cs
+1
-1
IPaginationService.cs
PhoneStore/Services/Interfaces/IPaginationService.cs
+1
-1
IPhoneService.cs
PhoneStore/Services/Interfaces/IPhoneService.cs
+1
-1
ISearchService.cs
PhoneStore/Services/Interfaces/ISearchService.cs
+9
-0
IUserSearchService.cs
PhoneStore/Services/Interfaces/IUserSearchService.cs
+11
-0
IUsersFilter.cs
PhoneStore/Services/Interfaces/IUsersFilter.cs
+1
-1
IUsersSortService.cs
PhoneStore/Services/Interfaces/IUsersSortService.cs
+1
-1
PaginationService.cs
PhoneStore/Services/PaginationService.cs
+1
-1
PhoneService.cs
PhoneStore/Services/PhoneService.cs
+1
-1
SearchService.cs
PhoneStore/Services/SearchService.cs
+34
-0
UserSearchService.cs
PhoneStore/Services/UserSearchService.cs
+30
-0
UsersFilter.cs
PhoneStore/Services/UsersFilter.cs
+1
-1
UsersSortService.cs
PhoneStore/Services/UsersSortService.cs
+1
-1
Startup.cs
PhoneStore/Startup.cs
+0
-1
UserSearchResultPartialView.cshtml
...s/Account/PartialViews/UserSearchResultPartialView.cshtml
+48
-0
_Layout.cshtml
PhoneStore/Views/Shared/_Layout.cshtml
+7
-2
No files found.
PhoneStore/Controllers/AccountController.cs
View file @
cb7ddf60
using
System
;
using
System.Linq
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.Mvc
;
using
PhoneStore.Enums
;
using
PhoneStore.Enums
;
using
PhoneStore.Helpers
;
using
PhoneStore.Helpers
;
using
PhoneStore.Services.
Abstraction
s
;
using
PhoneStore.Services.
Interface
s
;
using
PhoneStore.ViewModels.Account
;
using
PhoneStore.ViewModels.Account
;
namespace
PhoneStore.Controllers
namespace
PhoneStore.Controllers
...
@@ -11,10 +12,12 @@ namespace PhoneStore.Controllers
...
@@ -11,10 +12,12 @@ namespace PhoneStore.Controllers
public
class
AccountController
:
Controller
public
class
AccountController
:
Controller
{
{
private
readonly
IAccountService
_accountService
;
private
readonly
IAccountService
_accountService
;
private
readonly
ISearchService
_searchService
;
public
AccountController
(
IAccountService
accountService
)
public
AccountController
(
IAccountService
accountService
,
ISearchService
searchService
)
{
{
_accountService
=
accountService
;
_accountService
=
accountService
;
_searchService
=
searchService
;
}
}
[
HttpGet
]
[
HttpGet
]
...
@@ -73,5 +76,19 @@ namespace PhoneStore.Controllers
...
@@ -73,5 +76,19 @@ namespace PhoneStore.Controllers
await
_accountService
.
LogOf
();
await
_accountService
.
LogOf
();
return
RedirectToAction
(
"Index"
,
"Phones"
);
return
RedirectToAction
(
"Index"
,
"Phones"
);
}
}
[
HttpGet
]
public
IActionResult
SearchAccounts
(
string
searchTerm
)
{
try
{
var
users
=
_searchService
.
SearchUsersByAny
(
searchTerm
);
return
PartialView
(
"PartialViews/UserSearchResultPartialView"
,
users
);
}
catch
(
Exception
e
)
{
return
StatusCode
(
500
,
e
.
Message
);
}
}
}
}
}
}
\ No newline at end of file
PhoneStore/Controllers/BasketsController.cs
View file @
cb7ddf60
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.Mvc
;
using
PhoneStore.Enums
;
using
PhoneStore.Enums
;
using
PhoneStore.Services.
Abstraction
s
;
using
PhoneStore.Services.
Interface
s
;
using
PhoneStore.ViewModels
;
using
PhoneStore.ViewModels
;
namespace
PhoneStore.Controllers
namespace
PhoneStore.Controllers
...
...
PhoneStore/Controllers/PhonesController.cs
View file @
cb7ddf60
...
@@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Mvc;
...
@@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Mvc;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore
;
using
PhoneStore.Helpers
;
using
PhoneStore.Helpers
;
using
PhoneStore.Models
;
using
PhoneStore.Models
;
using
PhoneStore.Services.
Abstraction
s
;
using
PhoneStore.Services.
Interface
s
;
using
PhoneStore.ViewModels
;
using
PhoneStore.ViewModels
;
namespace
PhoneStore.Controllers
namespace
PhoneStore.Controllers
...
...
PhoneStore/Helpers/ServiceConnector.cs
View file @
cb7ddf60
...
@@ -2,7 +2,7 @@ using Microsoft.Extensions.Configuration;
...
@@ -2,7 +2,7 @@ using Microsoft.Extensions.Configuration;
using
Microsoft.Extensions.DependencyInjection
;
using
Microsoft.Extensions.DependencyInjection
;
using
PhoneStore.Models
;
using
PhoneStore.Models
;
using
PhoneStore.Services
;
using
PhoneStore.Services
;
using
PhoneStore.Services.
Abstraction
s
;
using
PhoneStore.Services.
Interface
s
;
namespace
PhoneStore.Helpers
namespace
PhoneStore.Helpers
{
{
...
@@ -22,6 +22,8 @@ namespace PhoneStore.Helpers
...
@@ -22,6 +22,8 @@ namespace PhoneStore.Helpers
services
.
AddTransient
<
IUsersFilter
,
UsersFilter
>();
services
.
AddTransient
<
IUsersFilter
,
UsersFilter
>();
services
.
AddTransient
<
IPaginationService
<
User
>,
PaginationService
<
User
>>();
services
.
AddTransient
<
IPaginationService
<
User
>,
PaginationService
<
User
>>();
services
.
AddTransient
<
IAccountService
,
AccountService
>();
services
.
AddTransient
<
IAccountService
,
AccountService
>();
services
.
AddTransient
<
ISearchService
,
SearchService
>();
services
.
AddScoped
<
IUserSearchService
,
UserSearchService
>();
}
}
}
}
}
}
\ No newline at end of file
PhoneStore/PhoneStore.csproj
View file @
cb7ddf60
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
<ItemGroup>
<ItemGroup>
<_ContentIncludedByDefault Remove="wwwroot\Files\book.pdf" />
<_ContentIncludedByDefault Remove="wwwroot\Files\book.pdf" />
<_ContentIncludedByDefault Remove="Views\Searchs\Search.cshtml" />
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
...
...
PhoneStore/Services/AccountService.cs
View file @
cb7ddf60
...
@@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Identity;
...
@@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Identity;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.Mvc
;
using
PhoneStore.Enums
;
using
PhoneStore.Enums
;
using
PhoneStore.Models
;
using
PhoneStore.Models
;
using
PhoneStore.Services.
Abstraction
s
;
using
PhoneStore.Services.
Interface
s
;
using
PhoneStore.ViewModels.Account
;
using
PhoneStore.ViewModels.Account
;
using
IdentityResult
=
PhoneStore
.
DataObjects
.
IdentityResult
;
using
IdentityResult
=
PhoneStore
.
DataObjects
.
IdentityResult
;
using
SignInResult
=
Microsoft
.
AspNetCore
.
Identity
.
SignInResult
;
using
SignInResult
=
Microsoft
.
AspNetCore
.
Identity
.
SignInResult
;
...
...
PhoneStore/Services/BasketService.cs
View file @
cb7ddf60
...
@@ -3,7 +3,7 @@ using System.Linq;
...
@@ -3,7 +3,7 @@ using System.Linq;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore
;
using
PhoneStore.Enums
;
using
PhoneStore.Enums
;
using
PhoneStore.Models
;
using
PhoneStore.Models
;
using
PhoneStore.Services.
Abstraction
s
;
using
PhoneStore.Services.
Interface
s
;
namespace
PhoneStore.Services
namespace
PhoneStore.Services
{
{
...
...
PhoneStore/Services/DefaultPhoneImagePathProvider.cs
View file @
cb7ddf60
using
PhoneStore.Services.
Abstraction
s
;
using
PhoneStore.Services.
Interface
s
;
namespace
PhoneStore.Services
namespace
PhoneStore.Services
{
{
...
...
PhoneStore/Services/
Abstraction
s/IAccountService.cs
→
PhoneStore/Services/
Interface
s/IAccountService.cs
View file @
cb7ddf60
using
System.Collections.Generic
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
PhoneStore.DataObjects
;
using
PhoneStore.DataObjects
;
using
PhoneStore.Models
;
using
PhoneStore.ViewModels.Account
;
using
PhoneStore.ViewModels.Account
;
namespace
PhoneStore.Services.
Abstraction
s
namespace
PhoneStore.Services.
Interface
s
{
{
public
interface
IAccountService
public
interface
IAccountService
{
{
...
...
PhoneStore/Services/
Abstraction
s/IBasketService.cs
→
PhoneStore/Services/
Interface
s/IBasketService.cs
View file @
cb7ddf60
...
@@ -2,7 +2,7 @@ using System.Collections.Generic;
...
@@ -2,7 +2,7 @@ using System.Collections.Generic;
using
PhoneStore.Enums
;
using
PhoneStore.Enums
;
using
PhoneStore.Models
;
using
PhoneStore.Models
;
namespace
PhoneStore.Services.
Abstraction
s
namespace
PhoneStore.Services.
Interface
s
{
{
public
interface
IBasketService
public
interface
IBasketService
{
{
...
...
PhoneStore/Services/
Abstraction
s/ICreatable.cs
→
PhoneStore/Services/
Interface
s/ICreatable.cs
View file @
cb7ddf60
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
namespace
PhoneStore.Services.
Abstraction
s
namespace
PhoneStore.Services.
Interface
s
{
{
public
interface
ICreatable
<
in
T
>
where
T
:
class
public
interface
ICreatable
<
in
T
>
where
T
:
class
{
{
...
...
PhoneStore/Services/
Abstraction
s/IDefaultPhoneImagePathProvider.cs
→
PhoneStore/Services/
Interface
s/IDefaultPhoneImagePathProvider.cs
View file @
cb7ddf60
namespace
PhoneStore.Services.
Abstraction
s
namespace
PhoneStore.Services.
Interface
s
{
{
public
interface
IDefaultPhoneImagePathProvider
public
interface
IDefaultPhoneImagePathProvider
{
{
...
...
PhoneStore/Services/
Abstraction
s/IPaginationService.cs
→
PhoneStore/Services/
Interface
s/IPaginationService.cs
View file @
cb7ddf60
using
System.Linq
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
namespace
PhoneStore.Services.
Abstraction
s
namespace
PhoneStore.Services.
Interface
s
{
{
public
interface
IPaginationService
<
T
>
public
interface
IPaginationService
<
T
>
{
{
...
...
PhoneStore/Services/
Abstraction
s/IPhoneService.cs
→
PhoneStore/Services/
Interface
s/IPhoneService.cs
View file @
cb7ddf60
using
PhoneStore.ViewModels
;
using
PhoneStore.ViewModels
;
namespace
PhoneStore.Services.
Abstraction
s
namespace
PhoneStore.Services.
Interface
s
{
{
public
interface
IPhoneService
:
ICreatable
<
PhoneCreateViewModel
>
public
interface
IPhoneService
:
ICreatable
<
PhoneCreateViewModel
>
{
{
...
...
PhoneStore/Services/Interfaces/ISearchService.cs
0 → 100644
View file @
cb7ddf60
using
System.Collections.Generic
;
using
PhoneStore.Models
;
namespace
PhoneStore.Services.Interfaces
;
public
interface
ISearchService
{
IEnumerable
<
User
>
SearchUsersByAny
(
string
searchTerm
);
}
\ No newline at end of file
PhoneStore/Services/Interfaces/IUserSearchService.cs
0 → 100644
View file @
cb7ddf60
using
System.Collections.Generic
;
using
PhoneStore.Models
;
namespace
PhoneStore.Services.Interfaces
;
public
interface
IUserSearchService
{
IEnumerable
<
User
>
SearchByName
(
string
searchTerm
);
IEnumerable
<
User
>
SearchByLogin
(
string
searchTerm
);
IEnumerable
<
User
>
SearchByEmail
(
string
searchTerm
);
}
\ No newline at end of file
PhoneStore/Services/
Abstraction
s/IUsersFilter.cs
→
PhoneStore/Services/
Interface
s/IUsersFilter.cs
View file @
cb7ddf60
using
System.Linq
;
using
System.Linq
;
using
PhoneStore.Models
;
using
PhoneStore.Models
;
namespace
PhoneStore.Services.
Abstraction
s
namespace
PhoneStore.Services.
Interface
s
{
{
public
interface
IUsersFilter
public
interface
IUsersFilter
{
{
...
...
PhoneStore/Services/
Abstraction
s/IUsersSortService.cs
→
PhoneStore/Services/
Interface
s/IUsersSortService.cs
View file @
cb7ddf60
...
@@ -2,7 +2,7 @@ using System.Linq;
...
@@ -2,7 +2,7 @@ using System.Linq;
using
PhoneStore.Models
;
using
PhoneStore.Models
;
using
Order
=
PhoneStore
.
Enums
.
Order
;
using
Order
=
PhoneStore
.
Enums
.
Order
;
namespace
PhoneStore.Services.
Abstraction
s
namespace
PhoneStore.Services.
Interface
s
{
{
public
interface
IUsersSortService
public
interface
IUsersSortService
{
{
...
...
PhoneStore/Services/PaginationService.cs
View file @
cb7ddf60
using
System.Linq
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore
;
using
PhoneStore.Services.
Abstraction
s
;
using
PhoneStore.Services.
Interface
s
;
namespace
PhoneStore.Services
namespace
PhoneStore.Services
{
{
...
...
PhoneStore/Services/PhoneService.cs
View file @
cb7ddf60
...
@@ -5,7 +5,7 @@ using System.Threading.Tasks;
...
@@ -5,7 +5,7 @@ using System.Threading.Tasks;
using
Microsoft.Extensions.Hosting
;
using
Microsoft.Extensions.Hosting
;
using
PhoneStore.Helpers
;
using
PhoneStore.Helpers
;
using
PhoneStore.Models
;
using
PhoneStore.Models
;
using
PhoneStore.Services.
Abstraction
s
;
using
PhoneStore.Services.
Interface
s
;
using
PhoneStore.ViewModels
;
using
PhoneStore.ViewModels
;
namespace
PhoneStore.Services
namespace
PhoneStore.Services
...
...
PhoneStore/Services/SearchService.cs
0 → 100644
View file @
cb7ddf60
using
System.Collections.Generic
;
using
System.Linq
;
using
PhoneStore.Models
;
using
PhoneStore.Services.Interfaces
;
namespace
PhoneStore.Services
;
public
class
SearchService
:
ISearchService
{
private
readonly
IUserSearchService
_userSearch
;
public
SearchService
(
IUserSearchService
userSearch
)
{
_userSearch
=
userSearch
;
}
public
IEnumerable
<
User
>
SearchUsersByAny
(
string
searchTerm
)
{
var
resultByName
=
_userSearch
.
SearchByName
(
searchTerm
);
var
resultByLogin
=
_userSearch
.
SearchByLogin
(
searchTerm
);
var
resultByEmail
=
_userSearch
.
SearchByEmail
(
searchTerm
);
var
users
=
resultByName
.
Concat
(
resultByLogin
)
.
Concat
(
resultByEmail
)
.
ToHashSet
();
//if (users == null || !users.Any())
if
(
users
?.
Any
()
??
false
)
{
return
users
;
}
return
new
List
<
User
>();
}
}
\ No newline at end of file
PhoneStore/Services/UserSearchService.cs
0 → 100644
View file @
cb7ddf60
using
System.Collections.Generic
;
using
System.Linq
;
using
PhoneStore.Models
;
using
PhoneStore.Services.Interfaces
;
namespace
PhoneStore.Services
;
public
class
UserSearchService
:
IUserSearchService
{
private
readonly
MobileContext
_db
;
public
UserSearchService
(
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/Services/UsersFilter.cs
View file @
cb7ddf60
using
System.Linq
;
using
System.Linq
;
using
PhoneStore.Models
;
using
PhoneStore.Models
;
using
PhoneStore.Services.
Abstraction
s
;
using
PhoneStore.Services.
Interface
s
;
namespace
PhoneStore.Services
namespace
PhoneStore.Services
{
{
...
...
PhoneStore/Services/UsersSortService.cs
View file @
cb7ddf60
using
System.Linq
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
PhoneStore.Models
;
using
PhoneStore.Models
;
using
PhoneStore.Services.
Abstraction
s
;
using
PhoneStore.Services.
Interface
s
;
using
Order
=
PhoneStore
.
Enums
.
Order
;
using
Order
=
PhoneStore
.
Enums
.
Order
;
namespace
PhoneStore.Services
namespace
PhoneStore.Services
...
...
PhoneStore/Startup.cs
View file @
cb7ddf60
...
@@ -9,7 +9,6 @@ using Microsoft.Extensions.Hosting;
...
@@ -9,7 +9,6 @@ using Microsoft.Extensions.Hosting;
using
PhoneStore.Helpers
;
using
PhoneStore.Helpers
;
using
PhoneStore.Models
;
using
PhoneStore.Models
;
using
PhoneStore.Services
;
using
PhoneStore.Services
;
using
PhoneStore.Services.Abstractions
;
namespace
PhoneStore
namespace
PhoneStore
{
{
...
...
PhoneStore/Views/Account/PartialViews/UserSearchResultPartialView.cshtml
0 → 100644
View file @
cb7ddf60
@model IEnumerable<User>
@if (Model.Any())
{
var count = 1;
<table class="table">
<caption>Список пользователей</caption>
<thead>
<tr>
<th scope="col">
#
</th>
<th scope="col">
Имя
</th>
<th scope="col">
Login
</th>
<th scope="col">
Email
</th>
<th scope="col">
Age
</th>
<th scope="col">
Phone
</th>
</tr>
</thead>
<tbody>
@foreach (var user in Model)
{
<tr>
<th scope="row" id="@user.Id">@(count++)</th>
<td id="name">@user.Name</td>
<td id="username">@user.UserName</td>
<td id="email">@user.Email</td>
<td id="age">@user.Age</td>
<td id="phone">@(string.IsNullOrWhiteSpace(user.PhoneNumber) ? "номера нет" : user.PhoneNumber)</td>
</tr>
}
</tbody>
</table>
}
else
{
<h2>Таких пользователей нет</h2>
}
\ No newline at end of file
PhoneStore/Views/Shared/_Layout.cshtml
View file @
cb7ddf60
...
@@ -27,10 +27,14 @@
...
@@ -27,10 +27,14 @@
<li
class=
"nav-item"
>
<li
class=
"nav-item"
>
<a
class=
"nav-link text-dark"
asp-area=
""
asp-controller=
"Brands"
asp-action=
"Create"
>
Добавить бренд
</a>
<a
class=
"nav-link text-dark"
asp-area=
""
asp-controller=
"Brands"
asp-action=
"Create"
>
Добавить бренд
</a>
</li>
</li>
<li
class=
"nav-item"
>
<input
type=
"text"
id=
"search"
class=
"form-control"
placeholder=
"Критерии для поиска"
>
</li>
</ul>
</ul>
</div>
</div>
<div
class=
"login_group"
>
<div
class=
"login_group"
>
@if(User.Identity.IsAuthenticated)
@if
(User.Identity.IsAuthenticated)
{
{
<p>
@User.Identity.Name
</p>
<p>
@User.Identity.Name
</p>
...
@@ -49,6 +53,7 @@
...
@@ -49,6 +53,7 @@
</header>
</header>
<div
class=
"container"
>
<div
class=
"container"
>
<main
role=
"main"
class=
"pb-3"
>
<main
role=
"main"
class=
"pb-3"
>
<div
id=
"results"
></div>
@RenderBody()
@RenderBody()
</main>
</main>
</div>
</div>
...
...
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