本文整理汇总了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));
}
}
示例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);
}
}
示例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);
}
}
示例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));
}
}
示例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")
});
}
}
}
示例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);
}
}
示例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));
}
}
示例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));
}
}
示例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));
}
}
示例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));
}
}
示例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)
);
}
}
示例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));
}
}