public async Task <IActionResult> Edit(int id, [Bind("ExpenseID,BudgetID,CategoryID,Description,Amount")] Expense expense) { if (id != expense.ExpenseID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(expense); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ExpenseExists(expense.ExpenseID)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index", new { budgetId = expense.BudgetID })); } return(View(expense)); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var aspUser = await _userManager.GetUserAsync(User); if (aspUser == null) { return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.")); } var email = await _userManager.GetEmailAsync(aspUser); var user = _context.Users.FirstOrDefault(u => u.Email == email); user.FirstName = Input.FirstName; user.LastName = Input.LastName; _context.Update(user); await _context.SaveChangesAsync(); await _signInManager.RefreshSignInAsync(aspUser); StatusMessage = "Your profile has been updated"; return(RedirectToPage()); }
public async Task <IActionResult> Edit(int id, [Bind("BudgetID,UserID,BudgetName,BudgetMax,BudgetTotal,CreationDate")] Budget budget) { if (id != budget.BudgetID) { return(NotFound()); } var user = GetUser(); if (user.UserID != budget.UserID) { return(NotFound()); } ViewData["DuplicateNameErrorMessage"] = ""; try { budget.BudgetName = budget.BudgetName.Trim(); } catch (NullReferenceException) { ViewData["DuplicateNameErrorMessage"] = "Budget name cannot be empty"; return(View(budget)); } var existingBudget = await _context.Budgets .SingleOrDefaultAsync(b => b.BudgetName.ToLower() == budget.BudgetName.ToLower() && b.UserID == budget.UserID && b.BudgetID != budget.BudgetID); if (existingBudget != null) { ViewData["DuplicateNameErrorMessage"] = "This budget already exists"; return(View(budget)); } if (ModelState.IsValid) { try { _context.Update(budget); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BudgetExists(budget.BudgetID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(budget)); }
public async Task <IActionResult> Edit(int id, [Bind("CategoryID,CategoryName,UserID")] Category category) { if (id != category.CategoryID) { return(NotFound()); } var user = GetUser(); if (user.UserID != category.UserID) { return(NotFound()); } ViewData["DuplicateNameErrorMessage"] = ""; try { category.CategoryName = category.CategoryName.Trim(); } catch (NullReferenceException) { ViewData["DuplicateNameErrorMessage"] = "Category name cannot be empty"; return(View(category)); } var existingCategory = await _context.Categories .SingleOrDefaultAsync(c => c.CategoryName.ToLower() == category.CategoryName.ToLower() && c.UserID == category.UserID && c.CategoryID != category.CategoryID); if (existingCategory != null) { ViewData["DuplicateNameErrorMessage"] = "This category already exists"; return(View(category)); } if (ModelState.IsValid) { try { _context.Update(category); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(category.CategoryID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(category)); }