//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.
        foreach (ObjectTableRow objRow in partyTable.ObjectRows)
        {
            //Only care about PartyMembers
            if (objRow.Obj.GetType() == typeof(PartyMember))
            {
                PartyMember partyMember = (PartyMember)objRow.Obj;
                if (partyMember.UserID == (int)Session["userID"])
                {
                    partyMembersTable.updatePartyMember(partyMember);                                               //update partyMember
                }
            }
        }

        //Save to savedContent w/ new IDs
        Session["savedContent"] = party;

        angryLabel.ForeColor = Color.Green;
        angryLabel.Text      = "Character(s) saved!";
    }
Example #2
0
    //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");
    }