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
0402a7a2
Commit
0402a7a2
authored
Aug 09, 2022
by
Пасько Виталий
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- добавил библиотеку для валидации.
parent
004b98d5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
3 deletions
+44
-3
FeedbackController.cs
PhoneStore/Controllers/FeedbackController.cs
+15
-3
ValidationsConnector.cs
PhoneStore/Helpers/ValidationsConnector.cs
+13
-0
PhoneStore.csproj
PhoneStore/PhoneStore.csproj
+1
-0
Startup.cs
PhoneStore/Startup.cs
+1
-0
FeedbackValidation.cs
PhoneStore/Validations/FeedbackValidation.cs
+14
-0
No files found.
PhoneStore/Controllers/FeedbackController.cs
View file @
0402a7a2
using
System.Linq
;
using
System.Threading.Tasks
;
using
Microsoft.AspNetCore.Mvc
;
using
PhoneStore.Models
;
using
PhoneStore.Services.Interfaces
;
using
PhoneStore.Validations
;
using
PhoneStore.ViewModels
;
using
PhoneStore.ViewModels.Feedback
;
...
...
@@ -11,17 +13,27 @@ namespace PhoneStore.Controllers
{
private
readonly
IFeedbackService
_feedbackService
;
private
readonly
MobileContext
_db
;
private
readonly
FeedbackValidation
_feedbackValidation
;
public
FeedbackController
(
IFeedbackService
feedbackService
,
MobileContext
db
)
public
FeedbackController
(
IFeedbackService
feedbackService
,
MobileContext
db
,
FeedbackValidation
feedbackValidation
)
{
_feedbackService
=
feedbackService
;
_db
=
db
;
_feedbackValidation
=
feedbackValidation
;
}
[
HttpPost
]
public
IActionResult
Create
(
FeedbackCreateViewModel
model
)
public
async
Task
<
IActionResult
>
Create
(
FeedbackCreateViewModel
model
)
{
//TODO: валидация.
var
validationResult
=
await
_feedbackValidation
.
ValidateAsync
(
model
);
if
(!
validationResult
.
IsValid
)
{
//TODO: сформировать сообщение
return
NotFound
();
}
var
feedbackViewModel
=
_feedbackService
.
Create
(
model
,
User
);
return
PartialView
(
"PartialViews/FeedbackPartialView"
,
feedbackViewModel
);
}
...
...
PhoneStore/Helpers/ValidationsConnector.cs
0 → 100644
View file @
0402a7a2
using
Microsoft.Extensions.DependencyInjection
;
using
PhoneStore.Validations
;
namespace
PhoneStore.Helpers
{
public
static
class
ValidationsConnector
{
public
static
void
AddValidationServices
(
this
IServiceCollection
services
)
{
services
.
AddTransient
<
FeedbackValidation
>();
}
}
}
\ No newline at end of file
PhoneStore/PhoneStore.csproj
View file @
0402a7a2
...
...
@@ -5,6 +5,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentValidation" Version="11.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.17" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.17">
<PrivateAssets>all</PrivateAssets>
...
...
PhoneStore/Startup.cs
View file @
0402a7a2
...
...
@@ -29,6 +29,7 @@ namespace PhoneStore
.
AddEntityFrameworkStores
<
MobileContext
>();
services
.
AddControllersWithViews
();
services
.
AddApplicationServices
(
Configuration
);
services
.
AddValidationServices
();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
...
...
PhoneStore/Validations/FeedbackValidation.cs
0 → 100644
View file @
0402a7a2
using
FluentValidation
;
using
PhoneStore.ViewModels.Feedback
;
namespace
PhoneStore.Validations
{
public
class
FeedbackValidation
:
AbstractValidator
<
FeedbackCreateViewModel
>
{
public
FeedbackValidation
()
{
RuleFor
(
f
=>
f
.
Text
).
NotEmpty
().
MinimumLength
(
10
);
RuleFor
(
f
=>
f
.
PhoneId
).
NotEmpty
().
NotEqual
(
0
);
}
}
}
\ 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