예제 #1
0
        public async Task<CollectionUsersTeamMembers> updateMemberContacts(long member_id, CollectionUsersTeamMembers teammembers)
        {
            RootObjectMemberContacts rmemcontacts = new RootObjectMemberContacts();
            string family_contacts_res = await LibraryAPI.apiCall((string)ApplicationData.Current.LocalSettings.Values["Tokens"], "https://api.teamsnap.com/v3/contacts/search?member_id=" + member_id.ToString());
            rmemcontacts = MemberContacts.membercontactsDataDeserializer(family_contacts_res);
            try
            {
                //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + (rmemcontacts.collection.items == null ? ": No items in rmemcontacts" : ": rmemcontact has " + rmemcontacts.collection.items.Count + " values"), false);
                if (rmemcontacts.collection.items != null)
                {
                    //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Inside if (rmemcontacts.collection.items != null)", false);
                    teammembers.family_members = new List<FamilyMemberContacts>();

                    string family_contacts_phone_res = null;
                    Debug.WriteLine("filename family_contacts_phone_res : " + "family_contacts_phone_res" + teammembers.member_id);
                    string refreshclicked = (string)ApplicationData.Current.LocalSettings.Values["RefreshClicked"];
                    family_contacts_phone_res = await LibraryAPI.apiCall((string)ApplicationData.Current.LocalSettings.Values["Tokens"], "https://api.teamsnap.com/v3/contact_phone_numbers/search?member_id=" + (teammembers.member_id).ToString());


                    string family_contacts_email_res = await LibraryAPI.apiCall((string)ApplicationData.Current.LocalSettings.Values["Tokens"], "https://api.teamsnap.com/v3/contact_email_addresses/search?member_id=" + (teammembers.member_id).ToString()); ;

                    RootObjectContactPhone rcontactphone = new RootObjectContactPhone();
                    RootObjectContactEmailAddress rcontactemailaddress = new RootObjectContactEmailAddress();

                    rcontactemailaddress = MemberContactEmailAddress.contactEmailAddressDataDeserializer(family_contacts_email_res);
                    //Hashtable rcontactemail_items_ht = new Hashtable();

                    //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Finished deserializing Email API response", false);
                    rcontactphone = MemberContactsPhoneNumbers.contactPhoneDataDeserializer(family_contacts_phone_res);
                    //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Finished deserializing Phone API response", false);
                    Dictionary<string, int> rmemcontacts_ht = new Dictionary<string, int>();

                    //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Hashtable has been populated.", false);
                    for (int ind = 0; ind < rmemcontacts.collection.items.Count; ind++)
                    {
                        //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Creating Hashtable.", false);
                        for (int ind1 = 0; ind1 < rmemcontacts.collection.items[ind].data.Count; ind1++)
                        {
                            rmemcontacts_ht.Add(rmemcontacts.collection.items[ind].data[ind1].name, ind1);
                        }
                        FamilyMemberContacts rfammemcontacts = new FamilyMemberContacts();
                        rfammemcontacts.id = rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["id"]].value == null ? 0 : (long)rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["id"]].value;
                        rfammemcontacts.address_city = rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["address_city"]].value == null ? null : (string)rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["address_city"]].value;
                        //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": fetched address_city from TeamSnap.", false);
                        rfammemcontacts.address_country = rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["address_country"]].value == null ? null : (string)rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["address_country"]].value;
                        //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": fetched address_country from TeamSnap.", false);
                        rfammemcontacts.address_state = rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["address_state"]].value == null ? null : (string)rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["address_state"]].value;
                        // await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": fetched address_state from TeamSnap.", false);
                        rfammemcontacts.address_street1 = rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["address_street1"]].value == null ? null : (string)rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["address_street1"]].value;
                        //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": fetched address_street1 from TeamSnap.", false);
                        rfammemcontacts.address_street2 = rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["address_street2"]].value == null ? null : (string)rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["address_street2"]].value; ;
                        // await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": fetched address_street2 from TeamSnap.", false);
                        rfammemcontacts.address_zip = rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["address_zip"]].value == null ? null : (string)rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["address_zip"]].value;
                        //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": fetched address_zip from TeamSnap.", false);
                        rfammemcontacts.first_name = rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["first_name"]].value == null ? null : (string)rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["first_name"]].value;
                        //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": fetched first_name from TeamSnap.", false);
                        rfammemcontacts.label = rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["label"]].value == null ? null : (string)rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["label"]].value;
                        //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": fetched label from TeamSnap.", false);
                        rfammemcontacts.last_name = rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["last_name"]].value == null ? null : (string)rmemcontacts.collection.items[ind].data[(int)rmemcontacts_ht["last_name"]].value;
                        //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": fetched last_name from TeamSnap.", false);
                        rfammemcontacts.full_name = rfammemcontacts.first_name + " " + rfammemcontacts.last_name;
                        //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": fetched full_name from TeamSnap.", false);
                        rfammemcontacts.nameAndLabel = rfammemcontacts.full_name + " (" + rfammemcontacts.label + ")";
                        //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": fetched label from TeamSnap.", false);
                        //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + (rcontactphone.collection.items == null ? ": No items in rcontactphone" : ": rcontactphone has " + rcontactphone.collection.items.Count + " values"), false);
                        if (rcontactphone.collection.items != null)
                        {
                            //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + (rcontactphone.collection.items[ind] == null ? ": rcontactphone.collection.items[ind] is null" : ": rcontactphone.collection.items[ind] is not null"), false);
                            Dictionary<string, int> rfamcontactphone_ht = new Dictionary<string, int>();
                            rfammemcontacts.phonenum = new System.Collections.ObjectModel.ObservableCollection<FamilyMemberContactsPhones>();
                            for (int k = 0; k < rcontactphone.collection.items[0].data.Count; k++)
                            {
                                rfamcontactphone_ht.Add(rcontactphone.collection.items[0].data[k].name, k);
                            }
                            for (int k = 0; k < rcontactphone.collection.items.Count; k++)
                            {
                                Debug.WriteLine((int)rfamcontactphone_ht["contact_id"]);
                                Debug.WriteLine((long)rcontactphone.collection.items[k].data[(int)rfamcontactphone_ht["contact_id"]].value);
                                if ((long)rcontactphone.collection.items[k].data[(int)rfamcontactphone_ht["contact_id"]].value == rfammemcontacts.id)
                                {
                                    FamilyMemberContactsPhones rfamcontactphone = new FamilyMemberContactsPhones();
                                    rfamcontactphone.phone_number = rcontactphone.collection.items[k].data[(int)rfamcontactphone_ht["phone_number"]].value == null ? null : (string)rcontactphone.collection.items[k].data[(int)rfamcontactphone_ht["phone_number"]].value;
                                    rfammemcontacts.phonenum.Add(rfamcontactphone);
                                }
                            }
                            rfamcontactphone_ht.Clear();
                        }
                        //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + (rcontactemailaddress.collection.items == null ? ": No items in rcontactphone" : ": rcontactphone has " + rcontactemailaddress.collection.items.Count + " values"), false);
                        if (rcontactemailaddress.collection.items != null)
                        {
                            //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + (rcontactemailaddress.collection.items[ind] == null ? ": rcontactemailaddress.collection.items[ind] is null" : ": rcontactemailaddress.collection.items[ind] is not null"), false);
                            Dictionary<string, int> rfamcontactemail_ht = new Dictionary<string, int>();
                            rfammemcontacts.emailAdd = new System.Collections.ObjectModel.ObservableCollection<FamilyMemberContactsEmail>();
                            for (int k = 0; k < rcontactemailaddress.collection.items[0].data.Count; k++)
                            {
                                // if (rcontactemailaddress.collection.items[0].data[k].name != "sms_gateway_id")
                                //{
                                rfamcontactemail_ht.Add(rcontactemailaddress.collection.items[0].data[k].name, k);
                                //}
                            }
                            for (int k = 0; k < rcontactemailaddress.collection.items.Count; k++)
                            {
                                if ((long)rcontactemailaddress.collection.items[k].data[(int)rfamcontactemail_ht["contact_id"]].value == rfammemcontacts.id)
                                {
                                    FamilyMemberContactsEmail rfamcontactemail = new FamilyMemberContactsEmail();
                                    Debug.WriteLine((int)rfamcontactemail_ht["email"]);
                                    Debug.WriteLine((string)rcontactemailaddress.collection.items[k].data[(int)rfamcontactemail_ht["email"]].value);
                                    rfamcontactemail.email_address = rcontactemailaddress.collection.items[k].data[(int)rfamcontactemail_ht["email"]].value == null ? null : (string)rcontactemailaddress.collection.items[k].data[(int)rfamcontactemail_ht["email"]].value;
                                    rfammemcontacts.emailAdd.Add(rfamcontactemail);
                                }
                            }
                            rfamcontactemail_ht.Clear();
                        }
                        //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Addsing rfamemcontacts to teammebers.family_members.", false);
                        teammembers.family_members.Add(rfammemcontacts);
                        //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Clearing the hashtable.", false);
                        rmemcontacts_ht.Clear();
                    }
                }
            }
            catch (Exception ex)
            {
                //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": Exception in Calling Contacts, Contacts Phone and Contacts Email API " + ex, true);
            }
            //await mlb.writeToLogFile((DateTime.UtcNow).ToString() + ": ****Finished calling Contacts, Contacts Phone and Contacts Email API****", false);
            /*
            Family Member Information Section over
            */
            string emailres = await LibraryAPI.apiCall((string)ApplicationData.Current.LocalSettings.Values["Tokens"], "https://api.teamsnap.com/v3/member_email_addresses/search?member_id=" + teammembers.member_id);
            RootObjectMemberEmail rmemberemail = MemberEmail.memberemailDataDeserializer(emailres);
            if (rmemberemail.collection.items != null)
            {
                for (int emaili = 0; emaili < rmemberemail.collection.items[0].data.Count; emaili++)
                {
                    if (rmemberemail.collection.items[0].data[emaili].name == "email")
                    {
                        teammembers.email_address = (string)rmemberemail.collection.items[0].data[emaili].value;
                        Debug.WriteLine(teammembers.member_id);
                        break;
                    }
                }
            }
            else
            {
                teammembers.email_address = null;
            }
            string phoneres = await LibraryAPI.apiCall((string)ApplicationData.Current.LocalSettings.Values["Tokens"], "https://api.teamsnap.com/v3/member_phone_numbers/search?member_id=" + teammembers.member_id);
            RootObjectMemberPhone rmemberphone = MemberPhone.memberPhoneDataDeserializer(phoneres);
            if (rmemberphone.collection.items != null)
            {
                for (int phonei = 0; phonei < rmemberphone.collection.items[0].data.Count; phonei++)
                {
                    if (rmemberphone.collection.items[0].data[phonei].name == "phone_number")
                    {
                        //Debug.WriteLine(teammembers.first_name + " " + teammembers.last_name + " of team " + teamsCollection.name + " has a phone number : " + (string)rmemberphone.collection.items[0].data[phonei].value);
                        teammembers.phone_number = (string)rmemberphone.collection.items[0].data[phonei].value;
                        break;
                    }
                }
            }
            else
            {
                //Debug.WriteLine(teammembers.first_name + " " + teammembers.last_name + " of team " + teamsCollection.name + " doesn't have a phone number");
                teammembers.phone_number = null;
            }
            return teammembers;
        }
예제 #2
0
 public static string membercontactsDataSerializer(RootObjectMemberContacts rmembercontacts)
 {
     string response = JsonConvert.SerializeObject(rmembercontacts);
     return response;
 }