public void ParticipateInRoundWithExistingAccount(long clientId, long roundId, long walletId, long accountId, bool joinNearest, string language, bool?usePass) { Logger.Trace("Participate in round {0}. Client {4}, account {2}, wallet {1}, {3}use pass", roundId, walletId, accountId, !usePass.HasValue || !usePass.Value ? "don't " : "", clientId); return(InvokeOperations.InvokeOperation(() => { try { var clientData = clientService.GetClient(clientId); if (!clientData.IsSuccess) { throw new OperationException(clientData.Error, clientData.Code); } if (tournamentRepository.CheckRoundParticipation(roundId, clientId)) { throw new OperationException("Already participant", ResultCode.TournamentAlreadyParticipate); } var round = tournamentRepository.GetRound(roundId); var account = tournamentRepository.GetParticipant(accountId); if (account.client_account_id != clientId) { throw new Exception("Wrong client id"); } if (round.AccountType != account.account_type_id) { throw new Exception(String.Format("Wrong account type. was {0} expected {1}", account.account_type_id, round.AccountType)); } var tournament = tournamentRepository.GetTournament(round.Round.tournament_id); if (tournament.entrance_only_by_pass && (!usePass.HasValue || !usePass.Value)) { throw new OperationException("Entrance only by pass", ResultCode.TournamentWelcomeNotAllowed); } if (tournament.authorized_only) { var clientStatusesData = clientService.GetClientStatuses(clientId); if (!clientStatusesData.IsSuccess) { throw new OperationException(clientStatusesData.Error, clientStatusesData.Code); } if (!clientStatusesData.Result.Has(ClientStatuses.IsApproved)) { throw new OperationException("Client is not approved", ResultCode.TournamentAuthorizedOnly); } } //Check freeroll prizes and bans if (tournament.type_id == (int)TournamentsType.FreeRoll) { if (clientData.Result.ClientStatuses.Has(ClientStatuses.IsPromotionBlocked)) { throw new OperationException("Participation in round is not available", ResultCode.SiteOperationNotAvailable); } if (tournamentRepository.CheckClientTournamentPrizes(clientId, tournament.id_name)) { throw new OperationException("Already has prize", ResultCode.TournamentAlreadyWon); } if (tournamentRepository.CheckClientBans(clientId, tournament.type_id)) { throw new OperationException("Banned", ResultCode.TournamentBanned); } } else if (tournament.type_id == (int)TournamentsType.Special) { if (tournamentRepository.CheckSpecialTournamentParticipation(clientId, tournament.id_name)) { throw new OperationException("Already participant", ResultCode.TournamentChallengeAlreadyParticipate); } } if (joinNearest) { round = tournamentRepository.GetNearestRound(tournament.id_name); } else if (round.Round.is_started && !tournament.entry_after_start) { throw new OperationException("Round is already started", ResultCode.TournamentRoundAlreadyStarted); } var participants = tournamentRepository.GetRoundParticipants(roundId).Count(); if (tournament.participants_number != 0) { if (participants >= tournament.participants_number) { throw new OperationException("Round is full", ResultCode.TournamentRoundIsFull); } } if (CheckRoundsIntersection(tournamentRepository.GetAccountActiveRounds(accountId), round.Round.date_start, round.Round.date_end)) { throw new OperationException("Rounds intersection", ResultCode.TournamentRoundsIntersection); } PayForTournament(tournament, round, walletId, clientId, language, clientData.Result.Email, usePass); accountService.ChangeAccountBalance(accountId, 0, ""); tournamentRepository.AddRoundParticipation(accountId, roundId, walletId); if (round.Round.is_started) { var resMove = accountService.ChangeAccountGroup(accountId, tournament.group_name); if (!resMove.IsSuccess) { throw new OperationException(resMove.Error, (ResultCode)resMove.Code); } if (tournament.leverage != null) { var leverageRes = accountService.ChangeAccountLeverage(accountId, (int)tournament.leverage); if (!leverageRes.IsSuccess) { throw new OperationException(leverageRes.Error, (ResultCode)leverageRes.Code); } } var flagResult = accountService.ChangeReadOnlyFlag(accountId, false); if (!flagResult.IsSuccess) { throw new OperationException(flagResult.Error, (ResultCode)flagResult.Code); } var setBalanceResult = accountService.SetAccountsBalance(new[] { accountId }, tournament.base_deposit, new[] { string.Format(MT4CommentHelper.GetMt4CommentTournament(MT4CommentHelper.MT4CommentType.Deposit, tournament.id_name, round.Round.id, accountId)) }); if (!setBalanceResult.IsSuccess) { throw new OperationException(setBalanceResult.Error, (ResultCode)setBalanceResult.Code); } } tournamentProcessor.ConstructRoundRating(round.Round); participants = tournamentRepository.GetRoundParticipants(roundId).Count(); if (!round.Round.is_started && participants == tournament.participants_number) { tournamentProcessor.StartRound(round.Round); } } catch (Exception ex) { Logger.Error("Error at participate in round {0}. Client {4}, account {2}, wallet {1}, {3}use pass. {5}", roundId, walletId, accountId, !usePass.HasValue || !usePass.Value ? "don't " : "", clientId, ex.ToString()); throw; } })); }