-пофиксил добавление отзыва.

-добавил вывод информации о количестве зарегистрированных пользователях и количестве отзывов.
parent ca2ccbeb
using Microsoft.AspNetCore.Identity; using System.Linq;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using PhoneStore.Models; using PhoneStore.Models;
using PhoneStore.Services.Interfaces; using PhoneStore.Services.Interfaces;
using PhoneStore.ViewModels;
using PhoneStore.ViewModels.Feedback; using PhoneStore.ViewModels.Feedback;
namespace PhoneStore.Controllers namespace PhoneStore.Controllers
{ {
public class FeedbackController : Controller public class FeedbackController : Controller
{ {
private readonly UserManager<User> _userManager;
private readonly IFeedbackService _feedbackService; private readonly IFeedbackService _feedbackService;
private readonly MobileContext _db;
public FeedbackController( public FeedbackController(IFeedbackService feedbackService, MobileContext db)
UserManager<User> userManager,
IFeedbackService feedbackService)
{ {
_userManager = userManager;
_feedbackService = feedbackService; _feedbackService = feedbackService;
_db = db;
} }
[HttpGet] [HttpPost]
public ActionResult<FeedbackViewModel> Create(FeedbackCreateViewModel model) public IActionResult Create(FeedbackCreateViewModel model)
{ {
//TODO: валидация. //TODO: валидация.
var feedbackViewModel = _feedbackService.Create(model, User); var feedbackViewModel = _feedbackService.Create(model, User);
return PartialView("PartialViews/FeedbackPartialView", feedbackViewModel);
}
return Json(feedbackViewModel); [HttpGet]
public ActionResult<FeedbackViewModel> GetCount()
{
var usersCount = _db.Users.Count();
var feedbacksCount = _db.Feedbacks.Count();
var model = new AccountingViewModel
{
User = new UserAccountingViewModel(nameof(User), usersCount),
Feedback = new FeedbackAccountingViewModel(nameof(Feedback), feedbacksCount)
};
return Json(model);
} }
} }
} }
\ No newline at end of file
...@@ -13,6 +13,8 @@ namespace PhoneStore.Helpers ...@@ -13,6 +13,8 @@ namespace PhoneStore.Helpers
Text = self.Text, Text = self.Text,
PhoneId = self.PhoneId, PhoneId = self.PhoneId,
UserId = self.UserId, UserId = self.UserId,
User = self.User.MapToUserViewModel(),
Phone = self.Phone.MapToPhoneViewModel(),
CreationDateTime = self.CreationDateTime CreationDateTime = self.CreationDateTime
}; };
return feedbackViewModel; return feedbackViewModel;
......
namespace PhoneStore.ViewModels
{
public class AccountingViewModel
{
public UserAccountingViewModel User { get; set; }
public FeedbackAccountingViewModel Feedback { get; set; }
}
public class AccountingBase
{
public string EntityName { get; set; }
public int Count { get; set; }
public AccountingBase(string entityName, int count)
{
EntityName = entityName;
Count = count;
}
}
public class UserAccountingViewModel : AccountingBase
{
public UserAccountingViewModel(string entityName, int count) : base(entityName, count)
{
}
}
public class FeedbackAccountingViewModel : AccountingBase
{
public FeedbackAccountingViewModel(string entityName, int count) : base(entityName, count)
{
}
}
}
\ No newline at end of file
using System; using System;
using PhoneStore.ViewModels.Account; using PhoneStore.ViewModels.Account;
using PhoneStore.ViewModels.Account;
using PhoneStore.ViewModels.PhoneViewModels; using PhoneStore.ViewModels.PhoneViewModels;
namespace PhoneStore.ViewModels.Feedback namespace PhoneStore.ViewModels.Feedback
......
...@@ -53,6 +53,16 @@ ...@@ -53,6 +53,16 @@
<div class="container"> <div class="container">
<main role="main" class="pb-3"> <main role="main" class="pb-3">
<div id="results"></div> <div id="results"></div>
<button id="getData" class="btn btn-outline-warning">Получить данные</button>
<div id="widget">
<div class="alert alert-warning alert-dismissible fade show" role="alert">
<strong id="user"></strong> = <span id="usersCount"></span><br>
<strong id="feedback"></strong> = <span id="feedbacksCount"></span><br>
<button id="widgetClose" type="button" class="close" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
</div>
@RenderBody() @RenderBody()
</main> </main>
</div> </div>
......
$(document).ready(function (){ $(document).ready(function (){
$('#widget').hide();
$('#search').on('keyup', function (e){ $('#search').on('keyup', function (e){
e.preventDefault(); e.preventDefault();
let searchTerm = $(this).val(); let searchTerm = $(this).val();
...@@ -11,7 +12,27 @@ ...@@ -11,7 +12,27 @@
}); });
$(document).ready(function (){ $(document).ready(function (){
$("#feedbackForm").on("submit", function (e){ $('#getData').on('click', function (){
$('#widget').show();
$.ajax({
url: 'https://localhost:5001/feedback/getCount',
type: 'GET',
success: function (response) {
$('#user').text(response.user.entityName);
$('#usersCount').text(response.user.count);
$('#feedback').text(response.feedback.entityName);
$('#feedbacksCount').text(response.feedback.count);
}
});
});
$('#widgetClose').on('click', function (){
$('#widget').hide();
})
});
$(document).ready(function () {
$("#feedbackForm").on("submit", function (e) {
e.preventDefault(); e.preventDefault();
let phoneId = $("input[name=phoneId]"); let phoneId = $("input[name=phoneId]");
let text = $("#text"); let text = $("#text");
...@@ -19,8 +40,12 @@ $(document).ready(function (){ ...@@ -19,8 +40,12 @@ $(document).ready(function (){
text: text.val(), text: text.val(),
phoneId: phoneId.attr('id') phoneId: phoneId.attr('id')
}; };
$.post('https://localhost:5001/feedback/create', feedback, function (response){ $.post('https://localhost:5001/Feedback/Create', feedback, function (response) {
$('#feedbacks').before(response); }).done(function (response) {
$('#feedbacks').prepend(response);
text.text("");
return true;
}); });
}); });
}); });
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