当前位置: 首页>>代码示例>>C#>>正文


C# DataContext.GetTournament方法代码示例

本文整理汇总了C#中DataContext.GetTournament方法的典型用法代码示例。如果您正苦于以下问题:C# DataContext.GetTournament方法的具体用法?C# DataContext.GetTournament怎么用?C# DataContext.GetTournament使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataContext的用法示例。


在下文中一共展示了DataContext.GetTournament方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Get

        public IHttpActionResult Get(Guid tournamentKey)
        {
            using(var dataContext = new DataContext())
            {
                var tournament = dataContext.GetTournament(tournamentKey);

                if(tournament == null)
                    return NotFound();

                return Ok(TournamentResponseProvider.Create(tournament));
            }
        }
开发者ID:Jaecen,项目名称:Peregrine,代码行数:12,代码来源:TournamentController.cs

示例2: Get

        public IHttpActionResult Get(Guid tournamentKey)
        {
            using(var dataContext = new DataContext())
            {
                var tournament = dataContext
                    .GetTournament(tournamentKey);

                if(tournament == null)
                    return NotFound();

                var roundNumbers = tournament
                    .Rounds
                    .Select(round => new
                        {
                            Number = round.Number,
                            State = RoundManager.GetRoundState(tournament, round.Number),
                        })
                    .Select(o => new
                        {
                            number = o.Number,
                            started = o.State >= RoundState.Committed,
                            completed = o.State >= RoundState.Completed,
                            final = o.State >= RoundState.Final,
                        })
                    .OrderBy(round => round.number)
                    .ToArray();

                var lastRoundNumber = tournament
                    .Rounds
                    .Select(round => round.Number)
                    .OrderBy(number => number)
                    .DefaultIfEmpty(0)
                    .LastOrDefault();

                var nextRoundState = RoundManager.GetRoundState(tournament, lastRoundNumber + 1);

                if(nextRoundState != RoundState.Invalid && lastRoundNumber < RoundManager.GetMaxRoundsForTournament(tournament))
                    roundNumbers = roundNumbers
                        .Concat(new[]
                            {
                                new
                                {
                                    number = lastRoundNumber + 1,
                                    started = false,
                                    completed = false,
                                    final = false,
                                }
                            })
                        .ToArray();

                return Ok(roundNumbers);
            }
        }
开发者ID:Jaecen,项目名称:Peregrine,代码行数:53,代码来源:RoundsController.cs

示例3: Delete

        public IHttpActionResult Delete(Guid tournamentKey)
        {
            using(var dataContext = new DataContext())
            {
                var tournament = dataContext.GetTournament(tournamentKey);

                if(tournament == null)
                    return NotFound();

                dataContext.Tournaments.Remove(tournament);
                dataContext.SaveChanges();

                return StatusCode(HttpStatusCode.NoContent);
            }
        }
开发者ID:Jaecen,项目名称:Peregrine,代码行数:15,代码来源:TournamentController.cs

示例4: Put

        public IHttpActionResult Put(Guid tournamentKey, [FromBody] ActiveRoundRequest request)
        {
            using(var dataContext = new DataContext())
            {
                var tournament = dataContext
                    .GetTournament(tournamentKey);

                if(tournament == null)
                    return NotFound();

                tournament.ActiveRoundNumber = request.roundNumber;
                dataContext.SaveChanges();

                return Ok(ActiveRoundResponseProvider.Create(tournament, tournament.ActiveRoundNumber));
            }
        }
开发者ID:Jaecen,项目名称:Peregrine,代码行数:16,代码来源:ActiveRoundController.cs

示例5: Delete

        public IHttpActionResult Delete(Guid tournamentKey, string playerName)
        {
            using(var dataContext = new DataContext())
            {
                var tournament = dataContext
                    .GetTournament(tournamentKey);

                if(tournament == null)
                    return NotFound();

                var player = tournament
                    .GetPlayer(playerName);

                if(player == null)
                    return NotFound();

                var tournamentHasResults = tournament
                    .Rounds
                    .Where(round => round
                        .Matches
                        .Any()
                    )
                    .Any();

                if(tournamentHasResults)
                {
                    // Drop
                    player.Dropped = true;

                    dataContext.SaveChanges();

                    return Ok(PlayerResponseProvider.Create(player));
                }
                else
                {
                    // Delete
                    dataContext.Players.Remove(player);
                    dataContext.SaveChanges();

                    return ResponseMessage(new System.Net.Http.HttpResponseMessage(System.Net.HttpStatusCode.NoContent)
                        {
                            Content = new StringContent(String.Empty, Encoding.UTF8, "application/json")
                        });
                }
            }
        }
开发者ID:Jaecen,项目名称:Peregrine,代码行数:46,代码来源:PlayerController.cs

示例6: Get

        public IHttpActionResult Get(Guid tournamentKey)
        {
            using(var dataContext = new DataContext())
            {
                var tournament = dataContext
                    .GetTournament(tournamentKey);

                if(tournament == null)
                    return NotFound();

                var playerNames = tournament
                    .Players
                    .Select(player => PlayerResponseProvider.Create(player))
                    .ToArray();

                return Ok(playerNames);
            }
        }
开发者ID:Jaecen,项目名称:Peregrine,代码行数:18,代码来源:PlayersController.cs

示例7: Get

        public IHttpActionResult Get(Guid tournamentKey, int roundNumber)
        {
            using(var dataContext = new DataContext())
            {
                var tournament = dataContext
                    .GetTournament(tournamentKey);

                if(tournament == null)
                    return NotFound();

                var round = RoundManager.GetRound(tournament, roundNumber);

                if(round == null)
                    return NotFound();

                return Ok(RoundResponseProvider.Create(tournament, round));
            }
        }
