public async Task Update(AppUser userParam, string password = null) { var user = await _context.Users.FindAsync(userParam.AppUserId); if (user == null) { throw new Exception("User not found"); } if (userParam.Username != user.Username) { // username has changed so check if the new username is already taken if (await _context.Users.AnyAsync(x => x.Username == userParam.Username)) { throw new Exception("Username " + userParam.Username + " is already taken"); } } // update user properties user.FirstName = userParam.FirstName; user.LastName = userParam.LastName; user.Username = userParam.Username; // update password if it was entered if (!string.IsNullOrWhiteSpace(password)) { SecurityUtils.CreatePasswordHash(password, out var passwordHash, out var passwordSalt); user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; } _context.Users.Update(user); await _context.SaveChangesAsync(); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Email")] Student student) { if (ModelState.IsValid) { _context.Add(student); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(student)); }
public async Task <IActionResult> Create([Bind("Id,Title,ReleaseDate,Genre,Price")] Movie movie) { if (ModelState.IsValid) { _context.Add(movie); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(movie)); }
public async Task Save() { await _context.SaveChangesAsync(); }
public virtual async Task <int> CommitAsync() { return(await Context.SaveChangesAsync()); }
public async Task <int> CommitAsync() { return(await _context.SaveChangesAsync()); }