I use the MVC application only to learn technology. I make fun of the registration register application, which tracks the current account, what cleared the bank and what not. I am using EF for my model and everything seems to work correctly since Edit, Create, etc. However, I have a couple of totals at the top. One to show the balance of the bank, and the other to show the actual balance. It works most of the time, but when I do Edit, it does not always accurately reflect the new value, and I need to update it every time a change occurs (for example, when something clears the bank):
[Authorize(Roles = "admin, checkUser")]
public ActionResult Index()
{
var resultSet = from myChecking in chk.tblCheckings
orderby myChecking.id descending
select myChecking;
ViewData.Model = resultSet.Take(45).ToList();
var actualBalance = from theChecking in chk.tblCheckings
select theChecking.deposit - theChecking.withdrawal;
var bankBalance = from theChecking in chk.tblCheckings
where theChecking.cleared == true
select theChecking.deposit - theChecking.withdrawal;
ViewData["bankBalance"] = bankBalance.Sum();
ViewData["actualBalance"] = actualBalance.Sum();
return View();
}
I show the actual and other balance as an index as follows:
<td colspan="9" style="text-align: center; font-size: 11pt; color: white;">
<%= string.Format("Bank Balance: {0:c}", ViewData["bankBalance"]) %> ------
<%= string.Format("Actual Balance: {0:c}", ViewData["actualBalance"]) %>
</td>
source
share