public void DeleteRole(Role role)
 {
     try
     {
         if (role == null)
         {
             _logger.Error("role is null AuthentificationService.cs");
             throw new ArgumentNullException("role");
         }
         _unitOfWork.RoleRepository.Delete(role);
         _unitOfWork.Save();
     }
     catch (Exception ex)
     {
         _logger.Error("Error in AuthentificationService.cs DeleteRole(Role role)" + ex.Message);
         throw;
     }
 }
        public bool UpdateRole(Role role, List<int> users)
        {
            try
            {
                if (role == null)
                {
                    _logger.Error("UpdateRole(Role role, List<int> users) role is null ");
                    throw new ArgumentNullException("role");
                }
                Role r = _unitOfWork.RoleRepository.GetById(role.Id);
                role.Users= new List<User>();
                foreach (var u in users)
                    role.Users.Add(_unitOfWork.UserRepository.GetById(u));
                _unitOfWork.RoleRepository.AttachStubs(role.Users.ToArray());

                foreach (var user in _unitOfWork.UserRepository.Get())
                {
                    if (user.UserRoles.Any(x => x.Id == role.Id))
                        user.UserRoles.Remove(user.UserRoles.First(x => x.Id == role.Id));
                }
                foreach (var prop in r.GetType().GetProperties())
                {
                    prop.SetValue(r, role.GetType().GetProperty(prop.Name).GetValue(role));
                }

                _unitOfWork.RoleRepository.Update(r);
                _unitOfWork.Save();
                return true;
            }
            catch (Exception ex)
            {
                _logger.Error("Error in AuthentificationService.cs UpdateUser(User user, IEnumerable<int> roles))" + ex.Message);
                throw;
            }
        }