Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        // 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()));
        }