protected override async void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); //TODO : Read fileuserclass and store the member ID related info in a new object. // GET member_payments string response_memberpayment = await APILibrary.apiCall((string)ApplicationData.Current.LocalSettings.Values["Tokens"], "https://api.teamsnap.com/v3/member_payments/search?team_id=" + ApplicationData.Current.LocalSettings.Values["currentTeamID"].ToString()); // Deserialize it rMemberPaymentAPI = MemberPaymentAPI.teamMediaDataDeserializer(response_memberpayment); //GET all team_fees for the current team string response_teamfee = await APILibrary.apiCall((string)ApplicationData.Current.LocalSettings.Values["Tokens"], "https://api.teamsnap.com/v3/team_fees/search?team_id=" + ApplicationData.Current.LocalSettings.Values["currentTeamID"].ToString()); rteamFeeAPI = TeamFeeAPI.teamMediaDataDeserializer(response_teamfee); if (rteamFeeAPI.collection.items == null) { NoPaymentsGrid.Visibility = Visibility.Visible; ListViewGrid.Visibility = Visibility.Collapsed; CurrentListViewTitleGrid.Visibility = Visibility.Collapsed; } else { NoPaymentsGrid.Visibility = Visibility.Collapsed; ListViewGrid.Visibility = Visibility.Visible; CurrentListViewTitleGrid.Visibility = Visibility.Visible; rpayment = await PaymentCollection.createPaymentCollection(rteamFeeAPI, rMemberPaymentAPI); rpaymentcollection.Clear(); foreach (var teamfee in rpayment.team_fees) { rpaymentcollection.Add(teamfee); } PaymentItemsListView.DataContext = this; Debug.WriteLine(rpayment.team_fees.Count); } //csvGrid.Children.Add(cvs); }
public PaymentsPage() { this.InitializeComponent(); APILibrary = new Library_APICall(); mlibrary = new methodLibrary(); rteamFeeAPI = new RootObjectTeamFeeAPI(); rMemberPaymentAPI = new RootObjectMemberPaymentAPI(); rpaymentcollection = new ObservableCollection<TeamFeeItems>(); rpayment = new RootPaymentCollection(); }
public static string teamMediatDataSerializer(RootObjectMemberPaymentAPI rteamMemberPaymentAPI) { string response = JsonConvert.SerializeObject(rteamMemberPaymentAPI); return response; }
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>(); Hashtable teamfeeId_ListPos = new Hashtable(); // 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*/ Hashtable memberid_ListPos = new Hashtable(); //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>(); Hashtable rteamfee_ht = new Hashtable(); // 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.Contains(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 Hashtable rteamMemberPayment_ht = new Hashtable(); 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.member_payment_id = (long)rteamMemberPayment.collection.items[i].data[(int)rteamMemberPayment_ht["id"]].value; 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; }
private async void SavePaymentItem_Click(object sender, RoutedEventArgs e) { PaymentItemsListView.IsEnabled = true; ShowList.IsEnabled = true; NewFeeButton.IsEnabled = true; AddNewPaymentItemGrid.Visibility = Visibility.Collapsed; string res = null; string teamid = (ApplicationData.Current.LocalSettings.Values["currentTeamID"]).ToString(); double amount = 0; if (!double.TryParse(FeeAmount.Text, out amount)) { // it's a valid integer => you could use the distance variable here } else { res = "{ \"template\":{ \"data\":[{\"name\":\"description\",\"value\":\"" + FeeDescription.Text + "\"}"; res += ",{\"name\":\"amount\",\"value\":\"" + FeeAmount.Text + "\"}"; res += ",{\"name\":\"notes\",\"value\":\"" + Notes.Text + "\"}"; res += ",{\"name\":\"team_id\",\"value\":" + teamid + "}"; res += ",{\"name\":\"type\",\"value\":\"team_fee\"}"; res += "]}}"; Debug.WriteLine(res); try { bool r = await APILibrary.apiPOST((string)ApplicationData.Current.LocalSettings.Values["Tokens"], res, "https://api.teamsnap.com/v3/team_fees"); } catch (Exception ex) { Debug.WriteLine(ex); } // GET member_payments string response_memberpayment = await APILibrary.apiCall((string)ApplicationData.Current.LocalSettings.Values["Tokens"], "https://api.teamsnap.com/v3/member_payments/search?team_id=" + ApplicationData.Current.LocalSettings.Values["currentTeamID"].ToString()); // Deserialize it rMemberPaymentAPI = MemberPaymentAPI.teamMediaDataDeserializer(response_memberpayment); //GET all team_fees for the current team string response_teamfee = await APILibrary.apiCall((string)ApplicationData.Current.LocalSettings.Values["Tokens"], "https://api.teamsnap.com/v3/team_fees/search?team_id=" + ApplicationData.Current.LocalSettings.Values["currentTeamID"].ToString()); rteamFeeAPI = TeamFeeAPI.teamMediaDataDeserializer(response_teamfee); if (rteamFeeAPI.collection.items == null) { NoPaymentsGrid.Visibility = Visibility.Visible; ListViewGrid.Visibility = Visibility.Collapsed; CurrentListViewTitleGrid.Visibility = Visibility.Collapsed; } else { NoPaymentsGrid.Visibility = Visibility.Collapsed; ListViewGrid.Visibility = Visibility.Visible; CurrentListViewTitleGrid.Visibility = Visibility.Visible; rpayment = await PaymentCollection.createPaymentCollection(rteamFeeAPI, rMemberPaymentAPI); rpaymentcollection.Clear(); foreach (var teamfee in rpayment.team_fees) { rpaymentcollection.Add(teamfee); } PaymentItemsListView.DataContext = this; Debug.WriteLine(rpayment.team_fees.Count); } } }