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

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