private async void CheckOut_Click(object sender, RoutedEventArgs e)
{
Notice.Foreground = new SolidColorBrush(Windows.UI.Colors.Black);
Notice.Text = "Attempting check out...";
Dictionary<string, string> checkout = new Dictionary<string, string>();
checkout["isbn"] = ISBN.Text;
checkout["patron_barcode"] = Patron.Password;
checkout["distributor_barcode"] = Distributor.Password;
string json = JsonConvert.SerializeObject(checkout);
try {
HttpClient client = new HttpClient();
StringContent theContent = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
HttpResponseMessage aResponse = await client.PostAsync(new Uri("http://alexandria.ad.sofse.org/checkouts.json"), theContent);
string content = await aResponse.Content.ReadAsStringAsync();
ISBN.Text = "";
Patron.Password = "";
Distributor.Password = "";
if ((int)aResponse.StatusCode == 201)
{
Dictionary<string, string> dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(content);
Notice.Foreground = new SolidColorBrush(Windows.UI.Colors.ForestGreen);
Notice.Text = "You succesfully checked out " + dictionary["title"] + "!";
}
else
{
Dictionary<string, List<string>> dictionary = JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(content);
string notice = "";
foreach (var item in dictionary)
{
foreach (var error in item.Value)
{
notice += error + "\n";
}
}
Notice.Foreground = new SolidColorBrush(Windows.UI.Colors.Red);
Notice.Text = notice;
}
}
catch (HttpRequestException)
{
Notice.Foreground = new SolidColorBrush(Windows.UI.Colors.Red);
Notice.Text = "You might want to consider connecting to the internet...";
return;
}
}
}