public ActionResult Create() { var game = new Game(); context.Insert(game); return RedirectToAction("Index", "Game", new { gameId = game.Id }); }
// Constructor with number of players. public GameViewModel(Game game, int playerCount) : this(game) { PlayerCapacity = playerCount; }
private void UpdateUserStatuses(Game game) { if (game.Observers != null) { foreach (var observer in game.Observers) { var user = context.Users.Find(observer.Id); user.Status = UserStatus.Observing; context.InsertOrUpdate(user, true); } } foreach (var player in game.Players) { player.User.Status = UserStatus.Playing; player.User.Games.Add(new GamePlayerStatus() { GameId = game.Id, UserId = player.User.Id, User = player.User, Status = GameStatus.InProgress }); context.InsertOrUpdate(player.User); } }
public GameViewModel(Game game) : this() { Id = game.Id; IsPrivate = game.IsPrivate; PlayerCapacity = game.PlayerCapacity; TimePlayed = game.TimePlayed.ToTotalHoursString(); Players = new List<PlayerViewModel>(); foreach (var player in game.Players) { Players.Add((PlayerViewModel)player.Player.GetViewModel()); } Observers = game.Observers.ToList(); }