シナリオ : ビューには、すべての利益の合計、すべてのコストの合計、および残高 = 利益 - コストが含まれている必要があります
public ProfitAndCostViewModel getTotalBalance()
{
var totalProfit = db.Profits.Where(p=>p.IdUser.UserId == WebSecurity.CurrentUserId).Sum(p=>p.Value);
var totalCost = db.Costs.Where(c=>c.IdUser.UserId == WebSecurity.CurrentUserId).Sum(c=>c.Value);
var balance = totalProfit - totalCost ;
return new ProfitAndCostViewModel { FinalBalance = balance };
}
コントローラ:
public ActionResult Index()
{
var pcv = new ProfitAndCostViewModel();
pcv.ProfModel =getProfitSum();
pcv.CostModel =getCostSum();
pcv.TOTALBALANCE = getTotalBalance();
return View(pcv);
}
意見:
@model WHFM.ViewModels.ProfitAndCostViewModel
@Model.FinalBalance.FinalBalance