public static async Task<ObservableCollection<MemberItemTrackingStatus>> getTrackingItemStatus(long trackingitemid) { ObservableCollection<MemberItemTrackingStatus> ritemstatuscollection = new ObservableCollection<MemberItemTrackingStatus>(); methodLibrary mlb = new methodLibrary(); string userclass = await mlb.readSerializedUserClass(); RootObjectUsers rusers = new RootObjectUsers(); rusers = Users.usersDataDeserializer(userclass); Library_APICall apiLibrary = new Library_APICall(); string resp = await apiLibrary.apiCall((string)ApplicationData.Current.LocalSettings.Values["Tokens"], "https://api.teamsnap.com/v3/tracked_item_statuses/search?tracked_item_id=" + trackingitemid); RootObjectTrackingItemStatus ritemstatus = trackingStatusDataDeserializer(resp); Dictionary<string, int> rstatus_items_data_ht = new Dictionary<string, int>(); for (int i = 0; i < ritemstatus.collection.items[0].data.Count; i++) { if (!rstatus_items_data_ht.ContainsKey(ritemstatus.collection.items[0].data[i].name)) { rstatus_items_data_ht.Add(ritemstatus.collection.items[0].data[i].name, i); } } ritemstatuscollection.Clear(); for (int i = 0; i < ritemstatus.collection.items.Count; i++) { MemberItemTrackingStatus robj = new MemberItemTrackingStatus(); robj.object_id = ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["id"]].value == null ? 0 : (long)ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["id"]].value; robj.trackingitemid = ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["tracked_item_id"]].value == null ? 0 : (long)ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["tracked_item_id"]].value; robj.status = ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["status"]].value == null ? "" : (string)ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["status"]].value; robj.member_id = ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["member_id"]].value == null ? 0 : (long)ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["member_id"]].value; robj.status_code = ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["status_code"]].value == null ? 0 : (long)ritemstatus.collection.items[i].data[(int)rstatus_items_data_ht["status_code"]].value; CollectionUsersTeamMembers rmember = new CollectionUsersTeamMembers(); rmember = mlb.getMemberInfoFromFile(rusers, robj.member_id); robj.member_name = rmember.fullname; ritemstatuscollection.Add(robj); } return ritemstatuscollection; }
public async Task<bool> getUserCollection(ObservableCollection<CollectionUsersTeam> teamData) { try { libMethods = new methodLibrary(); //await libMethods.writeToLogFile((DateTime.UtcNow).ToString() + ": in getUserCollection method"); string resp = await libMethods.readSerializedUserClass(); var rootuser = usersDataDeserializer(resp); var teamsobject = rootuser.teams; teamData.Clear(); foreach (var teams in teamsobject) { teamData.Add(teams); } } catch (Exception ex) { var tc = new TelemetryClient(); tc.TrackEvent("getUserCollection Exception : " + ex); //await libMethods.writeToLogFile((DateTime.UtcNow).ToString() + ": Exception in getUserCollection"); return false; } return true; }
public static async Task<ObservableCollection<Comments>> createCollection(string response) { methodLibrary mlb = new methodLibrary(); string userclass = await mlb.readSerializedUserClass(); RootObjectUsers rusers = Users.usersDataDeserializer(userclass); ObservableCollection<Comments> rphotocomments = new ObservableCollection<Comments>(); try { RootObjectMediaComments rmediacom = mediaCommentsDataDeserializer(response); if (rmediacom.collection.items != null) { Dictionary<string, int> rmediacom_itemdata_ht = new Dictionary<string, int>(); for (int i = 0; i < rmediacom.collection.items[0].data.Count; i++) { if (!rmediacom_itemdata_ht.ContainsKey(rmediacom.collection.items[0].data[i].name)) { rmediacom_itemdata_ht.Add(rmediacom.collection.items[0].data[i].name, i); } } for (int i = 0; i < rmediacom.collection.items.Count; i++) { Comments cm = new Comments(); CollectionUsersTeamMembers rmembers = new CollectionUsersTeamMembers(); cm.comment = (string)rmediacom.collection.items[i].data[(int)rmediacom_itemdata_ht["comment"]].value; cm.memberid = rmediacom.collection.items[i].data[(int)rmediacom_itemdata_ht["member_id"]].value == null ? 0 : (long)rmediacom.collection.items[i].data[(int)rmediacom_itemdata_ht["member_id"]].value; cm.mediaid = rmediacom.collection.items[i].data[(int)rmediacom_itemdata_ht["team_medium_id"]].value == null ? 0 : (long)rmediacom.collection.items[i].data[(int)rmediacom_itemdata_ht["team_medium_id"]].value; rmembers = mlb.getMemberInfoFromFile(rusers, cm.memberid); cm.membername = rmembers.first_name + " " + rmembers.last_name; cm.memberphoto = rmembers.member_thumbnail_uri; DateTime lastupdatetime = rmediacom.collection.items[i].data[(int)rmediacom_itemdata_ht["updated_at"]].value == null ? DateTime.MinValue : (DateTime)rmediacom.collection.items[i].data[(int)rmediacom_itemdata_ht["updated_at"]].value; if (lastupdatetime.CompareTo(DateTime.MinValue) > 0) { if (lastupdatetime.CompareTo(DateTime.UtcNow.AddDays(-1)) > 0) { TimeSpan ts = DateTime.Now.Subtract(lastupdatetime); if (ts.Hours == 0) { if (ts.Minutes == 0) { cm.lastupdatedat = "A few seconds ago"; } else if (ts.Minutes < 5 && ts.Minutes > 0) { cm.lastupdatedat = "A few min ago"; } else { cm.lastupdatedat = ts.Minutes + " min ago"; } } else { if (ts.Hours == 1) { cm.lastupdatedat = "An hour ago"; } else { cm.lastupdatedat = ts.Hours + " hours ago"; } } } else { DateTime localtime = lastupdatetime.ToLocalTime(); cm.lastupdatedat = String.Format("{0:ddd, MMM dd, yyyy}", localtime); } } rphotocomments.Add(cm); } } } catch (Exception ex) { } return rphotocomments; }
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; }