public async Task <RSV_Global <List <SubArea> > > GetSubArea() { RSV_Global <List <SubArea> > infoResult = new RSV_Global <List <SubArea> >(); HttpResponseMessage response = new HttpResponseMessage(); try { using (var httpClient = new HttpClient()) { response = await httpClient.GetAsync(GetSubAreaByIDAreaRequest()); } if (response.IsSuccessStatusCode) { var dataAsString = await response.Content.ReadAsStringAsync().ConfigureAwait(false); infoResult = JsonConvert.DeserializeObject <RSV_Global <List <SubArea> > >(dataAsString); } else { infoResult.error = new Error(new Exception(), "Se presentó un error al registrar la información"); } } catch (Exception ex) { infoResult.error = new Error(ex, $"Se presento un error en el método {((MethodInfo)MethodBase.GetCurrentMethod()).Name.ToString()}. {ex.Message}"); } return(infoResult); }
public async Task <RSV_Global <Employee> > Update() { RSV_Global <Employee> infoResult = new RSV_Global <Employee>(); HttpResponseMessage response; HttpRequestMessage request; try { var employeeResult = EmployeeValidator.ValidationSimple(this.Employee); if (employeeResult.IsValid) { request = new HttpRequestMessage(HttpMethod.Post, $"{this.BaseAddress}Employee/Update"); string jsonEmployee = JsonConvert.SerializeObject(this.Employee); request.Content = new StringContent(jsonEmployee, System.Text.Encoding.UTF8, "application/json"); using (var http = new HttpClient()) { response = await http.SendAsync(request); } if (response.IsSuccessStatusCode) { infoResult.data = new Employee(); var dataAsString = await response.Content.ReadAsStringAsync().ConfigureAwait(false); infoResult = JsonConvert.DeserializeObject <RSV_Global <Employee> >(dataAsString); } else { infoResult.error = new Error(new Exception(), "Se presentó un error al registrar la información"); } } else { infoResult.error = new Error(new Exception(), string.Join(Environment.NewLine, employeeResult.ErrorMessage)); } } catch (Exception ex) { infoResult.error = new Error(ex, $"Se presento un error en el método {((MethodInfo)MethodBase.GetCurrentMethod()).Name.ToString()}. {ex.Message}"); } return(infoResult); }