public Guid OrderCollection(DebtDetails debtDetails) { var clientId = _playerRepository.GetPlayerId(debtDetails.ClientRealm, debtDetails.ClientName); if (clientId == default(Guid)) { var clientApiResult = _gameApiClient.GetCharacterDetails(debtDetails.ClientRealm, debtDetails.ClientName); if (clientApiResult == null) { throw new ArgumentOutOfRangeException(nameof(debtDetails.ClientName), "Could not find specified character"); } clientId = _playerRepository.AddPlayer(debtDetails.ClientRealm, debtDetails.ClientName); } var debtorId = _playerRepository.GetPlayerId(debtDetails.DebtorRealm, debtDetails.DebtorName); if (debtorId == default(Guid)) { var debtorApiResult = _gameApiClient.GetCharacterDetails(debtDetails.DebtorRealm, debtDetails.DebtorName); if (debtorApiResult == null) { throw new ArgumentOutOfRangeException(nameof(debtDetails.DebtorName), "Could not find specified character"); } debtorId = _playerRepository.AddPlayer(debtDetails.DebtorRealm, debtDetails.DebtorName); } var orderId = _debtRepository.AddDebt(debtorId, clientId, debtDetails.DebtContextId, debtDetails.DebtAmount); var userName = WindowsIdentity.GetCurrent().Name; _debtCollectionRepository.UpdateOrderAssignment(orderId, userName); return(orderId); }