示例#1
0
        public ActionResult Create([Bind(Include = "Id,Name,Description,InitiationBalance,AccountNumber,CategoryId")] Account account)
        {
            ApplicationUser user = db.Users.Find(User.Identity.GetUserId());

            if (ModelState.IsValid)
            {
                if (user.HouseholdId == null)
                {
                    return(RedirectToAction("Index", "Manage"));
                }
                account.Opened      = DateTime.UtcNow;
                account.OwnerId     = user.Id;
                account.HouseholdId = user.HouseholdId.Value;
                account.IsActive    = true;
                db.Accounts.Add(account);
                db.SaveChanges();
                TransactionProcessor txProc = new TransactionProcessor();
                txProc.AccountInitiatorTransaction(account.Id, account.InitiationBalance, user);
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(db.AccountCategories.Where(x => x.HouseholdId == 0 || x.HouseholdId == user.HouseholdId), "Id", "Category", account.CategoryId);
            return(View(account));
        }