Пример #1
0
        public static void SaveResult(int tournamentId, int golferId, int place, decimal winnings, bool isCut, bool isTied, bool isWithdrawn, bool isDisqualified, bool isPlayoff)
        {
            using (var db = new FantasyGolfContext())
            {
                var query = from x in db.TournamentResult
                            where x.TournamentId == tournamentId && x.GolferId == golferId
                            select x;

                var result = query.FirstOrDefault();
                if (result == null)
                {
                    result = new TournamentResult();
                    db.TournamentResult.Add(result);
                }
                else
                {
                    db.Entry(result).State = System.Data.Entity.EntityState.Modified;
                }

                result.TournamentId   = tournamentId;
                result.GolferId       = golferId;
                result.Place          = place;
                result.Winnings       = winnings;
                result.IsCut          = isCut;
                result.IsTied         = isTied;
                result.IsWithdrawn    = isWithdrawn;
                result.IsDisqualified = isDisqualified;
                result.IsPlayoff      = isPlayoff;

                db.SaveChanges();
            }
        }
Пример #2
0
        private void ParsePlayerLine(string line)
        {
            if (_status != EloFileReadStatus.Players)
            {
                throw new ParsingExeption(string.Format("Trying to parse player line while having wrong status:{0} - read line {1}", _status, line));
            }
            //%_%    5198, VAN DEN BERG, Erwin, NL,  7, 393
            line = PartToString(line, 4);
            if (line.StartsWith("+"))
            {
                line = PartToString(line, 2);
            }
            var values = line.Split(',');
            var player = new Player
            {
                PlayerId  = ConvertToInt(values[0]),
                LastName  = values[1].Trim(),
                FirstName = values[2].Trim(),
                Country   = new Country(values[3].Trim())
            };

            Tournament.Players.Add(player);
            var tournamentResult = new TournamentResult
            {
                PlayerId = player.PlayerId,
                Points   = ConvertToDouble(values[4]),
                Mbq      = ConvertToDouble(values[5])
            };

            Tournament.Results.Add(tournamentResult);
        }
Пример #3
0
        private void System_TournamentEnded(TournamentResult result, DateTime?next)
        {
            string message;

            if (next == null)
            {
                message = "Stream has gone offline, so the fishing tournament was ended early. D:";
                if (result.Entries.Count > 0)
                {
                    message += $" Winner at the time of conclusion: {UserLookup.GetUsername(result.Winner.UserId)} with a score of {result.Winner.Points}.";
                }
            }
            else
            {
                if (result.Entries.Count > 0)
                {
                    message = $"The fishing tournament has ended! Out of {result.Entries.Count} participants, {UserLookup.GetUsername(result.Winner.UserId)} won with {result.Winner.Points} points!";
                }
                else
                {
                    message = "The fishing tournament has ended.";
                }
            }
            PushNotification?.Invoke(null, new CommandResult {
                Processed = true, Messages = new string[] { message }
            });
        }
Пример #4
0
        public void StartTournamentDoesNothingIfTournamentAlreadyRunning()
        {
            var tournament = new TournamentResult()
            {
                Id = 123
            };

            System.CurrentTournament = tournament;
            System.StartTournament();
            Assert.AreEqual(tournament.Id, System.CurrentTournament.Id);
        }
Пример #5
0
        public ActionResult Results(int tournamentId, int?token)
        {
            using (var db = new Adriana42Context())
            {
                var tournamentRepository = new Repository <Models.Tournament>(db);
                var marketRepository     = new Repository <Models.Market>(db);
                var betRepository        = new Repository <Models.Bet>(db);
                var bets       = betRepository.Find(b => b.TournamentId == tournamentId && (!token.HasValue || token.Value == b.UserId));
                var tournament = tournamentRepository.GetById(t => t.Id == tournamentId);
                if (tournament == null)
                {
                    return(HttpNotFound());
                }

                var tournamentResult = new TournamentResult
                {
                    Id           = tournament.Id,
                    Description  = tournament.Description,
                    StartTimeUtc = tournament.StartTimeUtc,
                    EndTimeUtc   = tournament.EndTimeUtc,
                    ImgUrl       = tournament.ImgUrl,
                    Name         = tournament.Name
                };

                tournamentResult.MarketResults = bets.Select(b => new MarketResult
                {
                    MarketId          = b.MarketId,
                    ChosenSelectionId = b.SelectionId
                }).ToList();
                tournamentResult.MarketResults.ForEach(x =>
                {
                    var market = marketRepository.GetById(x.MarketId);
                    if (market != null)
                    {
                        x.Selections = market.Selections?.Select(s => new Selection
                        {
                            Id     = s.Id,
                            ImgUrl = s.ImgUrl,
                            Name   = s.Name,
                            Odds   = s.Odds.ToString(),
                            Result = s.Result
                        });
                        x.WinningSelectionId = x.Selections.FirstOrDefault(s => s.Result == true)?.Id;
                        x.Name   = market.Name;
                        x.ImgUrl = market.ImgUrl;
                    }
                    ;
                });

                return(View(tournamentResult));;
            }
        }
