public async void LoadData() { try { int otbID = int.Parse(Application.Current.Properties["Otb_ID"].ToString()); if (Connectivity.NetworkAccess == NetworkAccess.Internet) { ResponseHTTP <UserModel> responseHTTP = await userService.UsersByOtb(otbID); if (responseHTTP.Code == System.Net.HttpStatusCode.OK) { UserList = responseHTTP.Data; await App.SQLiteDB.SaveUserAsync(UserList); } else { DependencyService.Get <IMessage>().LongAlert(responseHTTP.Msj); } } else { UserList = await App.SQLiteDB.GetUserAsync(); } } catch (System.Exception ex) { DependencyService.Get <IMessage>().LongAlert(ex.Message); } }
private async Task LoadUsers() { try { int otbId = int.Parse(Application.Current.Properties["Otb_ID"].ToString()); if (Connectivity.NetworkAccess == NetworkAccess.Internet) { ResponseHTTP <UserModel> responseHTTP = await userService.UsersByOtb(otbId); if (responseHTTP.Code == System.Net.HttpStatusCode.OK) { userLis = responseHTTP.Data; await App.SQLiteDB.SaveUserAsync(userLis); } else { DependencyService.Get <IMessage>().LongAlert(responseHTTP.Msj); } } else { userLis = await App.SQLiteDB.GetUserAsync(); } } catch (Exception ex) { throw ex; } }
private async Task LoadAlertTypes() { try { if (Connectivity.NetworkAccess == NetworkAccess.Internet) { ResponseHTTP <AlertTypeModel> responseHTTP = await alertTypeService.GetAlertTypes(); if (responseHTTP.Code == System.Net.HttpStatusCode.OK) { AlertTypeList = new ObservableCollection <AlertTypeModel>(responseHTTP.Data); await App.SQLiteDB.SaveAlertTypeAsync(responseHTTP.Data); } else { DependencyService.Get <IMessage>().LongAlert(responseHTTP.Msj); } } else { var aux = await App.SQLiteDB.GetAlertTypeAsync(); AlertTypeList = new ObservableCollection <AlertTypeModel>(aux); } } catch (Exception ex) { throw ex; } }
private async Task LoadAlerts() { try { int otbId = int.Parse(Application.Current.Properties["Otb_ID"].ToString()); if (Connectivity.NetworkAccess == NetworkAccess.Internet) { ResponseHTTP <AlertModel> responseHTTP = await alertService.listarAlertas(otbId); if (responseHTTP.Code == System.Net.HttpStatusCode.OK) { listActivity = responseHTTP.Data; await App.SQLiteDB.SaveAlertAsync(listActivity); } else { DependencyService.Get <IMessage>().LongAlert(responseHTTP.Msj); } } else { listActivity = await App.SQLiteDB.GetAlertAsync(); } } catch (Exception ex) { throw ex; } }
protected async Task <ResponseHTTP <T> > UPLOAD(MultipartFormDataContent formData, string actionUrl) { actionUrl = urlserver + actionUrl; using (var client = new HttpClient()) { var response = await client.PostAsync(actionUrl, formData); if (response.StatusCode == HttpStatusCode.OK) { var jsonString = await response.Content.ReadAsStringAsync(); res = JsonConvert.DeserializeObject <ResponseHTTP <T> >(jsonString); return(res); } else { res.Code = response.StatusCode; if (res.Msj == null) { res.Msj = response.StatusCode.ToString(); } return(res); } } }
//Metodos nuevos private async Task LoadAlertsType() { try { ResponseHTTP <AlertTypeModel> responseHTTP = await alertTypeService.GetAlertTypes(); if (responseHTTP.Code == System.Net.HttpStatusCode.OK) { ListAlertsType = responseHTTP.Data; } } catch (Exception ex) { DependencyService.Get <IMessage>().LongAlert(ex.Message); } }
// Metodo que carga la data de actividades de usuarios public async void LoadData() { try { ResponseHTTP <AlertModel> response = await alertService.listarAlertas(int.Parse(Application.Current.Properties["Otb_ID"].ToString())); if (response.Code == System.Net.HttpStatusCode.OK) { listaAlertas = response.Data; } else { DependencyService.Get <IMessage>().LongAlert(response.Msj); } } catch (Exception ex) { DependencyService.Get <IMessage>().LongAlert(ex.Message); } }
protected async Task <ResponseHTTP <T> > POST(string json, string url) { try { Uri RequestUri = new Uri(urlserver + url); var client = new HttpClient(); var contJson = new StringContent(json, Encoding.UTF8, "application/json"); if (Application.Current.Properties.ContainsKey("Token")) { string token = Application.Current.Properties["Token"].ToString(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(token); } var response = await client.PostAsync(RequestUri, contJson); if (response.StatusCode == HttpStatusCode.OK) { var jsonString = await response.Content.ReadAsStringAsync(); res = JsonConvert.DeserializeObject <ResponseHTTP <T> >(jsonString); return(res); } else { res.Code = response.StatusCode; if (res.Msj == null) { res.Msj = response.StatusCode.ToString(); } return(res); } } catch (Exception ex) { throw ex; } }
/// <summary> /// Metodo que carga las actividades en la vista View_UserProfile segun el id del usuario que reciba /// </summary> /// <param name="id">codigo id de un usuario que sera utilizado para hacer consultas a la bdd</param> /// public async void LoadActivities() { try { if (Connectivity.NetworkAccess == NetworkAccess.Internet) { ResponseHTTP <AlertModel> responseHTTP = await alertService.GetAlertsByUser(user.Otb_ID, user.User_ID); if (responseHTTP.Code == System.Net.HttpStatusCode.OK) { ActivityList = responseHTTP.Data.OrderByDescending(x => x.Date).ToList(); await App.SQLiteDB.SaveAlertAsync(activityList); } } else { ActivityList = await App.SQLiteDB.GetAlertAsync(); } } catch (System.Exception ex) { DependencyService.Get <IMessage>().LongAlert(ex.Message); } }