public async Task<InvoiceModel> CreateInvoiceAsync(ClientInvoiceModel invoice, List<ClientInvoiceProductModel> clientInvoiceProducts, List<PartialTimesheetsModel> timesheets) { var invoiceDto = new InvoiceModel { ClientInvoice = invoice, ClientInvoiceProducts = clientInvoiceProducts, Timesheets = timesheets }; using (var client = new HttpClient()) { string invoiceDTOJson = JsonConvert.SerializeObject(invoiceDto); client.DefaultRequestHeaders.Authorization = HelperMethods.CreateAuthorizationHeader(_apiKey); var content = new StringContent(invoiceDTOJson, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync(BaseRequestUri, content); string responseString = await response.Content.ReadAsStringAsync(); return JsonConvert.DeserializeObject<InvoiceModel>(responseString); } }
public async Task<ClientInvoiceModel> EditInvoiceAsync(ClientInvoiceModel clientInvoice) { using (var client = new HttpClient()) { var values = HelperMethods.CreateKeyValuePairsFromReflection(clientInvoice); client.DefaultRequestHeaders.Authorization = HelperMethods.CreateAuthorizationHeader(_apiKey); var content = new FormUrlEncodedContent(values); HttpResponseMessage response = await client.PutAsync(BaseRequestUri, content); return await GetInvoiceByIdAsync(clientInvoice.InvoiceID); } }
public async Task<ClientInvoiceModel> CreateInvoiceAsync(ClientInvoiceModel clientInvoice) { using (var client = new HttpClient()) { var values = HelperMethods.CreateKeyValuePairsFromReflection(clientInvoice); 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<ClientInvoiceModel>(responseString); } }
public async Task<InvoiceModel> CreateInvoiceAsync(ClientInvoiceModel invoice, List<ClientInvoiceProductModel> clientInvoiceProducts) { var timesheets = new List<PartialTimesheetsModel>(); var result = await CreateInvoiceAsync(invoice, clientInvoiceProducts, timesheets); return result; }