Merge branch 'vnext' of github.com:pazof/yavsc into vnext

vnext
Paul Schneider 8 years ago
commit 5a0c3f7f51
1 changed files with 24 additions and 3 deletions

@ -90,13 +90,17 @@ namespace BookAStar.Data
CurrentItem = item; CurrentItem = item;
return CurrentItem; return CurrentItem;
} }
private Uri GetUri(K key)
{
return new Uri(controllerUri.AbsoluteUri + "/" + key.ToString());
}
public async Task<V> RemoteGet(K key) public async Task<V> RemoteGet(K key)
{ {
V item = default(V); V item = default(V);
BeforeExecute(); BeforeExecute();
// Get the whole data // Get the whole data
var uri = new Uri(controllerUri.AbsoluteUri + "/" + key.ToString()); var uri = GetUri(key);
using (HttpClient client = UserHelpers.CreateClient()) using (HttpClient client = UserHelpers.CreateClient())
{ {
@ -146,16 +150,17 @@ namespace BookAStar.Data
{ {
BeforeExecute(); BeforeExecute();
var uri = GetUri(GetKey(item));
using (HttpClient client = UserHelpers.CreateClient()) using (HttpClient client = UserHelpers.CreateClient())
{ {
HttpContent content = new StringContent( HttpContent content = new StringContent(
JsonConvert.SerializeObject(item) JsonConvert.SerializeObject(item)
); );
using (var response = await client.PutAsync(controllerUri, content)) using (var response = await client.PutAsync(uri, content))
{ {
if (!response.IsSuccessStatusCode) if (!response.IsSuccessStatusCode)
// TODO throw custom exception, and catch to inform user // TODO throw custom exception, and catch to inform user
throw new Exception($"Update failed puting {item} @ {controllerUri.AbsolutePath}"); throw new Exception($"Update failed puting {item} @ {uri.AbsolutePath}");
} }
} }
@ -163,5 +168,21 @@ namespace BookAStar.Data
AfterExecuting(); AfterExecuting();
} }
public async void Delete(K key)
{
BeforeExecute();
var uri = GetUri(key);
using (HttpClient client = UserHelpers.CreateClient())
{
using (var response = await client.DeleteAsync(uri))
{
if (!response.IsSuccessStatusCode)
// TODO throw custom exception, and catch to inform user
throw new Exception($"Delete failed @ {uri.AbsolutePath}");
}
}
CurrentItem = default(V);
AfterExecuting();
}
} }
} }

Loading…