public async Task<IEnumerable<EmployeeModel>> CreateEmployeeAsync(EmployeeModel employee) { using (var client = new HttpClient()) { List<KeyValuePair<string, string>> values = HelperMethods.CreateKeyValuePairsFromReflection(employee); client.DefaultRequestHeaders.Authorization = HelperMethods.CreateAuthorizationHeader(_apiKey); var content = new FormUrlEncodedContent(values); HttpResponseMessage response = await client.PostAsync(BaseRequestUri, content); string responseString = await response.Content.ReadAsStringAsync(); return JsonConvert.DeserializeObject<IEnumerable<EmployeeModel>>(responseString); } }
public async Task<EmployeeModel> EditEmployeeAsync(EmployeeModel employee) { using (var client = new HttpClient()) { List<KeyValuePair<string, string>> values = HelperMethods.CreateKeyValuePairsFromReflection(employee); client.DefaultRequestHeaders.Authorization = HelperMethods.CreateAuthorizationHeader(_apiKey); var content = new FormUrlEncodedContent(values); HttpResponseMessage response = await client.PutAsync(BaseRequestUri, content); return await GetEmployeeByIdAsync(employee.EmpID); } }