【发布时间】:2020-03-19 18:25:58
【问题描述】:
在 ASP.NET CORE 中,我的 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}
}
在controller的Create方法中
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 而不是controller 的Create 方法中?还是我应该把它留在controller 中?
【问题讨论】:
标签: c# asp.net asp.net-core model-view-controller