Esempio n. 1
0
        public static Guid?BeginMatch(List <Guid> intellects, Guid userID, string title, Guid stageId = new Guid())
        {
            Guid gameID = Guid.NewGuid();
            Game match  = Game.CreateGame(gameID, userID, DateTime.UtcNow, title);

            var teamInfo = new List <TeamInfo>
            {
                // system command
                //new TeamInfo()
                //  {
                //    TeamId = Guid.Empty
                //  }
            };

            //db.AddToTeams(Team.CreateTeam(Guid.Empty, gameID));
            foreach (Guid id in intellects)
            {
                Team team             = Team.CreateTeam(Guid.NewGuid(), gameID);
                var  currentIntellect = (from i in db.Intellect
                                         where i.Intellect_ID == id
                                         select i).FirstOrDefault <Intellect>();
                team.Intellects.Add(currentIntellect);
                db.AddToTeams(team);
                match.Teams.Add(team);
                teamInfo.Add(new TeamInfo()
                {
                    TeamId  = team.Team_ID,
                    Members = new List <Guid>()
                    {
                        id
                    }
                });
            }

            if (stageId != Guid.Empty)
            {
                match.Stage = db.Stages.First(x => x.Stage_ID == stageId);
            }

            db.AddToGame(match);

            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                return(null);
            }

            PutMessage(new Message(gameID, teamInfo));

            return(gameID);
        }