开发者ID:Jaecen,项目名称:Peregrine,代码行数:18,代码来源:RoundController.cs

示例8: Put

        public IHttpActionResult Put(Guid tournamentKey, [FromBody] TournamentRequest requestBody)
        {
            if(requestBody == null)
                return BadRequest("No request body provided.");

            using(var dataContext = new DataContext())
            {
                var tournament = dataContext.GetTournament(tournamentKey);

                if(tournament == null)
                    return NotFound();

                tournament.Name = requestBody.name;
                dataContext.SaveChanges();

                return Ok(TournamentResponseProvider.Create(tournament));
            }
        }
开发者ID:Jaecen,项目名称:Peregrine,代码行数:18,代码来源:TournamentController.cs

示例9: Get

        public IHttpActionResult Get(Guid tournamentKey, int? roundNumber = null)
        {
            using(var dataContext = new DataContext())
            {
                var tournament = dataContext.GetTournament(tournamentKey);

                if(tournament == null)
                    return NotFound();

                if(roundNumber.HasValue && tournament.GetRound(roundNumber.Value) == null)
                    return NotFound();

                if(!roundNumber.HasValue && !tournament.ActiveRoundNumber.HasValue)
                    return NotFound();

                return Ok(StandingsResponseProvider.Create(tournament, roundNumber));
            }
        }
开发者ID:Jaecen,项目名称:Peregrine,代码行数:18,代码来源:StandingsController.cs

示例10: Get

        public IHttpActionResult Get(Guid tournamentKey, string playerName)
        {
            using(var dataContext = new DataContext())
            {
                var player = dataContext
                    .GetTournament(tournamentKey)
                    .GetPlayer(playerName);

                if(player == null)
                    return NotFound();

                return Ok(PlayerResponseProvider.Create(player));
            }
        }
开发者ID:Jaecen,项目名称:Peregrine,代码行数:14,代码来源:PlayerController.cs

示例11: Put

        public IHttpActionResult Put(Guid tournamentKey, string playerName)
        {
            using(var dataContext = new DataContext())
            {
                var tournament = dataContext
                    .GetTournament(tournamentKey);

                if(tournament == null)
                    return NotFound();

                var tournamentHasResults = tournament
                    .Rounds
                    .Where(round => round
                        .Matches
                        .Any()
                    )
                    .Any();

                if(tournamentHasResults)
                    return StatusCode(System.Net.HttpStatusCode.MethodNotAllowed);

                var player = tournament
                    .GetPlayer(playerName);

                if(player != null)
                    return Conflict();

                player = dataContext
                    .Players
                    .Add(new Player
                    {
                        Name = playerName,
                        Dropped = false,
                    });

                tournament.Players.Add(player);

                dataContext.SaveChanges();

                return CreatedAtRoute(
                        "player-get",
                        new { tournamentKey = tournament.Key, playerName = player.Name },
                        PlayerResponseProvider.Create(player)
                    );
            }
        }
开发者ID:Jaecen,项目名称:Peregrine,代码行数:46,代码来源:PlayerController.cs

示例12: Put

        public IHttpActionResult Put(Guid tournamentKey, int roundNumber, string playerName, string result, int count)
        {
            using(var dataContext = new DataContext())
            {
                var tournament = dataContext
                    .GetTournament(tournamentKey);

                if(tournament == null)
                    return NotFound();

                var player = tournament
                    .GetPlayer(playerName);

                if(player == null)
                    return NotFound();

                Player winningPlayer;
                if(result == "wins")
                    winningPlayer = player;
                else if(result == "draws")
                    winningPlayer = null;
                else
                    return BadRequest("result must be either 'wins' or 'draws'");

                if(roundNumber > RoundManager.GetMaxRoundsForTournament(tournament))
                    return NotFound();

                var roundState = RoundManager.GetRoundState(tournament, roundNumber);
                if(roundState == RoundState.Invalid)
                    return NotFound();

                // Can't add results to finalized rounds
                if(roundState >= RoundState.Final)
                    return StatusCode(System.Net.HttpStatusCode.MethodNotAllowed);

                var round = tournament
                    .GetRound(roundNumber)
                    ?? new Round
                    {
                        Number = roundNumber,
                        Matches = RoundManager.CreateMatches(tournament, roundNumber)
                    };

                if(roundState == RoundState.Projected)
                {
                    // Add the new round to the tournament.
                    tournament.Rounds.Add(round);
                }

                // Committed and Completed rounds accept new results.
                // Find the match for this player
                var match = round
                    .GetMatch(player);

                if(match == null)
                    return NotFound();

                // Can't change results of byes
                if(match.Players.Count() == 1)
                    return StatusCode(System.Net.HttpStatusCode.MethodNotAllowed);

                // Clear all the winning games for this player
                // Null for winner means a draw
                var existingGames = match
                    .Games
                    .Where(game => game.Winner == winningPlayer)
                    .ToArray();

                foreach(var game in existingGames)
                    match.Games.Remove(game);

                // Add new winning games
                for(int wins = 0; wins < count; wins++)
                    match
                        .Games
                        .Add(new Game
                        {
                            Winner = winningPlayer,
                        });

                dataContext.SaveChanges();

                return Ok(RoundResponseProvider.Create(tournament, round));
            }
        }
开发者ID:Jaecen,项目名称:Peregrine,代码行数:85,代码来源:MatchResultController.cs


注:本文中的DataContext.GetTournament方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。