public virtual void SavePersistedGrant(int userId, string grantClientId, PersistedGrantEntity newGrant) { var user = m_userRepository.FindById <UserEntity>(userId); if (user == null) { throw new NoResultException <UserEntity>(); } var client = m_clientRepository.FindClientByName(grantClientId); if (client == null) { throw new NoResultException <ClientEntity>(); } var persistedGrant = m_persistedGrantRepository.FindByKey(newGrant.Key); if (persistedGrant != null) //TODO Investigate performance of this { persistedGrant.Client = client; persistedGrant.User = user; persistedGrant.CreationTime = newGrant.CreationTime; persistedGrant.ExpirationTime = newGrant.ExpirationTime; persistedGrant.Type = newGrant.Type; persistedGrant.Data = newGrant.Data; m_persistedGrantRepository.Save(persistedGrant); } else { newGrant.User = user; newGrant.Client = client; m_persistedGrantRepository.Create(newGrant); } }