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
f1085f19
Commit
f1085f19
authored
Aug 30, 2022
by
Пасько Виталий
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: убрал лишний код.
parent
92307b0f
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
224 additions
and
18 deletions
+224
-18
OrdersController.cs
PhoneStore/Controllers/OrdersController.cs
+7
-0
PersonalAreaController.cs
PhoneStore/Controllers/PersonalAreaController.cs
+22
-0
FeedbackMapper.cs
PhoneStore/Mappers/FeedbackMapper.cs
+2
-2
PhoneMapper.cs
PhoneStore/Mappers/PhoneMapper.cs
+1
-1
Phone.cs
PhoneStore/Models/Phone.cs
+1
-1
User.cs
PhoneStore/Models/User.cs
+2
-0
PhoneStore.csproj
PhoneStore/PhoneStore.csproj
+5
-0
FeedbackRepository.cs
PhoneStore/Repositories/FeedbackRepository.cs
+5
-5
IFeedbackRepository.cs
PhoneStore/Repositories/Interfaces/IFeedbackRepository.cs
+1
-1
OrderRepository.cs
PhoneStore/Repositories/OrderRepository.cs
+6
-0
FeedbackService.cs
PhoneStore/Services/FeedbackService.cs
+18
-1
IFeedbackService.cs
PhoneStore/Services/Interfaces/IFeedbackService.cs
+4
-0
IOrderService.cs
PhoneStore/Services/Interfaces/IOrderService.cs
+0
-1
Startup.cs
PhoneStore/Startup.cs
+3
-3
PersonalAreaViewModel.cs
PhoneStore/ViewModels/PersonalAreaViewModel.cs
+12
-0
Index.cshtml
PhoneStore/Views/PersonalArea/Index.cshtml
+97
-0
_Layout.cshtml
PhoneStore/Views/Shared/_Layout.cshtml
+4
-2
appsettings.json
PhoneStore/appsettings.json
+1
-1
site.css
PhoneStore/wwwroot/css/site.css
+33
-0
No files found.
PhoneStore/Controllers/OrdersController.cs
View file @
f1085f19
...
...
@@ -48,8 +48,15 @@ namespace PhoneStore.Controllers
public
IActionResult
Create
(
OrderViewModel
order
)
{
order
.
UserId
=
int
.
Parse
(
_userManager
.
GetUserId
(
User
));
order
.
User
=
null
;
_orderService
.
Create
(
order
.
MapToOrderViewModel
());
return
RedirectToAction
(
"Index"
);
}
public
IActionResult
GetAllByUserId
(
int
id
)
{
var
model
=
_orderService
.
GetByUserId
(
id
);
return
Json
(
model
);
}
}
}
\ No newline at end of file
PhoneStore/Controllers/PersonalAreaController.cs
0 → 100644
View file @
f1085f19
using
Microsoft.AspNetCore.Mvc
;
using
PhoneStore.Services.Interfaces
;
namespace
PhoneStore.Controllers
{
public
class
PersonalAreaController
:
Controller
{
private
readonly
IFeedbackService
_feedbackService
;
public
PersonalAreaController
(
IFeedbackService
feedbackService
)
{
_feedbackService
=
feedbackService
;
}
[
HttpGet
]
public
IActionResult
Index
(
int
userId
)
{
var
model
=
_feedbackService
.
GetPersonalViewModel
(
userId
);
return
View
(
model
);
}
}
}
\ No newline at end of file
PhoneStore/Mappers/FeedbackMapper.cs
View file @
f1085f19
...
...
@@ -13,8 +13,8 @@ namespace PhoneStore.Mappers
Text
=
self
.
Text
,
PhoneId
=
self
.
PhoneId
,
UserId
=
self
.
UserId
,
User
=
self
.
User
.
MapToUserViewModel
(),
Phone
=
self
.
Phone
.
MapToPhoneViewModel
(),
User
=
self
.
User
?
.
MapToUserViewModel
(),
Phone
=
self
.
Phone
?
.
MapToPhoneViewModel
(),
CreationDateTime
=
self
.
CreationDateTime
};
return
feedbackViewModel
;
...
...
PhoneStore/Mappers/PhoneMapper.cs
View file @
f1085f19
...
...
@@ -28,7 +28,7 @@ namespace PhoneStore.Mappers
Brand
=
self
.
Brand
,
Image
=
self
.
Image
,
Id
=
self
.
Id
,
Feedbacks
=
self
.
Feedbacks
.
Select
(
f
=>
f
.
MapToFeedbackViewModel
()),
Feedbacks
=
self
.
Feedbacks
?
.
Select
(
f
=>
f
.
MapToFeedbackViewModel
()),
BrandId
=
self
.
BrandId
};
...
...
PhoneStore/Models/Phone.cs
View file @
f1085f19
...
...
@@ -10,6 +10,6 @@ namespace PhoneStore.Models
public
int
BrandId
{
get
;
set
;
}
public
Brand
Brand
{
get
;
set
;
}
public
string
Image
{
get
;
set
;
}
public
List
<
Feedback
>
Feedbacks
{
get
;
set
;
}
public
IEnumerable
<
Feedback
>
Feedbacks
{
get
;
set
;
}
}
}
\ No newline at end of file
PhoneStore/Models/User.cs
View file @
f1085f19
...
...
@@ -7,5 +7,7 @@ namespace PhoneStore.Models
{
public
string
Name
{
get
;
set
;
}
public
int
Age
{
get
;
set
;
}
public
IEnumerable
<
Feedback
>
Feedbacks
{
get
;
set
;
}
public
IEnumerable
<
Order
>
Orders
{
get
;
set
;
}
}
}
\ No newline at end of file
PhoneStore/PhoneStore.csproj
View file @
f1085f19
...
...
@@ -5,6 +5,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.17" />
<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">
...
...
@@ -18,4 +19,8 @@
<_ContentIncludedByDefault Remove="wwwroot\Files\book.pdf" />
</ItemGroup>
<ItemGroup>
<Folder Include="Pages" />
</ItemGroup>
</Project>
PhoneStore/Repositories/FeedbackRepository.cs
View file @
f1085f19
...
...
@@ -15,9 +15,6 @@ namespace PhoneStore.Repositories
_db
=
db
;
}
public
IEnumerable
<
Feedback
>
GetAllByUserId
(
int
userId
)
=>
_db
.
Feedbacks
.
Where
(
f
=>
f
.
UserId
==
userId
);
public
Feedback
GetById
(
int
id
)
{
return
_db
.
Feedbacks
...
...
@@ -41,7 +38,10 @@ namespace PhoneStore.Repositories
_db
.
SaveChanges
();
}
public
IEnumerable
<
Order
>
GetByUserId
(
int
id
)
=>
_db
.
Orders
.
Where
(
o
=>
o
.
UserId
==
id
);
public
IEnumerable
<
Feedback
>
GetByUserId
(
int
id
)
=>
_db
.
Feedbacks
.
Include
(
f
=>
f
.
Phone
)
.
Include
(
f
=>
f
.
User
)
.
Where
(
o
=>
o
.
UserId
==
id
);
}
}
\ No newline at end of file
PhoneStore/Repositories/Interfaces/IFeedbackRepository.cs
View file @
f1085f19
...
...
@@ -3,7 +3,7 @@ using PhoneStore.Repositories.Interfaces.Base;
namespace
PhoneStore.Repositories.Interfaces
{
public
interface
IFeedbackRepository
:
IBaseOperations
<
Feedback
>,
IByUserIdProvider
<
Order
>
public
interface
IFeedbackRepository
:
IBaseOperations
<
Feedback
>,
IByUserIdProvider
<
Feedback
>
{
bool
CheckFeedbackExists
(
int
userId
,
int
phoneId
);
}
...
...
PhoneStore/Repositories/OrderRepository.cs
View file @
f1085f19
...
...
@@ -3,6 +3,7 @@ using System.Linq;
using
Microsoft.EntityFrameworkCore
;
using
PhoneStore.Models
;
using
PhoneStore.Repositories.Interfaces
;
using
PhoneStore.Repositories.Interfaces.Base
;
namespace
PhoneStore.Repositories
{
...
...
@@ -30,6 +31,8 @@ namespace PhoneStore.Repositories
public
Order
GetById
(
int
id
)
=>
_db
.
Orders
.
Include
(
o
=>
o
.
Phone
)
.
ThenInclude
(
p
=>
p
.
Brand
)
.
Include
(
p
=>
p
.
Phone
.
Feedbacks
)
.
Include
(
o
=>
o
.
User
)
.
FirstOrDefault
(
o
=>
o
.
Id
==
id
);
...
...
@@ -37,10 +40,13 @@ namespace PhoneStore.Repositories
{
return
_db
.
Orders
.
Include
(
p
=>
p
.
Phone
)
.
ThenInclude
(
p
=>
p
.
Brand
)
.
Include
(
p
=>
p
.
Phone
.
Feedbacks
)
.
Include
(
p
=>
p
.
User
)
.
ToList
();
}
public
IEnumerable
<
Order
>
GetByUserId
(
int
id
)
=>
_db
.
Orders
.
Include
(
o
=>
o
.
User
)
...
...
PhoneStore/Services/FeedbackService.cs
View file @
f1085f19
using
System
;
using
System.Linq
;
using
System.Security.Claims
;
using
Microsoft.AspNetCore.Identity
;
using
PhoneStore.Mappers
;
using
PhoneStore.Models
;
using
PhoneStore.Repositories.Interfaces
;
using
PhoneStore.Services.Interfaces
;
using
PhoneStore.ViewModels
;
using
PhoneStore.ViewModels.Feedback
;
namespace
PhoneStore.Services
...
...
@@ -13,13 +15,15 @@ namespace PhoneStore.Services
{
private
readonly
UserManager
<
User
>
_userManager
;
private
readonly
IFeedbackRepository
_feedbackRepository
;
private
readonly
MobileContext
_db
;
public
FeedbackService
(
UserManager
<
User
>
userManager
,
IFeedbackRepository
feedbackRepository
)
IFeedbackRepository
feedbackRepository
,
MobileContext
db
)
{
_userManager
=
userManager
;
_feedbackRepository
=
feedbackRepository
;
_db
=
db
;
}
public
FeedbackViewModel
Create
(
FeedbackCreateViewModel
model
,
ClaimsPrincipal
user
)
...
...
@@ -59,5 +63,18 @@ namespace PhoneStore.Services
.
GetById
(
id
)
.
MapToFeedbackViewModel
();
}
public
PersonalAreaViewModel
GetPersonalViewModel
(
int
userId
)
{
PersonalAreaViewModel
model
=
new
PersonalAreaViewModel
{
Feedbacks
=
_feedbackRepository
.
GetByUserId
(
userId
)
.
Select
(
f
=>
f
.
MapToFeedbackViewModel
()),
User
=
_db
.
Users
.
FirstOrDefault
(
u
=>
u
.
Id
==
userId
).
MapToUserViewModel
()
};
return
model
;
}
}
}
\ No newline at end of file
PhoneStore/Services/Interfaces/IFeedbackService.cs
View file @
f1085f19
using
System.Collections.Generic
;
using
System.Security.Claims
;
using
PhoneStore.Models
;
using
PhoneStore.ViewModels
;
using
PhoneStore.ViewModels.Feedback
;
namespace
PhoneStore.Services.Interfaces
...
...
@@ -9,5 +11,7 @@ namespace PhoneStore.Services.Interfaces
FeedbackViewModel
Create
(
FeedbackCreateViewModel
model
,
ClaimsPrincipal
user
);
FeedbackViewModel
Update
(
FeedbackEditViewModel
model
);
FeedbackViewModel
GetById
(
int
id
);
PersonalAreaViewModel
GetPersonalViewModel
(
int
userId
);
}
}
\ No newline at end of file
PhoneStore/Services/Interfaces/IOrderService.cs
View file @
f1085f19
...
...
@@ -8,7 +8,6 @@ namespace PhoneStore.Services.Interfaces
{
IEnumerable
<
OrderViewModel
>
GetAll
();
void
Create
(
Order
order
);
OrderViewModel
GetById
(
int
id
);
IEnumerable
<
OrderViewModel
>
GetByUserId
(
int
id
);
}
}
\ No newline at end of file
PhoneStore/Startup.cs
View file @
f1085f19
...
...
@@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore;
using
Microsoft.Extensions.Configuration
;
using
Microsoft.Extensions.DependencyInjection
;
using
Microsoft.Extensions.Hosting
;
using
Newtonsoft.Json
;
using
PhoneStore.Helpers
;
using
PhoneStore.Models
;
...
...
@@ -24,10 +25,9 @@ namespace PhoneStore
services
.
AddDbContext
<
MobileContext
>(
options
=>
options
.
UseNpgsql
(
connection
))
.
AddIdentity
<
User
,
Role
>()
.
AddEntityFrameworkStores
<
MobileContext
>();
services
.
AddControllersWithViews
()
;
//Можно так подключать сервисы
services
.
AddControllersWithViews
()
.
AddNewtonsoftJson
(
o
=>
o
.
SerializerSettings
.
ReferenceLoopHandling
=
ReferenceLoopHandling
.
Ignore
);
services
.
AddApplicationServices
(
Configuration
);
//А можно так
RepositoryConnector
.
AddRepositories
(
services
);
services
.
AddValidationServices
();
services
.
AddCors
();
...
...
PhoneStore/ViewModels/PersonalAreaViewModel.cs
0 → 100644
View file @
f1085f19
using
System.Collections.Generic
;
using
PhoneStore.ViewModels.Account
;
using
PhoneStore.ViewModels.Feedback
;
namespace
PhoneStore.ViewModels
{
public
class
PersonalAreaViewModel
{
public
UserViewModel
User
{
get
;
set
;
}
public
IEnumerable
<
FeedbackViewModel
>
Feedbacks
{
get
;
set
;
}
}
}
\ No newline at end of file
PhoneStore/Views/PersonalArea/Index.cshtml
0 → 100644
View file @
f1085f19
@model PhoneStore.ViewModels.PersonalAreaViewModel
@{
ViewBag.Title = "title";
Layout = "_Layout";
}
<h2 userId="@Model.User.Id">Профиль пользователя @Model.User.Name</h2>
<div class="tabs">
<div class="tab-items row w-50 m-auto">
<a href="#tab-feedbacks" class="active tab-pane col-md-6">Отзывы</a>
<a href="#tab-orders" class="tab-pane col-md-6">Заказы</a>
</div>
<div class="tab-contents">
<div id="tab-feedbacks" class="tab-content">
@foreach (var feedback in Model.Feedbacks)
{
await Html.RenderPartialAsync("PartialViews/FeedbackPartialView", feedback);
}
</div>
<div id="tab-orders" class="tab-content">
<table style="width: 100%">
<thead>
<tr>
<th>Id</th>
<th>Адрес</th>
<th>Контактный телефон</th>
<th>Имя пользователя</th>
<th>Название телефона</th>
</tr>
</thead>
<tbody id="orders">
</tbody>
</table>
</div>
</div>
</div>
@section Scripts
{
<script>
$('.tab-pane').click((e) => {
e.preventDefault;
let userId = $('h2').attr('userId');
fetch('https://localhost:5001/Orders/GetAllByUserId/' + userId)
.then((response) => {
return response.json();
})
.then((orders) => {
if (orders.length === 0){
$(this).html("<h3>Заказов нет</h3>");
console.log("orders - 0")
}
else {
let content;
$.each(orders, (order) => {
content += `<tr>
<td>order.id</td>
<td>order.address</td>
<td>order.contact.Phone</td>
<td>order.user.Name</td>
<td>order.phone.Name</td>
</tr>`
});
console.log("content " + content);
$('#orders').html(content);
}
});
});
let makeTabs = () => {
let tabs = $('.tabs').find('.tab-items a');
console.log(tabs);
$.each(tabs, (index, item) => {
if ($(item).hasClass('active')){
console.log(item)
let activeTabContent = $(this).attr('href');
$(this).parents(".tabs").find(activeTabContent).show();
}
});
$(tabs).click((e) => {
console.log("click tab");
e.preventDefault();
if (!$(this).hasClass("active")){
let tabContent = $(this).attr('href');
$(this).siblings('.tab-items').removeClass('active');
$(this).addClass('active');
$(this).closest('.tabs').find('.tab-content').hide();
$(this).closest('.tabs').find(tabContent).show();
}
})
}
makeTabs();
</script>
}
PhoneStore/Views/Shared/_Layout.cshtml
View file @
f1085f19
<!DOCTYPE html>
@using Microsoft.AspNetCore.Identity
@inject UserManager
<User>
UserManager
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"utf-8"
/>
...
...
@@ -35,7 +37,7 @@
<div
class=
"login_group"
>
@if(User.Identity.IsAuthenticated)
{
<
p>
@User.Identity.Name
</p
>
<
a
asp-action=
"Index"
asp-controller=
"PersonalArea"
asp-route-userId=
"@UserManager.GetUserId(User)"
>
@User.Identity.Name
</a
>
<form
method=
"post"
asp-controller=
"Account"
asp-action=
"LogOff"
>
<button
class=
"btn btn-outline-warning"
type=
"submit"
>
Выход
</button>
...
...
PhoneStore/appsettings.json
View file @
f1085f19
{
"ConnectionStrings"
:
{
"DefaultConnection"
:
"Server=localhost;Port=54320;database=lesson6
3
;Username=postgres;Password=postgres;"
"DefaultConnection"
:
"Server=localhost;Port=54320;database=lesson6
8
;Username=postgres;Password=postgres;"
},
"Logging"
:
{
"LogLevel"
:
{
...
...
PhoneStore/wwwroot/css/site.css
View file @
f1085f19
...
...
@@ -77,3 +77,36 @@ body {
.w_15
{
width
:
15%
;
}
.tabs
{
padding
:
40px
;
}
.tab-items
{
margin-bottom
:
-1px
;
position
:
relative
;
z-index
:
10
;
}
.tab-items
a
{
display
:
inline-block
;
padding
:
1px
25px
;
border
:
1px
solid
gold
;
border-bottom
:
none
;
background
:
#c69500
;
color
:
black
;
text-decoration
:
none
;
}
.tab-items
a
.active
{
color
:
#9fcdff
;
background
:
#fff
;
}
.tabs
.tab-content
{
padding
:
20px
;
border
:
1px
solid
silver
;
/*display: none;*/
position
:
relative
;
z-index
:
9
;
}
\ 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