async Task ExecuteLoadEventsCommand() { if (IsBusy) { return; } IsBusy = true; try { DetailItems.Clear(); var events = await Repository.EventDataStore.GetItemsAsync(true); events = events.Where(d => d.ClubId == Item.Id); foreach (var item in events) { DetailItems.Add(item); } } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }
public void OnPost() { //WebApi呼び出し var url = "http://localhost:50367/api/Details"; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); req.Method = "POST"; req.ContentType = "application/json"; var dic = new Dictionary <string, object> { { "user_id", 1764565 }, { "keyword", SearchItem.Keyword }, { "from_date", SearchItem.FromDate.ToString("yyyy-MM-dd") }, { "to_date", SearchItem.ToDate.ToString("yyyy-MM-dd") } }; var source = JToken.FromObject(dic); var inputJson = JsonConvert.SerializeObject(source); byte[] byteArray = Encoding.UTF8.GetBytes(inputJson); req.ContentLength = byteArray.Length; using (Stream dataStream = req.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); } HttpWebResponse res = (HttpWebResponse)req.GetResponse(); var responseJson = ""; using (var sr = new StreamReader(res.GetResponseStream())) { responseJson = sr.ReadToEnd(); } var result = JsonConvert.DeserializeObject <JToken>(responseJson); foreach (var t in result["items"]) { var item = new DetailItem() { Id = t["Id"].Value <int>(), SettlementDay = t["SettlementDay"].Value <DateTime>(), ItemNumber = t["ItemNumber"].Value <int>(), AccountTypeId = t["AccountTypeId"].Value <int>(), AccountTypeName = t["AccountTypeName"].Value <string>(), ExpenseOrRevenue = t["ExpenseOrRevenue"].Value <string>(), Amount = t["Amount"].Value <int>(), Remarks = t["Remarks"].Value <string>() }; DetailItems.Add(item); } }