public static string teamMediaGrouptDataSerializer(RootObjectTeamMediaGroup rteamMediaGroup) { string response = JsonConvert.SerializeObject(rteamMediaGroup); return response; }
public async Task<bool> updateTeamMediaCollection(RootObjectTeamMediaGroup rteamMediaGroup) { RootMediaFolder rmediafolder_old = new RootMediaFolder(); Hashtable rmediafolder_folderht = new Hashtable(); if (await methodLibrary.checkIfFileExists("teamFileandMediaFolder")) { //rmediafolder_old = new RootMediaFolder(); string res = await mLibrary.readFile("teamFileandMediaFolder"); rmediafolder_old = TeamMediaGroupClass.mediaFolderDataDeserializer(res); for (int i = 0; i < rmediafolder_old.photoCollection.Count; i++) { rmediafolder_folderht.Add(rmediafolder_old.photoCollection[i].folder_id, i); } } Hashtable rteamMediaGroup_ht = new Hashtable(); RootMediaFolder rmediafolder = new RootMediaFolder(); rmediafolder.photoCollection = new List<PhotoCollectionFolder>(); photoCollectionFolder.Clear(); for (int i = 0; i < rteamMediaGroup.collection.items[0].data.Count; i++) { rteamMediaGroup_ht.Add(rteamMediaGroup.collection.items[0].data[i].name, i); } for (int i = 0; i < rteamMediaGroup.collection.items.Count; i++) { PhotoCollectionFolder rphotofolder = new PhotoCollectionFolder(); rphotofolder.folder_id = rteamMediaGroup.collection.items[i].data[(int)rteamMediaGroup_ht["id"]].value == null ? 0 : (long)rteamMediaGroup.collection.items[i].data[(int)rteamMediaGroup_ht["id"]].value; rphotofolder.nameOfFolder = String.IsNullOrEmpty((string)rteamMediaGroup.collection.items[i].data[(int)rteamMediaGroup_ht["name"]].value) ? "New Folder" : (string)rteamMediaGroup.collection.items[i].data[(int)rteamMediaGroup_ht["name"]].value; rphotofolder.numOfPhotos = rteamMediaGroup.collection.items[i].data[(int)rteamMediaGroup_ht["count_team_media"]].value == null ? 0 : (long)rteamMediaGroup.collection.items[i].data[(int)rteamMediaGroup_ht["count_team_media"]].value; rphotofolder.position = rteamMediaGroup.collection.items[i].data[(int)rteamMediaGroup_ht["position"]].value == null ? 0 : (long)rteamMediaGroup.collection.items[i].data[(int)rteamMediaGroup_ht["position"]].value; rphotofolder.media_format = String.IsNullOrEmpty((string)rteamMediaGroup.collection.items[i].data[(int)rteamMediaGroup_ht["media_format"]].value) ? "image" : (string)rteamMediaGroup.collection.items[i].data[(int)rteamMediaGroup_ht["media_format"]].value; DateTime updated_at = rteamMediaGroup.collection.items[i].data[(int)rteamMediaGroup_ht["updated_at"]].value == null ? DateTime.MinValue : (DateTime)rteamMediaGroup.collection.items[i].data[(int)rteamMediaGroup_ht["updated_at"]].value; updated_at = updated_at.ToLocalTime(); //if (rmediafolder_old.photoCollection != null) //{ // if (rmediafolder_folderht.ContainsKey(rphotofolder.folder_id)) // { // rphotofolder.photos = rmediafolder_old.photoCollection[(int)rmediafolder_folderht[rphotofolder.folder_id]].photos; // } //} rphotofolder.updatedat = updated_at; for (int j = 0; j < rteamMediaGroup.collection.items[i].links.Count; j++) { if (String.Equals("team_media", rteamMediaGroup.collection.items[i].links[j].rel)) { rphotofolder.photosAPI = rteamMediaGroup.collection.items[i].links[j].href; } } if (rphotofolder.media_format == "image") { photoCollectionFolder.Add(rphotofolder); } rmediafolder.photoCollection.Add(rphotofolder); } rteamMediaGroup_ht.Clear(); string serializedMediaFolder = TeamMediaGroupClass.mediaFolderDataSerializer(rmediafolder); await mLibrary.writeFile("teamFileandMediaFolder", serializedMediaFolder); return true; }