public async Task <IActionResult> Post([FromBody] EmployeeModel model) { var user = await _applicationUserRepository.FindById(model.ID.ToString()); List <Task> tasks = new List <Task>(); if (user == default) { return(NotFound()); } user.Email = model.Email; user.PhoneNumber = model.PhoneNumber; user.FirstName = model.FirstName; user.LastName = model.LastName; user.AddressLine = model.AddressLine; user.PostalCode = model.PostalCode; user.Town = model.Town; tasks.Add(_applicationUserRepository.Update(user)); var listOfCurrentRoles = await _applicationUserRepository.GetRoles(user); var listOfNewRoles = model.Roles; foreach (var item in FindDifferences(listOfNewRoles, listOfCurrentRoles)) { tasks.Add(_applicationUserRepository.AddToRole(user, item)); } foreach (var item in FindDifferences(listOfCurrentRoles, listOfNewRoles)) { tasks.Add(_applicationUserRepository.RemoveFromRole(user, item)); } await Task.WhenAll(tasks); return(Ok()); }
public async Task AddToRoleAsync(ApplicationUser user, string roleName, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); await userRepository.AddToRole(user, roleName); }