コード例 #1
0
        public ActionResult Index([Bind(Include = "Id,Category,Amount,Date,Remark")] AccountBookViewModels accountBookViewModels)
        {
            //if (ModelState.IsValid)
            //{
            //accountBookModels.Id = Guid.NewGuid();
            //db.AccountBook.Add(accountBookModels);
            //db.SaveChanges();
            //return RedirectToAction("Index");
            //}

            //return View(accountBookModels);

            if (ModelState.IsValid)
            {
                accountBookViewModels.Id = Guid.NewGuid();
                _accountBookSvc.Add(accountBookViewModels);
                _accountBookSvc.Save();

                return(RedirectToAction("Index"));
            }

            var result = new AccountBookViewModels()
            {
                Id       = accountBookViewModels.Id,
                Amount   = accountBookViewModels.Amount,
                Category = accountBookViewModels.Category,
                Date     = accountBookViewModels.Date,
                Remark   = accountBookViewModels.Remark
            };

            return(View(result));
        }
コード例 #2
0
        public ActionResult CreateMoney(MoneyViewModel moneyData)
        {
            if (ModelState.IsValid)
            {
                _accountBookService.Add(new AccountBook
                {
                    Id         = Guid.NewGuid(),
                    Categoryyy = (int)moneyData.類別,
                    Amounttt   = moneyData.金錢,
                    Dateee     = moneyData.時間,
                    Remarkkk   = moneyData.備註
                });
                _unitOfWork.Commit();
            }
            var data        = _accountBookService.GetAllAccountBooks();
            var mappingData = from d in data
                              select new MoneyViewModel
            {
                類別 = (CategoryEnum)d.Categoryyy,
                時間 = d.Dateee,
                金錢 = d.Amounttt,
                備註 = d.Remarkkk
            };

            return(PartialView("ListMoney", mappingData.ToList()));
        }
コード例 #3
0
 public ActionResult Index(MoneyViewModel moneyRecord)
 {
     if (ModelState.IsValid)
     {
         moneyRecord.Id = Guid.NewGuid();
         _accountBookService.Add(moneyRecord);
         _unitOfWork.Commit();
         return(RedirectToAction("Index"));
     }
     return(View(moneyRecord));
 }
コード例 #4
0
        public ActionResult Create(AccountingViewModel data)
        {
            if (ModelState.IsValid)
            {
                _accountBookService.Add(data);
                _accountBookService.Save();

                return(RedirectToAction("Index"));
            }

            return(PartialView(data));
        }
コード例 #5
0
 public ActionResult AjaxPost(CreateViewModel model)
 {
     if (ModelState.IsValid)
     {
         model.AccountBookModel.ClassType = model.CategoryOptions.ToString();
         //fix null存檔會出錯
         model.AccountBookModel.Note = model.AccountBookModel.Note ?? string.Empty;
         _accountBookSvc.Add(model.AccountBookModel);
         _accountBookSvc.Save();
         return(RedirectToAction("ResultList"));
     }
     return(PartialView("CreatePartial", model));
 }
コード例 #6
0
        public ActionResult Index(AccountBook data)
        {
            if (ModelState.IsValid)
            {
                //data.Id = new Guid(); guid 會是 00000000-0000-0000-0000-000000000000
                data.Id = Guid.NewGuid(); //正確
                _accountbookService.Add(data);
                _unitOfWork.Commit();
                return(RedirectToAction("Index"));
            }

            return(View(data));
        }
コード例 #7
0
        public ActionResult Input([Bind(Include = "Category,Date,Amount,Remark")]
                                  PersonalAccountingViewModel accountingViewModel)
        {
            if (ModelState.IsValid)
            {
                _accountBookService.Add(accountingViewModel);
                _unitOfWork.Commit();

                ModelState.Remove("Category");
                ModelState.Remove("Date");
                ModelState.Remove("Amount");
                ModelState.Remove("Remark");
            }

            return(View());
        }
