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);
...@@ -30,7 +31,6 @@ ...@@ -30,7 +31,6 @@
</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.contact.Phone</td> <td>order.contactPhone</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";
...@@ -13,6 +17,8 @@ ...@@ -13,6 +17,8 @@
<p class="card-text">@(Model.Price.ToString("C2"))</p> <p class="card-text">@(Model.Price.ToString("C2"))</p>
</div> </div>
@if (User.Identity.IsAuthenticated) @if (User.Identity.IsAuthenticated)
{
if (!_feedbackRepository.CheckFeedbackExists(int.Parse(_userManager.GetUserId(User)), Model.Id))
{ {
<form class="mb-3" id="feedbackForm"> <form class="mb-3" id="feedbackForm">
<div class="form-group"> <div class="form-group">
...@@ -23,7 +29,8 @@ ...@@ -23,7 +29,8 @@
</div> </div>
</form> </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