Commit 8fdac13f authored by Пасько Виталий's avatar Пасько Виталий

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	PhoneStore/Controllers/OrdersController.cs
#	PhoneStore/Controllers/PersonalAreaController.cs
#	PhoneStore/Startup.cs
#	PhoneStore/Views/PersonalArea/Index.cshtml
#	PhoneStore/Views/Shared/_Layout.cshtml
#	PhoneStore/wwwroot/css/site.css
parents f1085f19 c822f9f1
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
...@@ -53,9 +54,10 @@ namespace PhoneStore.Controllers ...@@ -53,9 +54,10 @@ namespace PhoneStore.Controllers
return RedirectToAction("Index"); return RedirectToAction("Index");
} }
[HttpGet]
public IActionResult GetAllByUserId(int id) public IActionResult GetAllByUserId(int id)
{ {
var model = _orderService.GetByUserId(id); var model = _orderService.GetByUserId(id).ToArray();
return Json(model); return Json(model);
} }
} }
......
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using PhoneStore.Services.Interfaces; using PhoneStore.Services.Interfaces;
namespace PhoneStore.Controllers namespace PhoneStore.Controllers
......
...@@ -19,7 +19,7 @@ namespace PhoneStore.Mappers ...@@ -19,7 +19,7 @@ namespace PhoneStore.Mappers
}; };
} }
public static Order MapToOrderViewModel(this OrderViewModel self) public static Order MapToOrder(this OrderViewModel self)
{ {
return new Order return new Order
{ {
...@@ -27,7 +27,6 @@ namespace PhoneStore.Mappers ...@@ -27,7 +27,6 @@ namespace PhoneStore.Mappers
Phone = self.Phone?.MapToPhone(), Phone = self.Phone?.MapToPhone(),
ContactPhone = self.ContactPhone, ContactPhone = self.ContactPhone,
PhoneId = self.PhoneId, PhoneId = self.PhoneId,
User = self.User?.MapToUser(),
UserId = self.UserId, UserId = self.UserId,
Id = self.Id Id = self.Id
}; };
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.17" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.17" />
<PackageReference Include="FluentValidation" Version="11.2.0" /> <PackageReference Include="FluentValidation" Version="11.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.17" /> <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.17" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.17" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.17"> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.17">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
......
...@@ -31,6 +31,7 @@ namespace PhoneStore.Repositories ...@@ -31,6 +31,7 @@ namespace PhoneStore.Repositories
var a =_db.Phones var a =_db.Phones
.Include(p => p.Brand) .Include(p => p.Brand)
.Include(p => p.Feedbacks) .Include(p => p.Feedbacks)
.ThenInclude(f => f.User)
.FirstOrDefault(p => p.Id == id); .FirstOrDefault(p => p.Id == id);
return a; return a;
} }
......
namespace PhoneStore.Services.Interfaces
{
public interface IPersonalAreaServic
{
}
}
\ No newline at end of file
...@@ -21,7 +21,9 @@ namespace PhoneStore.Services ...@@ -21,7 +21,9 @@ namespace PhoneStore.Services
=> _orderRepository.GetAll().Select(o => o.MapToOrderViewModel()); => _orderRepository.GetAll().Select(o => o.MapToOrderViewModel());
public void Create(Order order) public void Create(Order order)
=> _orderRepository.Create(order); {
_orderRepository.Create(order);
}
public OrderViewModel GetById(int id) public OrderViewModel GetById(int id)
=> _orderRepository.GetById(id).MapToOrderViewModel(); => _orderRepository.GetById(id).MapToOrderViewModel();
......
...@@ -21,13 +21,7 @@ else ...@@ -21,13 +21,7 @@ else
</tr> </tr>
@foreach (var order in Model) @foreach (var order in Model)
{ {
<tr> await Html.RenderPartialAsync("PartialViews/OrderPartialView", order);
<td>@order.Id</td>
<td>@order.Address</td>
<td>@order.ContactPhone</td>
<td>@order.User.Name</td>
<td>@order.Phone.Name</td>
</tr>
} }
</table> </table>
} }
@model PhoneStore.ViewModels.PersonalAreaViewModel @model PersonalAreaViewModel
@{ @{
ViewBag.Title = "title"; ViewBag.Title = "title";
Layout = "_Layout"; Layout = "_Layout";
} }
<h2 userId="@Model.User.Id">Профиль пользователя @Model.User.Name</h2> <h2 userId="@Model.User.Id" >Кабинет @Model.User.Username</h2>
<div class="tabs"> <div class="tabs">
<div class="tab-items row w-50 m-auto"> <div class="tab-items row w-50 m-auto">
<a href="#tab-feedbacks" class="active tab-pane col-md-6">Отзывы</a> <a href="#tab-feedbaks" class="active tab-pane col-md-6">Все отзывы @Model.User.Username</a>
<a href="#tab-orders" class="tab-pane col-md-6">Заказы</a> <a href="#tab-orders" class="tab-pane col-md-6">Все заказы @Model.User.Username</a>
</div> </div>
<div class="tab-contents"> <div class="tab-contents">
<div id="tab-feedbacks" class="tab-content"> <div id="tab-feedbaks" class="tab-content">
@foreach (var feedback in Model.Feedbacks) @foreach (var feedback in Model.Feedbacks)
{ {
await Html.RenderPartialAsync("PartialViews/FeedbackPartialView", feedback); await Html.RenderPartialAsync("PartialViews/FeedbackPartialView", feedback);
...@@ -21,16 +22,15 @@ ...@@ -21,16 +22,15 @@
<div id="tab-orders" class="tab-content"> <div id="tab-orders" class="tab-content">
<table style="width: 100%"> <table style="width: 100%">
<thead> <thead>
<tr> <tr>
<th>Id</th> <th>Id</th>
<th>Адрес</th> <th>Адрес</th>
<th>Контактный телефон</th> <th>Контактный телефон</th>
<th>Имя пользователя</th> <th>Имя пользователя</th>
<th>Название телефона</th> <th>Название телефона</th>
</tr> </tr>
</thead> </thead>
<tbody id="orders"> <tbody id="orders">
</tbody> </tbody>
</table> </table>
</div> </div>
...@@ -39,59 +39,55 @@ ...@@ -39,59 +39,55 @@
@section Scripts @section Scripts
{ {
<script> <script >
$('.tab-pane').click((e) => {
e.preventDefault; $('.tab-pane').click(function (e){
e.preventDefault();
let userId = $('h2').attr('userId'); let userId = $('h2').attr('userId');
fetch('https://localhost:5001/Orders/GetAllByUserId/' + userId) fetch("https://localhost:5001/Orders/GetAllByUserId/" + userId)
.then((response) => { .then((response) => {
return response.json(); return response.json();
}) })
.then((orders) => { .then((orders) => {
if (orders.length === 0){ if (orders.length === 0){
$(this).html("<h3>Заказов нет</h3>"); $(this).html('<h3>Заказов нет</h3>');
console.log("orders - 0") }
} else{
else { let content;
let content; $.each(orders, (order) => {
$.each(orders, (order) => { content += `<tr>
content += `<tr> <td>order.id</td>
<td>order.id</td> <td>order.address</td>
<td>order.address</td> <td>order.contactPhone</td>
<td>order.contact.Phone</td> <td>order.user.Name</td>
<td>order.user.Name</td> <td>order.phone.Name</td>
<td>order.phone.Name</td> </tr>`
</tr>`
}); });
console.log("content " + content); $('#orders').html(content);
}
$('#orders').html(content); });
}
});
}); });
let makeTabs = () => {
let tabs = $('.tabs').find('.tab-items a'); let makeTabs = function (){
console.log(tabs); let tabs = $(".tabs").find(".tab-items a");
$.each(tabs, (index, item) => { $.each(tabs, function (index, item){
if ($(item).hasClass('active')){ if ($(item).hasClass('active')){
console.log(item)
let activeTabContent = $(this).attr('href'); let activeTabContent = $(this).attr('href');
$(this).parents(".tabs").find(activeTabContent).show(); $(this).parents('.tabs').find(activeTabContent).show();
} }
}); });
$(tabs).click((e) => { $(tabs).click(function (e){
console.log("click tab");
e.preventDefault(); e.preventDefault();
if (!$(this).hasClass("active")){ if (!$(this).hasClass('active')){
let tabContent = $(this).attr('href'); let tabContent = $(this).attr('href');
$(this).siblings('.tab-items').removeClass('active'); $(this).siblings('.tab-items a').removeClass('active');
$(this).addClass('active'); $(this).addClass('active');
$(this).closest('.tabs').find('.tab-content').hide(); $(this).closest('.tabs').find('.tab-content').hide();
$(this).closest('.tabs').find(tabContent).show(); $(this).closest('.tabs').find(tabContent).show();
} }
}) });
} };
makeTabs(); makeTabs();
</script> </script>
} }
@using PhoneStore.Repositories.Interfaces
@using Microsoft.AspNetCore.Identity
@model PhoneStore.ViewModels.PhoneViewModels.PhoneViewModel @model PhoneStore.ViewModels.PhoneViewModels.PhoneViewModel
@inject IFeedbackRepository _feedbackRepository;
@inject UserManager<User> _userManager;
@{ @{
ViewBag.Title = "Подробная информация"; ViewBag.Title = "Подробная информация";
Layout = "_Layout"; Layout = "_Layout";
...@@ -14,16 +18,19 @@ ...@@ -14,16 +18,19 @@
</div> </div>
@if (User.Identity.IsAuthenticated) @if (User.Identity.IsAuthenticated)
{ {
<form class="mb-3" id="feedbackForm"> if (!_feedbackRepository.CheckFeedbackExists(int.Parse(_userManager.GetUserId(User)), Model.Id))
<div class="form-group"> {
<label for="text">Добавьте отзыв о телефоне</label> <form class="mb-3" id="feedbackForm">
<input type="text" class="form-control" id="text" placeholder="Минимальная длина отзыва 10 символов"> <div class="form-group">
<input type="text" hidden name="phoneId" id="@Model.Id"> <label for="text">Добавьте отзыв о телефоне</label>
<button class="my-3 btn btn-outline-warning" type="submit">Отправить</button> <input type="text" class="form-control" id="text" placeholder="Минимальная длина отзыва 10 символов">
</div> <input type="text" hidden name="phoneId" id="@Model.Id">
</form> <button class="my-3 btn btn-outline-warning" type="submit">Отправить</button>
</div>
</form>
}
} }
else else if(!User.Identity.IsAuthenticated)
{ {
<a asp-action="Login" asp-controller="Account">Авторизируйтесь для добавления отзыва</a> <a asp-action="Login" asp-controller="Account">Авторизируйтесь для добавления отзыва</a>
} }
......
@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Identity
@model PhoneStore.ViewModels.Feedback.FeedbackViewModel @model PhoneStore.ViewModels.Feedback.FeedbackViewModel
@inject UserManager<User> _userManager; @inject UserManager<User> UserManager;
<div id="@Model.Id" class="card mb-3"> <div id="@Model.Id" class="card mb-3">
<h5 class="card-header"> <h5 class="card-header">
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
<div class="card-text">@Model.Text</div> <div class="card-text">@Model.Text</div>
@if (User.Identity.IsAuthenticated) @if (User.Identity.IsAuthenticated)
{ {
if (int.Parse(_userManager.GetUserId(User)) == Model.UserId) if (int.Parse(UserManager.GetUserId(User)) == Model.UserId)
{ {
<button type="button" <button type="button"
class="btn btn-outline-warning" class="btn btn-outline-warning"
...@@ -27,6 +27,5 @@ ...@@ -27,6 +27,5 @@
</button> </button>
} }
} }
</div> </div>
</div> </div>
\ No newline at end of file
@model OrderViewModel
<tr>
<td>@Model.Id</td>
<td>@Model.Address</td>
<td>@Model.ContactPhone</td>
<td>@Model.User.Name</td>
<td>@Model.Phone.Name</td>
</tr>
\ No newline at end of file
@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Identity
@inject UserManager<User> UserManager @inject UserManager<User> _userManager
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
...@@ -37,7 +37,10 @@ ...@@ -37,7 +37,10 @@
<div class="login_group"> <div class="login_group">
@if(User.Identity.IsAuthenticated) @if(User.Identity.IsAuthenticated)
{ {
<a asp-action="Index" asp-controller="PersonalArea" asp-route-userId="@UserManager.GetUserId(User)">@User.Identity.Name</a> <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"> <form method="post" asp-controller="Account" asp-action="LogOff">
<button class="btn btn-outline-warning" type="submit">Выход</button> <button class="btn btn-outline-warning" type="submit">Выход</button>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment