public void delete(long role_id) { try { _transactionManager.beginTransaction(); var role = _roleRepo.getById(role_id); if (role == null) { throw new ItemNotFoundException($"User Role with the id {role_id} doesnot exist."); } var usersWithSpecifiedRole = _userRoleRepo.getByRoleId(role_id); bool usersWithRoleExists = usersWithSpecifiedRole.Count > 0; if (usersWithRoleExists) { throw new ItemUsedException("The specified role has already been assigned to some users."); } _roleRepo.delete(role); _rolePermissionMapService.deletePermissionsByRoleId(role_id); _transactionManager.commitTransaction(); } catch (Exception) { _transactionManager.rollbackTransaction(); throw; } }
public void save(UserRoleDto dto) { try { _transactionManager.beginTransaction(); //var previousAssignedRoles = _userRoleRepo.getByTypeId(dto.type, dto.type_id); //bool isRoleAlreadyAssignedToUser = previousAssignedRoles.Count > 0; ////if (isRoleAlreadyAssignedToUser) ////{ //throw new InvalidValueException("Roles have already been assigned to the user."); //// } foreach (var roleId in dto.role_ids.Distinct()) { UserRole user_role = new UserRole(); user_role.role_id = roleId; user_role.role = _roleRepo.getById(roleId) ?? throw new ItemNotFoundException($"Role with the role id {roleId} doesnot exist."); user_role.type = dto.type; user_role.type_id = dto.type_id; _userRoleRepo.insert(user_role); _transactionManager.commitTransaction(); } } catch (Exception) { _transactionManager.rollbackTransaction(); throw; } }
public void disable(long type_id, UserType type = UserType.user) { try { _transactionManager.beginTransaction(); var authentication = _authenticationRepo.getByType(type_id, type) ?? throw new ItemNotFoundException($"Authentication detail doesnot exist."); authentication.deactivate(); _authenticationRepo.update(authentication); _transactionManager.commitTransaction(); } catch (Exception) { _transactionManager.rollbackTransaction(); throw; } }
public void save(LoginSessionDto session_dto) { try { _transactionManager.beginTransaction(); var authentication = _authenticationRepo.getById(session_dto.authentication_id); LoginSession sessionDetail = new LoginSession(); _loginSessionMaker.copy(sessionDetail, session_dto); sessionDetail.authentication = authentication ?? throw new ItemNotFoundException($"Authentication with the id {session_dto.authentication_id} doesnot exist."); _loginSessionRepo.insert(sessionDetail); _transactionManager.commitTransaction(); } catch (System.Exception) { _transactionManager.rollbackTransaction(); throw; } }