public PaymentItemDetails()
 {
     this.InitializeComponent();
     APILibrary = new Library_APICall();
     rteamfee = new TeamFeeItems();
     selectedTeamMember = new Team_Member();
     rteammember_collection = new ObservableCollection<Team_Member>();
     selectedTeamMemberPosInList = 0;
 }
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     base.OnNavigatedTo(e);
     rteamfee = (TeamFeeItems)e.Parameter;
     rteammember_collection.Clear();
     foreach (var member in rteamfee.team_member)
     {
         rteammember_collection.Add(member);
     }
     PaymentItemTitle.Text = rteamfee.team_fee_description;
     PaymentItemAmount.Text = rteamfee.team_fee_balance;
     PaymentItemMembersListView.DataContext = this;
 }
        public static async Task<RootPaymentCollection> createPaymentCollection(RootObjectTeamFeeAPI rteamFee, RootObjectMemberPaymentAPI rteamMemberPayment)
        {
            Library_APICall APILibrary = new Library_APICall();
            RootPaymentCollection rpayment = new RootPaymentCollection();
            methodLibrary mlb = new methodLibrary();
            List<CollectionUsersTeamMembers> ctrmList = new List<CollectionUsersTeamMembers>();
            Dictionary<long, int> teamfeeId_ListPos = new Dictionary<long, int>();  // Keeps track of position of each team id in the team_fees list.
            /*Extracting the list of members for the current team from FileUserClass.txt*/
            Dictionary<long, int> memberid_ListPos = new Dictionary<long, int>();  //Keeps track of the position in list based on the member id. Will be useful later.            
            string fileuserclass = await mlb.readSerializedUserClass();
            RootObjectUsers ruser = Users.usersDataDeserializer(fileuserclass);
            for (int i = 0; i < ruser.teams.Count; i++)
            {
                if (ruser.teams[i].id == (long)ApplicationData.Current.LocalSettings.Values["currentTeamID"])
                {
                    for (int j = 0; j < ruser.teams[i].members.Count; j++)
                    {
                        CollectionUsersTeamMembers ctm = new CollectionUsersTeamMembers();
                        ctm = ruser.teams[i].members[j];
                        ctrmList.Add(ctm);                                                                  // Keep in mind that all this stuff is being done for just one team. A single team will have all unique member_ids
                        if (ctrmList.Count > 0)
                        {
                            memberid_ListPos.Add(ruser.teams[i].members[j].member_id, ctrmList.Count - 1);
                        }
                    }
                }
            }
            /****************************/

            /*Working on the TeamFee */
            rpayment.team_fees = new List<TeamFeeItems>();
            Dictionary<string, int> rteamfee_ht = new Dictionary<string, int>();    // Adding the data items to a hashtable so that I can compare and add stuff to the right place
            for (int i = 0; i < rteamFee.collection.items[0].data.Count; i++)
            {
                rteamfee_ht.Add(rteamFee.collection.items[0].data[i].name, i);
            }

            // Run through array of items and add it to and object of type TeamFeeItems
            for (int i = 0; i < rteamFee.collection.items.Count; i++)
            {
                TeamFeeItems rtfitems = new TeamFeeItems();
                rtfitems.team_fee_id = rteamFee.collection.items[i].data[(int)rteamfee_ht["id"]].value == null ? 0 : (long)rteamFee.collection.items[i].data[(int)rteamfee_ht["id"]].value;
                if (!teamfeeId_ListPos.ContainsKey(rtfitems.team_fee_id))
                {
                    teamfeeId_ListPos.Add(rtfitems.team_fee_id, i);
                }
                rtfitems.team_fee_description = (string)rteamFee.collection.items[i].data[(int)rteamfee_ht["description"]].value;
                rtfitems.team_fee_amount = (string)rteamFee.collection.items[i].data[(int)rteamfee_ht["amount"]].value;
                rtfitems.team_fee_notes = (string)rteamFee.collection.items[i].data[(int)rteamfee_ht["notes"]].value;
                rtfitems.team_fee_balance = (string)rteamFee.collection.items[i].data[(int)rteamfee_ht["balance"]].value;
                rtfitems.team_member = new List<Team_Member>();
                rpayment.team_fees.Add(rtfitems);
            }


            /*************************/
            /*Working on member payments now*/
            //Run through memberPayments and for each matching team_fee_id, add the data to rpayment.team_fees[i].team_member

            Dictionary<string, int> rteamMemberPayment_ht = new Dictionary<string, int>();
            for (int i = 0; i < rteamMemberPayment.collection.items[0].data.Count; i++)
            {
                rteamMemberPayment_ht.Add(rteamMemberPayment.collection.items[0].data[i].name, i);
            }

            for (int i = 0; i < rteamMemberPayment.collection.items.Count; i++)
            {
                // read the team_fee_id
                long member_team_fee_id = (long)rteamMemberPayment.collection.items[i].data[(int)rteamMemberPayment_ht["team_fee_id"]].value;
                // check if it matches an existing team_fee_id in teamfeeId_ListPos
                if (teamfeeId_ListPos.ContainsKey(member_team_fee_id))
                {
                    TeamFeeItems rtfitems = new TeamFeeItems();
                    rtfitems = rpayment.team_fees[(int)teamfeeId_ListPos[member_team_fee_id]];
                    Team_Member rteammember = new Team_Member();
                    rteammember.tickmark = new TeamMemberTickMarkVisibility();
                    rteammember.team_fee_id = member_team_fee_id;
                    rteammember.team_id = (long)rteamMemberPayment.collection.items[i].data[(int)rteamMemberPayment_ht["team_id"]].value;
                    rteammember.amount_paid = (string)rteamMemberPayment.collection.items[i].data[(int)rteamMemberPayment_ht["amount_paid"]].value;
                    rteammember.amount_due = (string)rteamMemberPayment.collection.items[i].data[(int)rteamMemberPayment_ht["amount_due"]].value;
                    rteammember.is_applicable = rteamMemberPayment.collection.items[i].data[(int)rteamMemberPayment_ht["is_applicable"]].value == null ? false : (bool)rteamMemberPayment.collection.items[i].data[(int)rteamMemberPayment_ht["is_applicable"]].value;
                    rteammember.member_id = (long)rteamMemberPayment.collection.items[i].data[(int)rteamMemberPayment_ht["member_id"]].value;
                    rteammember.tickmark.is_applicable = rteammember.is_applicable;
                    rteammember.tickmark.amount_due = rteammember.amount_due;
                    //Check if memberid_ListPos contains this team_fee_member_id. If it does, fetch member info from there
                    long team_fee_member_id = (long)rteamMemberPayment.collection.items[i].data[(int)rteamMemberPayment_ht["member_id"]].value;
                    if (memberid_ListPos.ContainsKey(team_fee_member_id))
                    {
                        int pos = (int)memberid_ListPos[team_fee_member_id];
                        rteammember.member_name = ctrmList[pos].first_name + (String.IsNullOrEmpty(ctrmList[pos].last_name) ? "" : " " + ctrmList[pos].last_name);
                        rteammember.member_photo = ctrmList[pos].member_photo;
                        rteammember.member_photo = ctrmList[pos].member_photo_notscaled;
                        rteammember.email_address = ctrmList[pos].email_address;
                        rteammember.is_non_player = ctrmList[pos].is_non_player;
                    }
                    rpayment.team_fees[(int)teamfeeId_ListPos[member_team_fee_id]].team_member.Add(rteammember);  // Adding rteammember under the right TeamFeeItems
                }
            }
            return rpayment;
        }