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
e0839a9f
Commit
e0839a9f
authored
Nov 18, 2023
by
Yevgeniy Agrafenin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#3
Добавил валидацию.
parent
1e11eb19
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
24 additions
and
15 deletions
+24
-15
ValidationController.cs
CafeCritic/Controllers/ValidationController.cs
+19
-0
AddCafeViewModel.cs
CafeCritic/ViewModels/AddCafeViewModel.cs
+1
-0
IndexViewModel.cs
CafeCritic/ViewModels/IndexViewModel.cs
+0
-13
RegisterViewModel.cs
CafeCritic/ViewModels/RegisterViewModel.cs
+1
-0
Register.cshtml
CafeCritic/Views/Account/Register.cshtml
+1
-1
AddCafe.cshtml
CafeCritic/Views/Cafe/AddCafe.cshtml
+2
-1
No files found.
CafeCritic/Controllers/ValidationController.cs
0 → 100644
View file @
e0839a9f
using
CafeCritic.Context
;
using
Microsoft.AspNetCore.Mvc
;
namespace
CafeCritic.Controllers
;
public
class
ValidationController
:
Controller
{
private
readonly
CafeDbContext
_db
;
public
ValidationController
(
CafeDbContext
db
)
{
_db
=
db
;
}
public
bool
CheckEmail
(
string
email
)
=>
!
_db
.
Users
.
Any
(
u
=>
u
.
Email
==
email
);
public
bool
CheckCafeTitle
(
string
cafeTitle
)
=>
!
_db
.
Cafes
.
Any
(
u
=>
u
.
Title
==
cafeTitle
);
}
\ No newline at end of file
CafeCritic/ViewModels/AddCafeViewModel.cs
View file @
e0839a9f
...
@@ -6,6 +6,7 @@ namespace CafeCritic.ViewModels;
...
@@ -6,6 +6,7 @@ namespace CafeCritic.ViewModels;
public
class
AddCafeViewModel
public
class
AddCafeViewModel
{
{
[
Required
(
ErrorMessage
=
"Поле обязательно"
)]
[
Required
(
ErrorMessage
=
"Поле обязательно"
)]
[
Remote
(
"CheckCafeTitle"
,
"Validation"
,
ErrorMessage
=
"Заведение с такмим названием уже существуе"
)]
public
required
string
Title
{
get
;
set
;
}
public
required
string
Title
{
get
;
set
;
}
[
Required
(
ErrorMessage
=
"Поле обязательно"
)]
[
Required
(
ErrorMessage
=
"Поле обязательно"
)]
...
...
CafeCritic/ViewModels/IndexViewModel.cs
deleted
100644 → 0
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/RegisterViewModel.cs
View file @
e0839a9f
...
@@ -7,6 +7,7 @@ public class RegisterViewModel
...
@@ -7,6 +7,7 @@ public class RegisterViewModel
{
{
[
Required
(
ErrorMessage
=
"Для регистрации введите Email"
)]
[
Required
(
ErrorMessage
=
"Для регистрации введите Email"
)]
[
DataType
(
DataType
.
EmailAddress
)]
[
DataType
(
DataType
.
EmailAddress
)]
[
Remote
(
"CheckEmail"
,
"Validation"
,
ErrorMessage
=
"Пользователь с таким эл. адресом уже существует"
)]
public
string
Email
{
get
;
set
;
}
public
string
Email
{
get
;
set
;
}
[
Required
(
ErrorMessage
=
"Введите пароль"
)]
[
Required
(
ErrorMessage
=
"Введите пароль"
)]
...
...
CafeCritic/Views/Account/Register.cshtml
View file @
e0839a9f
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
<form asp-action="Register" method="post" asp-antiforgery="true">
<form asp-action="Register" method="post" asp-antiforgery="true">
<div class="validation" asp-validation-summary="All"></div>
<div class="validation" asp-validation-summary="All"></div>
<div class="mb-3">
<div class="mb-3">
<input asp-for="Email" class="form-control" placeholder="Email">
<input
id="email"
asp-for="Email" class="form-control" placeholder="Email">
<span asp-validation-for="Email" class="text-danger"></span>
<span asp-validation-for="Email" class="text-danger"></span>
</div>
</div>
<div class="mb-3">
<div class="mb-3">
...
...
CafeCritic/Views/Cafe/AddCafe.cshtml
View file @
e0839a9f
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
<div asp-validation-summary="ModelOnly"></div>
<div asp-validation-summary="ModelOnly"></div>
<div>
<div>
<span asp-validation-for="Title" class="text-danger"></span>
<span asp-validation-for="Title" class="text-danger"></span>
<input id="
restaurant
Title" asp-for="Title" class="form-control my-2 text-muted" placeholder="Название заведения">
<input id="
cafe
Title" asp-for="Title" class="form-control my-2 text-muted" placeholder="Название заведения">
</div>
</div>
<div>
<div>
<span asp-validation-for="Image" class="text-danger"></span>
<span asp-validation-for="Image" class="text-danger"></span>
...
@@ -26,6 +26,7 @@
...
@@ -26,6 +26,7 @@
</div>
</div>
</div>
</div>
</div>
</div>
@section Scripts
@section Scripts
{
{
@{
@{
...
...
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