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
dc4904b2
Commit
dc4904b2
authored
Nov 20, 2023
by
Yevgeniy Agrafenin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#4
Реализовал футкционал поиска заведений, добавил перечисление рейтинга.
parent
e0839a9f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
109 additions
and
5 deletions
+109
-5
CafeController.cs
CafeCritic/Controllers/CafeController.cs
+36
-4
ValidationController.cs
CafeCritic/Controllers/ValidationController.cs
+1
-1
Rating.cs
CafeCritic/Enums/Rating.cs
+17
-0
CafeMapper.cs
CafeCritic/Mappers/CafeMapper.cs
+13
-0
CafeSearch.cshtml
CafeCritic/Views/Cafe/CafeSearch.cshtml
+36
-0
_Layout.cshtml
CafeCritic/Views/Shared/_Layout.cshtml
+6
-0
No files found.
CafeCritic/Controllers/CafeController.cs
View file @
dc4904b2
using
System.ComponentModel.DataAnnotations
;
using
CafeCritic.Context
;
using
CafeCritic.Enums
;
using
CafeCritic.Mappers
;
using
CafeCritic.Models
;
using
CafeCritic.Services
;
...
...
@@ -48,6 +49,7 @@ public class CafeController : Controller
}
[
HttpPost
]
[
Authorize
]
[
ValidateAntiForgeryToken
]
[
Display
(
Name
=
"AddCafe"
)]
public
async
Task
<
IActionResult
>
AddCafeAsync
(
AddCafeViewModel
model
)
...
...
@@ -66,12 +68,42 @@ public class CafeController : Controller
public
IActionResult
Details
(
int
id
)
{
var
cafe
=
_db
.
Cafes
.
FirstOrDefault
(
c
=>
c
.
Id
==
id
);
if
(
cafe
is
null
)
var
cafe
=
_db
.
Cafes
.
Include
(
c
=>
c
.
Reviews
)
.
FirstOrDefault
(
c
=>
c
.
Id
==
id
);
_db
.
Reviews
.
Include
(
r
=>
r
.
User
)
.
ToList
();
if
(
cafe
is
not
null
)
{
return
NotFound
();
var
viewModel
=
CafeMapper
.
CafeCafeDetailViewModel
(
cafe
);
ViewBag
.
UserId
=
_userManager
.
GetUserId
(
User
);
ViewBag
.
Rating
=
new
List
<
Rating
>
{
Rating
.
One
,
Rating
.
Two
,
Rating
.
Three
,
Rating
.
Four
,
Rating
.
Five
};
return
View
(
viewModel
);
}
return
View
(
cafe
);
return
NotFound
();
}
[
HttpPost
]
[
AllowAnonymous
]
[
ValidateAntiForgeryToken
]
[
Display
(
Name
=
"CafeSearch"
)]
public
async
Task
<
IActionResult
>
CafeSearchAsync
(
string
search
)
{
var
cafes
=
await
_db
.
Cafes
.
Where
(
c
=>
c
.
Title
.
Contains
(
search
)
||
c
.
Description
.
Contains
(
search
))
.
ToListAsync
();
var
cafeViewModels
=
cafes
.
Select
(
CafeMapper
.
CafeCafeDetailViewModel
).
ToList
();
return
View
(
cafeViewModels
);
}
}
\ No newline at end of file
CafeCritic/Controllers/ValidationController.cs
View file @
dc4904b2
...
...
@@ -14,6 +14,6 @@ public class ValidationController : Controller
public
bool
CheckEmail
(
string
email
)
=>
!
_db
.
Users
.
Any
(
u
=>
u
.
Email
==
email
);
public
bool
CheckCafeTitle
(
string
cafeTitle
)
=>
!
_db
.
Cafes
.
Any
(
u
=>
u
.
Title
==
cafeTitle
);
public
bool
CheckCafeTitle
(
string
cafeTitle
)
=>
!
_db
.
Cafes
.
Any
(
c
=>
c
.
Title
==
cafeTitle
);
}
\ No newline at end of file
CafeCritic/Enums/Rating.cs
0 → 100644
View file @
dc4904b2
using
System.ComponentModel.DataAnnotations
;
namespace
CafeCritic.Enums
;
public
enum
Rating
{
[
Display
(
Name
=
"1"
)]
One
=
1
,
[
Display
(
Name
=
"2"
)]
Two
,
[
Display
(
Name
=
"3"
)]
Three
,
[
Display
(
Name
=
"4"
)]
Four
,
[
Display
(
Name
=
"5"
)]
Five
}
\ No newline at end of file
CafeCritic/Mappers/CafeMapper.cs
View file @
dc4904b2
...
...
@@ -25,4 +25,17 @@ public class CafeMapper
Description
=
cafe
.
Description
};
}
public
static
CafeDetailViewModel
CafeCafeDetailViewModel
(
Cafe
cafe
)
{
return
new
CafeDetailViewModel
{
Id
=
cafe
.
Id
,
Title
=
cafe
.
Title
,
Image
=
cafe
.
Image
,
Description
=
cafe
.
Description
,
Gallery
=
cafe
.
Gallery
,
Reviews
=
cafe
.
Reviews
};
}
}
\ No newline at end of file
CafeCritic/Views/Cafe/CafeSearch.cshtml
0 → 100644
View file @
dc4904b2
@model List<CafeCritic.ViewModels.CafeDetailViewModel>
@{
ViewBag.Title = "Поиск заведений";
Layout = "_Layout";
}
<div class="container">
@foreach (var cafe in Model)
{
<div class="card mb-3 mx-auto my-0" style="width: 570px;">
<div class="row g-0">
<div class="col-md-4">
<img src="~/@cafe.Image" class="img-fluid card_image" alt="restaurant_image">
</div>
<div class="col-md-8 text-start">
<div class="card-body">
<h5 class="card-title">Название: @cafe.Title</h5>
<ul>
<li>
Оценка: @cafe.Reviews.Count
</li>
<li>Кол-во изображений:
@if (cafe.Gallery != null)
{
@cafe.Gallery.Count
}
</li>
</ul>
</div>
</div>
</div>
</div>
}
</div>
CafeCritic/Views/Shared/_Layout.cshtml
View file @
dc4904b2
...
...
@@ -25,6 +25,12 @@
</button>
<div
class=
"navbar-collapse collapse d-sm-inline-flex justify-content-between"
>
<ul
class=
"navbar-nav flex-grow-1 justify-content-end"
>
<form
class=
"form-inline my-2 my-lg-0 search_form"
asp-action=
"CafeSearch"
asp-controller=
"Cafe"
method=
"post"
>
<input
class=
"form-control me-sm-2 search-input"
type=
"search"
aria-label=
"Search"
name=
"search"
placeholder=
"Поиск"
>
</form>
<li
class=
"nav-item"
>
<a
class=
"nav-link text-dark"
asp-area=
""
asp-controller=
"Cafe"
asp-action=
"Index"
>
Список заведений
</a>
</li>
@if (!User.Identity.IsAuthenticated)
{
<li
class=
"nav-item"
>
...
...
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