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
328ca1aa
Commit
328ca1aa
authored
Aug 08, 2022
by
Пасько Виталий
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Вынес создание отзыва в сервис.
parent
a51fd677
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
88 additions
and
32 deletions
+88
-32
FeedbackController.cs
PhoneStore/Controllers/FeedbackController.cs
+11
-30
FeedbackMapper.cs
PhoneStore/Helpers/FeedbackMapper.cs
+21
-0
FeedbackService.cs
PhoneStore/Services/FeedbackService.cs
+45
-0
IFeedbackService.cs
PhoneStore/Services/Interfaces/IFeedbackService.cs
+9
-0
About.cshtml
PhoneStore/Views/Phones/About.cshtml
+1
-1
_Layout.cshtml
PhoneStore/Views/Shared/_Layout.cshtml
+1
-1
No files found.
PhoneStore/Controllers/FeedbackController.cs
View file @
328ca1aa
using
System
;
using
System.Linq
;
using
System.Text.Json
;
using
Microsoft.AspNetCore.Identity
;
using
Microsoft.AspNetCore.Identity
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.EntityFrameworkCore
;
using
PhoneStore.Models
;
using
PhoneStore.Models
;
using
PhoneStore.
ViewModel
s
;
using
PhoneStore.
Services.Interface
s
;
using
PhoneStore.ViewModels.Feedback
;
using
PhoneStore.ViewModels.Feedback
;
namespace
PhoneStore.Controllers
namespace
PhoneStore.Controllers
{
{
public
class
FeedbackController
:
Controller
public
class
FeedbackController
:
Controller
{
{
private
readonly
MobileContext
_db
;
private
readonly
UserManager
<
User
>
_userManager
;
private
readonly
UserManager
<
User
>
_userManager
;
private
readonly
IFeedbackService
_feedbackService
;
public
FeedbackController
(
MobileContext
db
,
UserManager
<
User
>
userManager
)
public
FeedbackController
(
UserManager
<
User
>
userManager
,
IFeedbackService
feedbackService
)
{
{
_db
=
db
;
_userManager
=
userManager
;
_userManager
=
userManager
;
_feedbackService
=
feedbackService
;
}
}
// GET
[
HttpGet
]
public
ActionResult
<
FeedbackViewModel
>
Create
(
FeedbackCreateViewModel
model
)
public
ActionResult
<
FeedbackViewModel
>
Create
(
FeedbackCreateViewModel
model
)
{
{
Feedback
feedback
=
new
Feedback
//TODO: валидация.
{
var
userId
=
int
.
Parse
(
_userManager
.
GetUserId
(
User
));
CreationDateTime
=
DateTime
.
Now
,
var
feedbackViewModel
=
_feedbackService
.
Create
(
model
,
userId
);
Text
=
model
.
Text
,
PhoneId
=
model
.
PhoneId
,
UserId
=
int
.
Parse
(
_userManager
.
GetUserId
(
User
))
};
_db
.
Feedbacks
.
Add
(
feedback
);
_db
.
SaveChanges
();
Feedback
newFeedback
=
_db
.
Feedbacks
.
Include
(
f
=>
f
.
User
)
.
Include
(
f
=>
f
.
Phone
)
.
First
(
f
=>
f
.
Id
==
feedback
.
Id
);
FeedbackViewModel
feedbackViewModel
=
new
FeedbackViewModel
{
Id
=
newFeedback
.
Id
,
Text
=
newFeedback
.
Text
,
PhoneId
=
newFeedback
.
PhoneId
,
UserId
=
newFeedback
.
UserId
,
CreationDateTime
=
newFeedback
.
CreationDateTime
};
return
Json
(
feedbackViewModel
);
return
Json
(
feedbackViewModel
);
}
}
}
}
...
...
PhoneStore/Helpers/FeedbackMapper.cs
0 → 100644
View file @
328ca1aa
using
PhoneStore.Models
;
using
PhoneStore.ViewModels.Feedback
;
namespace
PhoneStore.Helpers
{
public
static
class
FeedbackMapper
{
public
static
FeedbackViewModel
MapToFeedbackViewModel
(
this
Feedback
self
)
{
FeedbackViewModel
feedbackViewModel
=
new
FeedbackViewModel
{
Id
=
self
.
Id
,
Text
=
self
.
Text
,
PhoneId
=
self
.
PhoneId
,
UserId
=
self
.
UserId
,
CreationDateTime
=
self
.
CreationDateTime
};
return
feedbackViewModel
;
}
}
}
\ No newline at end of file
PhoneStore/Services/FeedbackService.cs
0 → 100644
View file @
328ca1aa
using
System
;
using
System.Linq
;
using
Microsoft.AspNetCore.Identity
;
using
Microsoft.EntityFrameworkCore
;
using
PhoneStore.Helpers
;
using
PhoneStore.Models
;
using
PhoneStore.Services.Interfaces
;
using
PhoneStore.ViewModels.Feedback
;
namespace
PhoneStore.Services
{
public
class
FeedbackService
:
IFeedbackService
{
private
readonly
MobileContext
_db
;
private
readonly
UserManager
<
User
>
_userManager
;
public
FeedbackService
(
MobileContext
db
,
UserManager
<
User
>
userManager
)
{
_db
=
db
;
_userManager
=
userManager
;
}
public
FeedbackViewModel
Create
(
FeedbackCreateViewModel
model
,
int
userId
)
{
Feedback
feedback
=
new
Feedback
{
CreationDateTime
=
DateTime
.
Now
,
Text
=
model
.
Text
,
PhoneId
=
model
.
PhoneId
,
UserId
=
userId
};
_db
.
Feedbacks
.
Add
(
feedback
);
_db
.
SaveChanges
();
Feedback
newFeedback
=
_db
.
Feedbacks
.
Include
(
f
=>
f
.
User
)
.
Include
(
f
=>
f
.
Phone
)
.
First
(
f
=>
f
.
Id
==
feedback
.
Id
);
FeedbackViewModel
feedbackViewModel
=
newFeedback
.
MapToFeedbackViewModel
();
return
feedbackViewModel
;
}
}
}
\ No newline at end of file
PhoneStore/Services/Interfaces/IFeedbackService.cs
0 → 100644
View file @
328ca1aa
using
PhoneStore.ViewModels.Feedback
;
namespace
PhoneStore.Services.Interfaces
{
public
interface
IFeedbackService
{
FeedbackViewModel
Create
(
FeedbackCreateViewModel
model
,
int
userId
);
}
}
\ No newline at end of file
PhoneStore/Views/Phones/About.cshtml
View file @
328ca1aa
...
@@ -21,7 +21,7 @@
...
@@ -21,7 +21,7 @@
<label for="text">Добавьте отзыв о телефоне</label>
<label for="text">Добавьте отзыв о телефоне</label>
<input type="text" class="form-control" id="text" placeholder="Минимальная длина отзыва 10 символов">
<input type="text" class="form-control" id="text" placeholder="Минимальная длина отзыва 10 символов">
<input type="text" hidden name="phoneId" id="@Model.Id">
<input type="text" hidden name="phoneId" id="@Model.Id">
<button class="my-3" type="submit">Отправить</button>
<button class="my-3
btn btn-outline-warning
" type="submit">Отправить</button>
</div>
</div>
</form>
</form>
}
}
...
...
PhoneStore/Views/Shared/_Layout.cshtml
View file @
328ca1aa
...
@@ -28,7 +28,7 @@
...
@@ -28,7 +28,7 @@
<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"
>
<li
class=
"nav-item"
>
<input
type=
"text"
id=
"search"
class=
"form-control"
placeholder=
"Критерии для поиска"
>
<input
type=
"text"
id=
"search"
class=
"form-control"
placeholder=
"Критерии для поиска
пользователей
"
>
</li>
</li>
</ul>
</ul>
</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