/// <summary> /// Sends out invites to the affected users. Returns the Guid of the resulting game session. /// </summary> /// <param name="invitingUser"></param> /// <param name="otherUser1"></param> /// <param name="otherUser2"></param> /// <param name="otherUser3"></param> /// <param name="otherUser4"></param> /// <returns></returns> public Game StartGame(User invitingUser, string otherUser1, string otherUser2, string otherUser3, string otherUser4) { Game gameSession = CreateGame(); //GetUserByUserName will except if a user is not found, so we can just add users to a list without checking. UserList otherUsers = new UserList(); otherUsers.Add(GetUserByUserName(otherUser1)); otherUsers.Add(GetUserByUserName(otherUser2)); otherUsers.Add(GetUserByUserName(otherUser3)); otherUsers.Add(GetUserByUserName(otherUser4)); //Create invitations for all the other users. foreach (User user in otherUsers) { Invite invite = CreateGameInvite(invitingUser, gameSession, user); SendGameInvite(invite); } //Add yourself as an invited user and set Status to accepted from the start. Invite selfInvite = CreateGameInvite(invitingUser, gameSession, invitingUser); DB_Invite.FromInvite(selfInvite, _context); AcceptGameInvite(invitingUser, selfInvite.Id.Value); return(gameSession); }
/// <summary> /// Creates a GameInvite in the database from one user to another. /// </summary> /// <param name="invitingUser"></param> /// <param name="gameSession"></param> /// <param name="user"></param> /// <returns></returns> public Invite CreateGameInvite(User invitingUser, Game game, User user) { DB_Invite da_invite = DB_Invite.FromInvite(new Invite() { Id = Guid.NewGuid(), InvitedUser = user.Id.Value, InvitingUser = invitingUser.Id.Value, Status = (int)DB_Invite.InviteStatus.Pending, GameId = game.Id.Value }, _context); return(da_invite.ToInvite()); }