Рефакторинг.

parent 328ca1aa
......@@ -23,8 +23,7 @@ namespace PhoneStore.Controllers
public ActionResult<FeedbackViewModel> Create(FeedbackCreateViewModel model)
{
//TODO: валидация.
var userId = int.Parse(_userManager.GetUserId(User));
var feedbackViewModel = _feedbackService.Create(model, userId);
var feedbackViewModel = _feedbackService.Create(model, User);
return Json(feedbackViewModel);
}
......
using System;
using System.Linq;
using System.Security.Claims;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using PhoneStore.Helpers;
......@@ -22,14 +23,14 @@ namespace PhoneStore.Services
_userManager = userManager;
}
public FeedbackViewModel Create(FeedbackCreateViewModel model, int userId)
public FeedbackViewModel Create(FeedbackCreateViewModel model, ClaimsPrincipal user)
{
Feedback feedback = new Feedback
{
CreationDateTime = DateTime.Now,
Text = model.Text,
PhoneId = model.PhoneId,
UserId = userId
UserId = int.Parse(_userManager.GetUserId(user))
};
_db.Feedbacks.Add(feedback);
_db.SaveChanges();
......
using System.Security.Claims;
using PhoneStore.ViewModels.Feedback;
namespace PhoneStore.Services.Interfaces
{
public interface IFeedbackService
{
FeedbackViewModel Create(FeedbackCreateViewModel model, int userId);
FeedbackViewModel Create(FeedbackCreateViewModel model, ClaimsPrincipal user);
}
}
\ 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