public void AttachRole(string userName, string role)
 {
     int userId = GetUserId(userName);
     if (userId != 0)
     {
         int roleId = periodicalContext.Roles.Where(x => x.RoleValue == role).Select(x => x.Id).FirstOrDefault();
         UserInRole newUserInRole = new UserInRole();
         newUserInRole.RoleId = roleId;
         newUserInRole.UserId = userId;
         periodicalContext.UsersInRoles.Add(newUserInRole);
         SaveChanges();
     }
 }
Exemplo n.º 2
0
 private void AttachUserRole(int userId)
 {
     int roleId = periodicalContext.Roles.Where(x => x.RoleValue == "User").Select(x => x.Id).FirstOrDefault();
     UserInRole newUserInRole = new UserInRole();
     newUserInRole.RoleId = roleId;
     newUserInRole.UserId = userId;
     periodicalContext.UsersInRoles.Add(newUserInRole);
 }