From 0da036a9ce04ddb0601251b9f753e853a9a9eb46 Mon Sep 17 00:00:00 2001 From: demofan Date: Fri, 13 Jul 2018 15:59:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=98=97=E8=A9=A6=E8=AA=BF=E6=95=B4=E5=AF=AB?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MoneyNote/Controllers/AccountController.cs | 9 +++---- MoneyNote/Models/FakeAccountData.cs | 31 +++++++++------------- 2 files changed, 17 insertions(+), 23 deletions(-) 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