我怀疑应该在哪里完成权限。例如,我有一个 PersonController,它有两个方法,一个 HttpGet create 和一个 HttpPost create,我正在使用一个与存储库层通信的服务层。现在,最好的方法是什么?
1:
[HttpPost]
public ActionResult Create(Person person)
{
if (ModelState.IsValid)
{
new PersonService().Save(person, (int)Session["UserId"]);//I check here permission here
return RedirectToAction("Home","Home");
}
return View();
}
2:
[HttpPost]
public ActionResult Create(Person person)
{
if (ModelState.IsValid)
{
var personService = new PersonService();
if(personService.UserHasPermission((int)Session["UserId"]){
personService.Save(id);
}
return RedirectToAction("Home","Home");
}
return View();
}
换句话说,我应该在业务层还是在控制器中做呢?