in my API a user can be either a User
or an Admin
and I’m having some troubles editing a role of a user.
if I do:
var userAuth = _userAuthRepository.GetByPredicate(x => x.Company == companyId && x.Email == uc.User.Email).First();
var oldRoles = userAuth.Roles.ToList();
var newRole = new List<string> { request.Role.Value.ToString() };
_myAuthRepository.UnAssignRoles(userAuth, oldRoles); // remove all
_myAuthRepository.AssignRoles(userAuth, newRole); // add
I get a new duplicate user in UserAuth
table
if I go full NHibernate:
var allRoles = _rolesRepository.GetByPredicate(x => x.UserAuthId == userAuth.Id).ToList();
if (allRoles.Any())
// delete all
foreach (var role in allRoles) _rolesRepository.Delete(role);
// add new
_rolesRepository.SaveOrUpdate(new UserAuthRole() {
UserAuthId = userAuth.Id,
Role = request.Role.Value.ToString() });
I get an exception No persister for: ServiceStack.Auth.UserAuthRole
what am I doing wrong?