private async void OnEndSession(object obj) { if (IsBusy) { return; } IsBusy = true; try { // Thuc hien cong viec tai day var json = JsonConvert.SerializeObject(EndMoneyBindProp); var content = new StringContent(json, Encoding.UTF8, "application/json"); using (var client = new HttpClient()) { var response = await client.PutAsync(Properties.Resources.BaseUrl + "sessions", content); if (response.IsSuccessStatusCode) { var session = JsonConvert.DeserializeObject <SessionDto>(await response.Content.ReadAsStringAsync()); SessionBindProp = null; ListClosedSessionBindProp.Add(session); Application.Current.Properties.Remove("session"); await Application.Current.SavePropertiesAsync(); SessionDetailVisibleBindProp = false; SessionVisibleBindProp = true; } } } catch (Exception e) { await ShowErrorAsync(e); } finally { IsBusy = false; } }
public async override void OnNavigatedTo(INavigationParameters parameters) { base.OnNavigatedTo(parameters); switch (parameters.GetNavigationMode()) { case NavigationMode.Back: break; case NavigationMode.New: using (var client = new HttpClient()) { var task = client.GetAsync(Properties.Resources.BaseUrl + "sessions"); if (Application.Current.Properties.ContainsKey("session")) { SessionBindProp = Application.Current.Properties["session"] as SessionDto; SessionDetailVisibleBindProp = true; SessionVisibleBindProp = false; } var response = await task; if (response.IsSuccessStatusCode) { var sessions = JsonConvert.DeserializeObject <IEnumerable <SessionDto> >(await response.Content.ReadAsStringAsync()); foreach (var session in sessions) { ListClosedSessionBindProp.Add(session); } } } break; case NavigationMode.Forward: break; case NavigationMode.Refresh: break; default: break; } }