コード例 #8
0
        //[ValidateAntiForgeryToken]
        public ActionResult Create(MoneyModel moneyModel)
        {
            if (ModelState.IsValid)
            {
                var account = new AccountBook();
                account.Id         = Guid.NewGuid();
                account.Categoryyy = Convert.ToInt32(moneyModel.Type);
                account.Amounttt   = Convert.ToInt32(moneyModel.Money);
                account.Remarkkk   = moneyModel.Remark;
                _accountBookService.Add(account);
                _accountBookService.Save();

                return(RedirectToAction("AccountingBook"));
            }
            return(View(moneyModel));
        }
コード例 #9
0
        public ActionResult Create([Bind(Include = "Money,ExpenseIncometype,CreateTime,Remark")]
                                   ExpenseIncomeViewModel expenseIncomeViewModel)
        {
            var IsCreate = false;

            ViewData["TypeList"] = _classifyService.getOptionToSelectList("account_kind");
            if (ModelState.IsValid)
            {
                _accountBookService.Add(expenseIncomeViewModel);
                _unitOfWork.Commit();
                ModelState.Clear();
                IsCreate = true;
            }
            ViewData["IsCreate"] = IsCreate;

            return(View());
        }
コード例 #10
0
ファイル: MoneyBookController.cs プロジェクト: faychen/MvcHw
        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"));
        }
コード例 #11
0
ファイル: HomeController.cs プロジェクト: lynnlee19/finance
        public ActionResult Create([Bind(Exclude = "Id")] AccountBook accountBook)
        {
            if (ModelState.IsValid)
            {
                accountBook.Id = Guid.NewGuid();
                _AccountBookService.Add(accountBook);
                _LogService.Add(ControllerContext.RouteData.Values["action"].ToString(), "Id=" + accountBook.Id.ToString());

                //_AccountBookService.Save();
                //_LogService.Save();
                _unitOfWork.Commit();
                return(RedirectToAction("Index"));
            }

            IList <SelectListItem> list = this.GetCategoryList();

            ViewData["categoryList"] = list;
            return(View(accountBook));
        }
コード例 #12
0
        public ActionResult Create([Bind(Include = "Id,Category,Amount,Date,Remark")] AccountBookViewModels accountBookViewModels)
        {
            if (ModelState.IsValid)
            {
                accountBookViewModels.Id = Guid.NewGuid();
                _accountBookSvc.Add(accountBookViewModels);
                _accountBookSvc.Save();

                return(RedirectToAction("Index"));
            }

            var result = new AccountBookViewModels()
            {
                Id       = accountBookViewModels.Id,
                Amount   = accountBookViewModels.Amount,
                Category = accountBookViewModels.Category,
                Date     = accountBookViewModels.Date,
                Remark   = accountBookViewModels.Remark
            };

            return(View(accountBookViewModels));
        }
コード例 #13
0
        public ActionResult Index([Bind(Include = "Category,Amount,Date,Remark")] Models.ViewModels.EditRecordViewModel accountBook)
        {
            if (ModelState.IsValid)
            {
                var CreatorID = User.Identity.Name;
                var recordId  = Guid.NewGuid();
                var NewRecord = new Models.AccountBook
                {
                    Id       = recordId,
                    Category = (int)accountBook.Category,
                    Date     = accountBook.Date,
                    Amount   = accountBook.Amount,
                    Remark   = accountBook.Remark,
                    CreateDT = DateTime.Now,
                    Creator  = CreatorID
                };

                _AccountBookSvc.Add(NewRecord);
                _AccountBookSvc.Save();
            }

            return(View());
        }
コード例 #14
0
        public ActionResult Index(IndexViewModel vm)
        {
            bool isSuccess = true;

            if (ModelState.IsValid)
            {
                if (vm.item != null)
                {
                    if (vm.item.Amount <= 0)
                    {
                        ModelState.AddModelError("item.Amount", "金額不可小於或等於零!");
                        isSuccess = false;
                    }

                    if (vm.item.DataDate.Date > DateTime.Now.Date)
                    {
                        ModelState.AddModelError("item.DataDate", "日期不可大於今天!");
                        isSuccess = false;
                    }

                    if (isSuccess)
                    {
                        _accountBookSvc.Add(vm.item);
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Invalid input item!");
                }
            }

            List <SelectListItem> typeList = new List <SelectListItem>(GetTypeData());

            ViewBag.typeSelectList = typeList;
            return(View(vm));
        }