dimanche 18 mai 2014

c# - consommation web api avec reste (get par id) - Stack Overflow


I am developping a windows 8.1 application that consumes services from asp.net. Here is my problem, I want to display a club by id (application for managing clubs) In my welcome page I have a list of clubs (logos) when I click into a logo I want to display all information about the club concerned. (the get all works fine)


Here is my method


private Club GetClubById(int id) 
{
HttpClient httpClient = new HttpClient();
string result = httpClient.GetStringAsync("http://xxxxxx:2209/api/clubapi/" + id).Result;
Club club = JsonConvert.DeserializeObject<Club>(result);
return club;
}





protected override void OnNavigatedTo(NavigationEventArgs e)
{
navigationHelper.OnNavigatedTo(e);

DefaultViewModel["ClubById"] = GetClubById(1003);
//this ID already exists I don t know how to bind the id with the xaml.
}

My class:


          public class Club
{
public int IDClub { get; set; }
public string ClubName { get; set; }

public string ClubMail { get; set; }
public string PhoneNumber { set; get; }
public byte[] Logo { get; set; }
}

this is my gridview in xaml:


<HubSection Width="500" Header="Clubs">

<DataTemplate>
<GridView ItemsSource="{Binding ListClubs}" SelectionMode="None" Tapped="GridView_Tapped" >


<GridView.ItemTemplate>

<DataTemplate>
<Grid>
<Image Source="{Binding Logo,Converter={StaticResource bytesToImageSourceConverter}}" Height="100" Width="200" Stretch="UniformToFill"/>
<TextBlock TextWrapping="NoWrap" Width="100" >
<Run Text="{Binding ClubName}" Foreground="Black" > </Run>
</TextBlock>

</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
</DataTemplate>
</HubSection>

Pleeeeease I need help


Thank you



I am developping a windows 8.1 application that consumes services from asp.net. Here is my problem, I want to display a club by id (application for managing clubs) In my welcome page I have a list of clubs (logos) when I click into a logo I want to display all information about the club concerned. (the get all works fine)


Here is my method


private Club GetClubById(int id) 
{
HttpClient httpClient = new HttpClient();
string result = httpClient.GetStringAsync("http://xxxxxx:2209/api/clubapi/" + id).Result;
Club club = JsonConvert.DeserializeObject<Club>(result);
return club;
}





protected override void OnNavigatedTo(NavigationEventArgs e)
{
navigationHelper.OnNavigatedTo(e);

DefaultViewModel["ClubById"] = GetClubById(1003);
//this ID already exists I don t know how to bind the id with the xaml.
}

My class:


          public class Club
{
public int IDClub { get; set; }
public string ClubName { get; set; }

public string ClubMail { get; set; }
public string PhoneNumber { set; get; }
public byte[] Logo { get; set; }
}

this is my gridview in xaml:


<HubSection Width="500" Header="Clubs">

<DataTemplate>
<GridView ItemsSource="{Binding ListClubs}" SelectionMode="None" Tapped="GridView_Tapped" >


<GridView.ItemTemplate>

<DataTemplate>
<Grid>
<Image Source="{Binding Logo,Converter={StaticResource bytesToImageSourceConverter}}" Height="100" Width="200" Stretch="UniformToFill"/>
<TextBlock TextWrapping="NoWrap" Width="100" >
<Run Text="{Binding ClubName}" Foreground="Black" > </Run>
</TextBlock>

</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
</DataTemplate>
</HubSection>

Pleeeeease I need help


Thank you


0 commentaires:

Enregistrer un commentaire