public async Task <IdentityResult> UpdateAsync(Role role, CancellationToken cancellationToken) { db.Entry(role).State = Microsoft.EntityFrameworkCore.EntityState.Modified; await db.SaveChangesAsync(cancellationToken); return(await Task.FromResult(IdentityResult.Success)); }
// EmployeeRole public Task AddToRoleAsync(Employee employee, string rolename, CancellationToken cancellationToken) { // add user to role // inline statement to catch rolename validity and assign its ID var roles = db.Role.FirstOrDefault(r => r.Name == rolename); var roleId = roles.Id; string employeeId = employee.Id; var employeerole = new IdentityUserRole <string>() { UserId = employee.Id, RoleId = roleId }; // Add new UserRole to IdentityUser table db.UserRoles.Add(employeerole); db.Entry(employee).State = Microsoft.EntityFrameworkCore.EntityState.Modified; return(Task.FromResult(db.SaveChanges())); }