diff --git a/MoneyNote/Controllers/AccountController.cs b/MoneyNote/Controllers/AccountController.cs index aec4f09..bc7e7fc 100644 --- a/MoneyNote/Controllers/AccountController.cs +++ b/MoneyNote/Controllers/AccountController.cs @@ -12,16 +12,15 @@ public class AccountController : Controller // GET: 回傳帳簿資料 public ActionResult Index() { - FakeAccountData AccountBooks = new FakeAccountData(); - - return View(AccountBooks.GetFakeAccountData()); + + return View(); } [ChildActionOnly] public ActionResult AccountItems() { - FakeAccountData AccountBooks = new FakeAccountData(); + FakeAccountData accountBooks = new FakeAccountData(); - return View(AccountBooks.GetFakeAccountData()); + return View(accountBooks.GetFakeAccountData()); } } } \ No newline at end of file diff --git a/MoneyNote/Models/FakeAccountData.cs b/MoneyNote/Models/FakeAccountData.cs index 6faf275..1598700 100644 --- a/MoneyNote/Models/FakeAccountData.cs +++ b/MoneyNote/Models/FakeAccountData.cs @@ -9,29 +9,24 @@ namespace MoneyNote.Models public class FakeAccountData { /// - /// 記憶體暫存記帳本 + /// Gets the fake account data. /// - private static List MyAccountBooks; - - public List GetFakeAccountData() + /// + public IEnumerable GetFakeAccountData() { - MyAccountBooks = new List(); - //收入的sample資料 - for (int i = 1; i < 51; i++) + for (var i = 1; i < 51; i++) { - if (i <= 25) - - MyAccountBooks.Add(new AccountViewModel { Id = i, Category = "收入", Amoount = i * 1000, UpdateDate = DateTime.Now.AddDays(i), Remarks = "收入" + i }); - else - MyAccountBooks.Add(new AccountViewModel { Id = i, Category = "支出", Amoount = i * 500, UpdateDate = DateTime.Now.AddDays(i), Remarks = "支出" + i }); - + var type = i < 25 ? "收入" : "支出"; + yield return new AccountViewModel + { + Id = i, + Category = type, + Amoount = i * i < 25 ? 1000 : 500, + UpdateDate = DateTime.Now.AddDays(i), + Remarks = type + i + }; } - - - return MyAccountBooks; - } - } } \ No newline at end of file