Beispiel #1
0
        public static AccountBook ConvertToAccountBookModel(MoneyBookViewModels moneyBookViewModels)
        {
            var accountBook = new AccountBook
            {
                Id         = Guid.NewGuid(),
                Dateee     = moneyBookViewModels.Date,
                Categoryyy = moneyBookViewModels.Category.Equals(CategoryEnum.收入) ? 1 : 0,
                Amounttt   = moneyBookViewModels.Money,
                Remarkkk   = moneyBookViewModels.Description
            };

            return(accountBook);
        }
Beispiel #2
0
        public IEnumerable <MoneyBookViewModels> LookupMoney()
        {
            var source = _accountBookRepository.LookupAll();
            var result = new List <MoneyBookViewModels>();

            foreach (var item in source)
            {
                var moneyItem = new MoneyBookViewModels
                {
                    Date     = item.Dateee,
                    Category = (item.Categoryyy == 1 ? CategoryEnum.收入 : CategoryEnum.支出),
                    Money    = item.Amounttt
                };
                result.Add(moneyItem);
            }
            return(result.OrderByDescending(d => d.Date));
        }
Beispiel #3
0
        public ActionResult Create(MoneyBookViewModels moneyBook)
        {
            if (ModelState.IsValid)
            {
                //驗證日期不能=今
                if (moneyBook.Date.CompareTo(DateTime.Now) > 0)
                {
                    ModelState.AddModelError("Date", "日期不得大於今天");
                    return(View("Index"));
                }

                _accountBookService.Add(ModelHelper.ConvertToAccountBookModel(moneyBook));
                //_accountBookService.Save();
                _unitOfWork.Commit();
                return(RedirectToAction("Index"));
            }

            return(View("Index"));
        }