예제 #1
0
        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();
        }
예제 #2
0
        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));
        }
예제 #3
0
        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));
        }
예제 #4
0
 public async Task Save()
 {
     await _context.SaveChangesAsync();
 }
예제 #5
0
 public virtual async Task <int> CommitAsync()
 {
     return(await Context.SaveChangesAsync());
 }
 public async Task <int> CommitAsync()
 {
     return(await _context.SaveChangesAsync());
 }