private List <StudioPresentation> GetPresentationListStudio(List <Studio> studioList) { List <StudioPresentation> returnList = new List <StudioPresentation>(); foreach (var studio in studioList) { StudioPresentation presentData = new StudioPresentation { Id = studio.Id, Name = studio.Name }; returnList.Add(presentData); } return(returnList); }
public async System.Threading.Tasks.Task UppdateGame() { try { HttpClient client = new HttpClient(); DeveloperPresentation selectedDeveloper = (DeveloperPresentation)cmbDeveloper.SelectedItem; Developer gameDeveloper = new Developer { Id = selectedDeveloper.Id, Name = selectedDeveloper.Name, Role = selectedDeveloper.Role }; Publisher selectedPublisher = (Publisher)cmbPublisher.SelectedItem; StudioPresentation selectedStudio = (StudioPresentation)cmbStudio.SelectedItem; Studio gameStudio = new Studio { Id = selectedStudio.Id, Name = selectedStudio.Name }; Game updatedGame = (Game)cmbGames.SelectedItem; updatedGame.Name = txtName.Text; updatedGame.Gener = txtGener.Text; updatedGame.NumberOfPlayers = int.Parse(txtNumPlayers.Text); updatedGame.Publisher.Id = selectedPublisher.Id; updatedGame.Studio = new List <Studio>(); updatedGame.Studio.Add(gameStudio); updatedGame.Developer = new List <Developer>(); updatedGame.Developer.Add(gameDeveloper); string jsonString = JsonConvert.SerializeObject(updatedGame); var content = new StringContent(jsonString, Encoding.UTF8, "application/json"); string URL = BASE_URL + "Games/" + updatedGame.Id; var response = await client.PutAsync(URL, content); var responseString = await response.Content.ReadAsStringAsync(); System.Diagnostics.Debug.WriteLine(responseString); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } }