Which option is more correct for MVC – Creating an entity in the controller or Creating an entity in the service
Option #1
Controller:
[HttpPost]
public IActionResult SuccessfullyCreatedPromocode(string promocodeName, decimal discount)
{
Promocode promocode = new Promocode(promocodeName, discount);
promocodeService.CreatePromocode(promocode);
return View();
}
Service:
public void CreatePromocode(Promocode promocode)
{
context.Promocode.Add(promocode);
context.SaveChanges();
}
or Option #2
Controller:
[HttpPost]
public IActionResult SuccessfullyCreatedPromocode(string promocodeName, decimal discount)
{
promocodeService.CreatePromocode(promocodeName, discount);
return View();
}
Service:
public void CreatePromocode(string promocodeName, decimal discount)
{
Promocode promocode = new Promocode(promocodeName, discount)
context.Promocode.Add(promocode);
context.SaveChanges();
}