public async Task <IActionResult> Create([Bind("Name,Greeting")] Household household) { if (ModelState.IsValid) { household.Established = DateTime.Now; _context.Add(household); await _context.SaveChangesAsync(); var currentUser = await _userManager.GetUserAsync(User); currentUser.HouseholdId = household.Id; await _userManager.AddToRoleAsync(currentUser, PortalRole.HOH.ToString()); await _context.SaveChangesAsync(); await _signInManager.RefreshSignInAsync(currentUser); return(RedirectToAction("Details", "Households", new { id = household.Id })); } return(View(household)); }
public async Task <IActionResult> Create([Bind("Id,HouseholdId,Created,Subject,Body,IsRead")] Notification notification) { if (ModelState.IsValid) { _context.Add(notification); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(notification)); }
public async Task <IActionResult> Create([Bind("HouseholdId,Name,Description")] Category category) { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction("Details", "Households", new { id = category.HouseholdId })); } ViewData["HouseholdId"] = new SelectList(_context.Set <Household>(), "Id", "Id", category.HouseholdId); return(View(category)); }
public async Task <IActionResult> Create([Bind("Name,CategoryId,Description,TargetAmount")] CategoryItem categoryItem) { if (ModelState.IsValid) { _context.Add(categoryItem); await _context.SaveChangesAsync(); var category = await _context.Category.Include(c => c.Household).FirstOrDefaultAsync(c => c.Id == categoryItem.CategoryId); return(RedirectToAction("Details", "Households", new { id = category.HouseholdId })); } return(View(categoryItem)); }
public async Task <IActionResult> Create([Bind("HouseholdId,Name,Type,StartingBalance")] BankAccount bankAccount) { if (ModelState.IsValid) { bankAccount.FPUserId = _userManager.GetUserId(User); bankAccount.CurrentBalance = bankAccount.StartingBalance; _context.Add(bankAccount); await _context.SaveChangesAsync(); return(RedirectToAction("Details", "Households", new { id = bankAccount.HouseholdId })); } return(View(bankAccount)); }
public async Task <IActionResult> Create([Bind("CategoryItemId,BankAccountId,Created,Type,Memo,Amount")] Transaction transaction) { if (ModelState.IsValid) { transaction.FPUserId = _userManager.GetUserId(User); _context.Add(transaction); await _context.SaveChangesAsync(); //1:Decrease the Bank Current Balance var account = await _context.BankAccount.FindAsync(transaction.BankAccountId); var oldBalance = account.CurrentBalance; if (transaction.Type == Enum.TransactionType.Deposit) { account.CurrentBalance += transaction.Amount; } else { //Withdrawl account.CurrentBalance -= transaction.Amount; //2:Increase the Actual Amount of the associated Category Item var categoryItem = await _context.CategoryItem.FindAsync(transaction.CategoryItemId); categoryItem.ActualAmount += transaction.Amount; } await _context.SaveChangesAsync(); //3:Look for any needed notifications if (account.CurrentBalance < 0) { TempData["OverDraft"] = "you overdrft your account. FOO"; } await _notificationService.NotifyOverdraftAsync(transaction, account, oldBalance); return(RedirectToAction("Details", "Households", new { id = (await _userManager.GetUserAsync(User)).HouseholdId })); } ViewData["BankAccountId"] = new SelectList(_context.BankAccount, "Id", "Name", transaction.BankAccountId); ViewData["CategoryItemId"] = new SelectList(_context.CategoryItem, "Id", "Name", transaction.CategoryItemId); ViewData["FPUserId"] = new SelectList(_context.Users, "Id", "FullName", transaction.FPUserId); return(View(transaction)); }