В ASP. NET CORE У меня есть логика c и расчеты в моем controller
, но я знаю, что тощий controllers
и толстый models
- это типичный подход. Вот моя модель
public class Yearly
{
public int Id {get;set;}
public decimal Q1Rev {get;set;}
public decimal Q2Rev {get;set;}
public decimal Q3Rev {get;set;}
public decimal Q4Rev {get;set;}
public decimal Q1Cost {get;set;}
public decimal Q2Cost {get;set;}
public decimal Q3Cost {get;set;}
public decimal Q4Cost {get;set;}
public decimal Q1Profit {get;set;}
public decimal Q2Profit {get;set;}
public decimal Mean {get;set}
}
В методе Create
controller
Yearly yearly = new Yearly
{
Q1Rev = yearly.Q1Rev,
Q2Rev = yearly.Q2Rev,
Q3Rev = yearly.Q3Rev,
Q4Rev = yearly.Q4Rev,
Q1Cost = yearly.Q1Cost,
Q2Cost = yearly.Q2Cost,
Q3Cost = yearly.Q3Cost,
Q4Cost = yearly.Q4Cost,
Q1Profit = yearly.Q1Rev - Q1Cost,
Q2Profit = yearly.Q2Rev - yearly.Q2Cost,
Mean = (yearly.Q1Profit + yearly.Q2Profit) / 2
};
Как можно добавлять вычисления в model
, а не в метод Create
из controller
? Или я должен оставить это в controller
?