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

-добавил вывод информации о количестве зарегистрированных пользователях и количестве отзывов.
parent ca2ccbeb
using Microsoft.AspNetCore.Identity;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using PhoneStore.Models;
using PhoneStore.Services.Interfaces;
using PhoneStore.ViewModels;
using PhoneStore.ViewModels.Feedback;
namespace PhoneStore.Controllers
{
public class FeedbackController : Controller
{
private readonly UserManager<User> _userManager;
private readonly IFeedbackService _feedbackService;
private readonly MobileContext _db;
public FeedbackController(
UserManager<User> userManager,
IFeedbackService feedbackService)
public FeedbackController(IFeedbackService feedbackService, MobileContext db)
{
_userManager = userManager;
_feedbackService = feedbackService;
_db = db;
}
[HttpGet]
public ActionResult<FeedbackViewModel> Create(FeedbackCreateViewModel model)
[HttpPost]
public IActionResult Create(FeedbackCreateViewModel model)
{
//TODO: валидация.
var feedbackViewModel = _feedbackService.Create(model, User);
return Json(feedbackViewModel);
return PartialView("PartialViews/FeedbackPartialView", 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
Text = self.Text,
PhoneId = self.PhoneId,
UserId = self.UserId,
User = self.User.MapToUserViewModel(),
Phone = self.Phone.MapToPhoneViewModel(),
CreationDateTime = self.CreationDateTime
};
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 PhoneStore.ViewModels.Account;
using PhoneStore.ViewModels.Account;
using PhoneStore.ViewModels.PhoneViewModels;
namespace PhoneStore.ViewModels.Feedback
......
......@@ -36,4 +36,4 @@
{
await Html.RenderPartialAsync("PartialViews/FeedbackPartialView", feedBack);
}
</div>
</div>
\ No newline at end of file
......@@ -53,6 +53,16 @@
<div class="container">
<main role="main" class="pb-3">
<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()
</main>
</div>
......
$(document).ready(function (){
$('#widget').hide();
$('#search').on('keyup', function (e){
e.preventDefault();
let searchTerm = $(this).val();
......@@ -11,7 +12,27 @@
});
$(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();
let phoneId = $("input[name=phoneId]");
let text = $("#text");
......@@ -19,8 +40,12 @@ $(document).ready(function (){
text: text.val(),
phoneId: phoneId.attr('id')
};
$.post('https://localhost:5001/feedback/create', feedback, function (response){
$('#feedbacks').before(response);
$.post('https://localhost:5001/Feedback/Create', feedback, function (response) {
}).done(function (response) {
$('#feedbacks').prepend(response);
text.text("");
return true;
});
});
});
\ No newline at end of file
});
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