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
9f25a7aa
Commit
9f25a7aa
authored
Aug 30, 2022
by
Пасько Виталий
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor:
-Определил общий интерфейс для старницы создания и изменения телефона.
parent
8fdac13f
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
64 additions
and
19 deletions
+64
-19
OrdersController.cs
PhoneStore/Controllers/OrdersController.cs
+1
-1
PhoneValidatorController.cs
PhoneStore/Controllers/PhoneValidatorController.cs
+8
-1
PhonesController.cs
PhoneStore/Controllers/PhonesController.cs
+2
-2
OrderMapper.cs
PhoneStore/Mappers/OrderMapper.cs
+1
-1
PhoneStore.csproj
PhoneStore/PhoneStore.csproj
+0
-4
IPhoneEditable.cs
PhoneStore/ViewModels/PhoneViewModels/IPhoneEditable.cs
+24
-0
PhoneCreateViewModel.cs
...eStore/ViewModels/PhoneViewModels/PhoneCreateViewModel.cs
+1
-1
PhoneEditViewModel.cs
PhoneStore/ViewModels/PhoneViewModels/PhoneEditViewModel.cs
+16
-0
About.cshtml
PhoneStore/Views/Phones/About.cshtml
+4
-4
Create.cshtml
PhoneStore/Views/Phones/Create.cshtml
+1
-1
Edit.cshtml
PhoneStore/Views/Phones/Edit.cshtml
+1
-1
Index.cshtml
PhoneStore/Views/Phones/Index.cshtml
+1
-1
PhoneFormPartialView.cshtml
...ore/Views/Phones/PartialViews/PhoneFormPartialView.cshtml
+1
-1
FeedbackPartialView.cshtml
...tore/Views/Shared/PartialViews/FeedbackPartialView.cshtml
+1
-1
_ViewImports.cshtml
PhoneStore/Views/_ViewImports.cshtml
+2
-0
No files found.
PhoneStore/Controllers/OrdersController.cs
View file @
9f25a7aa
...
...
@@ -50,7 +50,7 @@ namespace PhoneStore.Controllers
{
order
.
UserId
=
int
.
Parse
(
_userManager
.
GetUserId
(
User
));
order
.
User
=
null
;
_orderService
.
Create
(
order
.
MapToOrder
ViewModel
());
_orderService
.
Create
(
order
.
MapToOrder
());
return
RedirectToAction
(
"Index"
);
}
...
...
PhoneStore/Controllers/PhoneValidatorController.cs
View file @
9f25a7aa
...
...
@@ -15,8 +15,15 @@ namespace PhoneStore.Controllers
}
[
AcceptVerbs
(
"GET"
,
"POST"
)]
public
bool
CheckName
(
string
name
)
public
bool
CheckName
(
string
name
,
int
?
id
)
{
if
(
id
.
HasValue
)
{
return
!
_db
.
Phones
.
AsEnumerable
()
.
Any
(
p
=>
p
.
Name
.
Equals
(
name
,
StringComparison
.
CurrentCulture
)
&&
p
.
Id
!=
id
.
Value
);
}
return
!
_db
.
Phones
.
AsEnumerable
()
.
Any
(
p
=>
p
.
Name
.
Equals
(
name
,
StringComparison
.
CurrentCulture
));
...
...
PhoneStore/Controllers/PhonesController.cs
View file @
9f25a7aa
...
...
@@ -47,7 +47,7 @@ namespace PhoneStore.Controllers
[
HttpGet
]
public
IActionResult
Create
()
{
PhoneCreateViewModel
model
=
new
PhoneCreateViewModel
IPhoneEditable
model
=
new
PhoneCreateViewModel
{
Brands
=
_db
.
Brands
.
ToList
()
};
...
...
@@ -111,7 +111,7 @@ namespace PhoneStore.Controllers
if
(
phone
is
null
)
return
RedirectToAction
(
"Error"
,
"Errors"
,
new
{
statusCode
=
777
});
PhoneCreateViewModel
model
=
new
PhoneCreate
ViewModel
IPhoneEditable
model
=
new
PhoneEdit
ViewModel
{
Id
=
phone
.
Id
,
Name
=
phone
.
Name
,
...
...
PhoneStore/Mappers/OrderMapper.cs
View file @
9f25a7aa
...
...
@@ -18,7 +18,7 @@ namespace PhoneStore.Mappers
Id
=
self
.
Id
};
}
public
static
Order
MapToOrder
(
this
OrderViewModel
self
)
{
return
new
Order
...
...
PhoneStore/PhoneStore.csproj
View file @
9f25a7aa
...
...
@@ -20,8 +20,4 @@
<_ContentIncludedByDefault Remove="wwwroot\Files\book.pdf" />
</ItemGroup>
<ItemGroup>
<Folder Include="Pages" />
</ItemGroup>
</Project>
PhoneStore/ViewModels/PhoneViewModels/IPhoneEditable.cs
0 → 100644
View file @
9f25a7aa
using
System.Collections.Generic
;
using
System.ComponentModel.DataAnnotations
;
using
Microsoft.AspNetCore.Http
;
using
Microsoft.AspNetCore.Mvc
;
using
PhoneStore.Models
;
namespace
PhoneStore.ViewModels.PhoneViewModels
{
public
interface
IPhoneEditable
{
public
int
Id
{
get
;
set
;
}
[
Required
(
ErrorMessage
=
"Поле обязательно для заполнения"
)]
[
Remote
(
"CheckName"
,
"PhoneValidator"
,
ErrorMessage
=
"Имя занято"
,
AdditionalFields
=
nameof
(
Id
))]
[
StringLength
(
50
,
MinimumLength
=
3
,
ErrorMessage
=
"Минимальная длина 3 символа, максимальная - 50"
)]
public
string
Name
{
get
;
set
;
}
[
Required
(
ErrorMessage
=
"Поле обязательно для заполнения"
)]
[
Range
(
1000
,
50000
,
ErrorMessage
=
"Значение не валидно, вводить можно знаение от 1000 до 5000"
)]
public
decimal
?
Price
{
get
;
set
;
}
public
int
BrandId
{
get
;
set
;
}
public
List
<
Brand
>
Brands
{
get
;
set
;
}
public
IFormFile
File
{
get
;
set
;
}
public
string
Image
{
get
;
set
;
}
}
}
\ No newline at end of file
PhoneStore/ViewModels/PhoneViewModels/PhoneCreateViewModel.cs
View file @
9f25a7aa
...
...
@@ -6,7 +6,7 @@ using PhoneStore.Models;
namespace
PhoneStore.ViewModels.PhoneViewModels
{
public
class
PhoneCreateViewModel
:
BaseEntity
public
class
PhoneCreateViewModel
:
BaseEntity
,
IPhoneEditable
{
[
Required
(
ErrorMessage
=
"Поле обязательно для заполнения"
)]
[
Remote
(
"CheckName"
,
"PhoneValidator"
,
ErrorMessage
=
"Имя занято"
)]
...
...
PhoneStore/ViewModels/PhoneViewModels/PhoneEditViewModel.cs
0 → 100644
View file @
9f25a7aa
using
System.Collections.Generic
;
using
Microsoft.AspNetCore.Http
;
using
PhoneStore.Models
;
namespace
PhoneStore.ViewModels.PhoneViewModels
{
public
class
PhoneEditViewModel
:
BaseEntity
,
IPhoneEditable
{
public
string
Name
{
get
;
set
;
}
public
decimal
?
Price
{
get
;
set
;
}
public
int
BrandId
{
get
;
set
;
}
public
List
<
Brand
>
Brands
{
get
;
set
;
}
public
IFormFile
File
{
get
;
set
;
}
public
string
Image
{
get
;
set
;
}
}
}
\ No newline at end of file
PhoneStore/Views/Phones/About.cshtml
View file @
9f25a7aa
@using PhoneStore.Repositories.Interfaces
@using Microsoft.AspNetCore.Identity
@model Phone
Store.ViewModels.PhoneViewModels.Phone
ViewModel
@inject IFeedbackRepository
_f
eedbackRepository;
@inject UserManager<User>
_u
serManager;
@model PhoneViewModel
@inject IFeedbackRepository
F
eedbackRepository;
@inject UserManager<User>
U
serManager;
@{
ViewBag.Title = "Подробная информация";
Layout = "_Layout";
...
...
@@ -18,7 +18,7 @@
</div>
@if (User.Identity.IsAuthenticated)
{
if (!
_feedbackRepository.CheckFeedbackExists(int.Parse(_u
serManager.GetUserId(User)), Model.Id))
if (!
FeedbackRepository.CheckFeedbackExists(int.Parse(U
serManager.GetUserId(User)), Model.Id))
{
<form class="mb-3" id="feedbackForm">
<div class="form-group">
...
...
PhoneStore/Views/Phones/Create.cshtml
View file @
9f25a7aa
@model
PhoneStore.ViewModels.PhoneViewModels.PhoneCreateViewModel
@model
IPhoneEditable
@{
ViewBag.Title = "title";
...
...
PhoneStore/Views/Phones/Edit.cshtml
View file @
9f25a7aa
@model
PhoneStore.ViewModels.PhoneViewModels.PhoneCreateViewModel
@model
IPhoneEditable
@{
ViewBag.Title = "Редактирование";
...
...
PhoneStore/Views/Phones/Index.cshtml
View file @
9f25a7aa
...
...
@@ -4,7 +4,7 @@
ViewBag.Title = "Смартфоны";
Layout = "_Layout";
}
@if (
Model.Phones.Count() == 0
)
@if (
!Model.Phones.Any()
)
{
<h2>Список пуст.</h2>
}
...
...
PhoneStore/Views/Phones/PartialViews/PhoneFormPartialView.cshtml
View file @
9f25a7aa
@model PhoneStore.ViewModels.PhoneViewModels.
PhoneCreateViewModel
@model PhoneStore.ViewModels.PhoneViewModels.
IPhoneEditable
<div class="mb-3">
<label asp-for="Name" class="form-label">Наименование</label>
<input type="text" class="form-control" asp-for="Name">
...
...
PhoneStore/Views/Shared/PartialViews/FeedbackPartialView.cshtml
View file @
9f25a7aa
@using Microsoft.AspNetCore.Identity
@model
PhoneStore.ViewModels.Feedback.
FeedbackViewModel
@model FeedbackViewModel
@inject UserManager<User> UserManager;
<div id="@Model.Id" class="card mb-3">
...
...
PhoneStore/Views/_ViewImports.cshtml
View file @
9f25a7aa
...
...
@@ -2,4 +2,6 @@
@using PhoneStore.Models
@using PhoneStore.ViewModels
@using PhoneStore.ViewModels.Account
@using PhoneStore.ViewModels.PhoneViewModels
@using PhoneStore.ViewModels.Feedback
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
\ 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