Пример #6
0
        public void EndsTournament()
        {
            var tournament = new TournamentResult()
            {
                Id = 123
            };
            var callbackMock = new Mock <TournamentEndHandler>();

            System.TournamentEnded  += callbackMock.Object;
            System.CurrentTournament = tournament;
            System.NextTournament    = null;
            System.EndTournament(true);
            Assert.IsNull(System.CurrentTournament);
            Assert.IsNotNull(System.NextTournament);
            Assert.IsTrue(TournamentResults.Data.Any(x => x.Id == tournament.Id));
            callbackMock.Verify(x => x(It.IsAny <TournamentResult>(), It.IsAny <DateTime>()));
        }
Пример #7
0
    public static void completeTournament(ref DataPool worldData, int managerIndex, TournamentResult result)
    {
        int boxerIndex = worldData.Managers[managerIndex].BoxerIndex;

        worldData.Managers[managerIndex].leaveTournament();

        worldData.Managers[managerIndex].Record.addWinBulk(result.Record.Wins);
        worldData.Managers[managerIndex].Record.addLossBulk(result.Record.Losses);
        worldData.Managers[managerIndex].Record.addTieBulk(result.Record.Ties);

        worldData.Boxers[boxerIndex].Record.addWinBulk(result.Record.Wins);
        worldData.Boxers[boxerIndex].Record.addLossBulk(result.Record.Losses);
        worldData.Boxers[boxerIndex].Record.addTieBulk(result.Record.Ties);

        if (result.QuarterlyWin)
        {
            worldData.Managers[managerIndex].graduateRank();
        }
    }
Пример #8
0
        private TournamentResult AddTournament(string eventDate, string selectedEvent, Game selectedGame, string url, WPEvent currentEvent)
        {
            int createTry = 0;
            var name      = $"[{eventDate}] LaDOSE.net - {selectedEvent} - {selectedGame.Name}";
            TournamentResult tournament = null;

            do
            {
                try
                {
                    if (createTry > 0)
                    {
                        url += createTry.ToString();
                    }
                    tournament = _challongeProvider.CreateTournament(name, url, currentEvent.Date).Result;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error Creating Challonge : " + ex.Message);
                    try
                    {
                        //Deja crée
                        var result = _challongeProvider.GetTournament(url).Result;
                        if (result.Name == name)
                        {
                            throw;
                        }
                    }
                    catch (Exception getex)
                    {
                        Console.WriteLine("Error Getting Challonge: " + url + " : " + getex.Message);
                    }

                    createTry++;
                }
            } while (tournament == null || createTry > MAX_CREATE_TRY);


            return(tournament);
        }
Пример #9
0
        /// <summary>
        /// Starts a new tournament.
        /// </summary>
        public void StartTournament()
        {
            if (CurrentTournament == null)
            {
                var fishers = Fishers.Read(x => x.IsFishing).ToList();
                foreach (var fisher in fishers)
                {
                    fisher.IsFishing  = false;
                    fisher.Hooked     = null;
                    fisher.HookedTime = null;
                    Fishers.Update(fisher);
                }
                Fishers.Commit();

                CurrentTournament = new TournamentResult
                {
                    Date = DateTime.Now.AddMinutes(Settings.FishingTournamentDuration)
                };
                NextTournament = null;
                TournamentStarted?.Invoke(CurrentTournament.Date);
            }
        }
        public void OnCreateTournamentComplete(ResultContainer resultContainer)
        {
            var result = new TournamentResult(resultContainer);

            CallbackManager.OnFacebookResponse(result);
        }
Пример #11
0
 public TournamentObject(TournamentResult result, ChallongeAPICaller caller)
 {
     this.result = result;
     this.caller = caller;
 }
        public async Task <PendingTournament> create(string name, TournamentType type, string url)
        {
            TournamentResult result = await new CreateTournamentQuery(name, type, url).call(caller);

            return(new TournamentObject(result, caller));
        }
        public async Task <TournamentObject> getTournament(string tournamentID)
        {
            TournamentResult tournamentResult = await new TournamentQuery(tournamentID, TournamentSubdomain).call(caller);

            return(new TournamentObject(tournamentResult, caller));
        }
Пример #14
0
        public async Task <TournamentObject> getTournament(int tournamentID)
        {
            TournamentResult tournamentResult = await new TournamentQuery(tournamentID).call(caller);

            return(new TournamentObject(tournamentResult, caller));
        }