//Quits the game on behalf of the player protected void leaveGameButton_Click(object sender, EventArgs e) { PartyMembersTable partyMembersTable = new PartyMembersTable(new DatabaseConnection()); UsersTable userTable = new UsersTable(new DatabaseConnection()); foreach (PartyMember pc in party.PartyMembers.Keys) { if (pc.UserID == (int)Session["userID"]) { partyMembersTable.deletePartyMember(pc); } } userTable.deleteUserPlayerGame((int)Session["userID"], game.GameID); Session.Remove("savedContent"); Session.Remove("activeGame"); //Load Home page and eat cookie so no error from controls not existing this.Page.Session.Remove("gameLinkID"); this.Page.Session.Remove("gameCategoryID"); this.Page.Session.Remove("gamePanelID"); this.Page.Session.Remove("gameTypePanelID"); this.Page.Session.Remove("page"); Response.Redirect("~/Home"); }
//Saves changes to the party protected void saveButton_Click(object sender, EventArgs e) { PartyMembersTable partyMembersTable = new PartyMembersTable(new DatabaseConnection()); partyTable.saveContentChanges(); party.PartyMembers = partyTable.getContent(); Session["savedContent"] = party; //Foreach tableRow if its a monster, do the applicable database command (update/insert/delete) to mirror what the user has done in the table. Dictionary <int, int> userChoppingBlock = new Dictionary <int, int>(); foreach (ObjectTableRow objRow in partyTable.ObjectRows) { //Only care about PartyMembers if (objRow.Obj.GetType() == typeof(PartyMember)) { PartyMember partyMember = (PartyMember)objRow.Obj; //Add to character count of users if (partyMember.UserID != 0 && userChoppingBlock.ContainsKey(partyMember.UserID)) { userChoppingBlock[partyMember.UserID]++; } else if (partyMember.UserID != 0) { userChoppingBlock.Add(partyMember.UserID, 1); } if (objRow.Visible == false) //delete partyMember { if (partyMember.PartyMemberID != 0) //Remove from database { partyMembersTable.deletePartyMember(partyMember); //if is owned by a user, subtract from counter so we can see later if they should still have access to the game if (partyMember.UserID != 0) { userChoppingBlock[partyMember.UserID]--; } } party.PartyMembers.Remove(partyMember); } else if (objRow.Visible == true && partyMember.PartyMemberID != 0) { partyMembersTable.updatePartyMember(partyMember); //update partyMember } else if (objRow.Visible == true && partyMember.PartyMemberID == 0) //create partyMember { partyMember.GameID = game.GameID; int partyMemberID = partyMembersTable.insertPartyMember(partyMember); if (partyMemberID > 0) { partyMember.PartyMemberID = partyMemberID; } partyMember.EntityID = partyMembersTable.getPartyMemberEntityID(partyMember.PartyMemberID); } } } //Remove users who should no longer have access because they have no characters UsersTable userTable = new UsersTable(new DatabaseConnection()); foreach (KeyValuePair <int, int> user in userChoppingBlock) { if (user.Value <= 0) { userTable.deleteUserPlayerGame(user.Key, game.GameID); } } //Save to savedContent w/ new IDs Session["savedContent"] = party; Session["message"] = new Message("Party Saved!", System.Drawing.Color.Green); //Reload page to clear any nonsense before loading Response.Redirect("GamePartyGM"); }