/// <summary> /// Create an expense reports from image path /// </summary> /// <param name="ExpenseReportCreateModelwImage"></param> /// <returns></returns> public ExpenseReportModel CreateExpenseReport(ExpenseReportCreateModelwImage model) { foreach (var RowCreate in model.ExpenseReportRows) { foreach (var RowContent in RowCreate.ExpenseReportRowContent) { using (Image image = Image.FromFile(RowContent.ImagePath)) { using (MemoryStream m = new MemoryStream()) { image.Save(m, image.RawFormat); byte[] imageBytes = m.ToArray(); RowContent.ImagePath = Convert.ToBase64String(imageBytes); } } } } ExpenseReportCreateModel modelCreate = new ExpenseReportCreateModel { VehicleId = model.VehicleId, ContactId = model.ContactId, TripId = model.TripId, ExpenseReportDateUtc = model.ExpenseReportDateUtc, ExpenseReportRows = new List <ExpenseReportRowCreateModel>() }; foreach (var row in model.ExpenseReportRows) { ExpenseReportRowCreateModel RowCreate = new ExpenseReportRowCreateModel(); RowCreate.AmountInCurrency = row.AmountInCurrency; RowCreate.VATInCurrency = row.VATInCurrency; RowCreate.ISO4217CurrencyCode = row.ISO4217CurrencyCode; RowCreate.Notes = row.Notes; RowCreate.Category = row.Category; RowCreate.ExpenseReportRowDateUtc = row.ExpenseReportRowDateUtc; RowCreate.ExpenseReportRowContent = new List <ExpenseReportRowContentCreateModel>(); foreach (var rowcontent in row.ExpenseReportRowContent) { ExpenseReportRowContentCreateModel RowContentCreate = new ExpenseReportRowContentCreateModel(); RowContentCreate.ExpenseReportRowId = rowcontent.ExpenseReportRowId; RowContentCreate.Data = rowcontent.ImagePath; RowContentCreate.ContentType = rowcontent.ContentType; RowCreate.ExpenseReportRowContent.Add(RowContentCreate); } modelCreate.ExpenseReportRows.Add(RowCreate); } string stringPayload = JsonConvert.SerializeObject(modelCreate); var content = new StringContent(stringPayload, Encoding.UTF8, "application/json"); var response = client.PostAsync("/v1/resourceowner/expensereport", content).Result; response.EnsureSuccessStatusCodeWithProperExceptionMessage(); var urlToCreatedExpenseReport = response.Headers.GetValues("Location").First(); var expensereportModelResult = client.GetAsync(urlToCreatedExpenseReport).Result; expensereportModelResult.EnsureSuccessStatusCodeWithProperExceptionMessage(); return(JsonConvert.DeserializeObject <ExpenseReportModel>(expensereportModelResult.Content.ReadAsStringAsync().Result)); }
/// <summary> /// Updates the given expense report /// </summary> /// <response code="200">The expense report was saved</response> /// <response code="500">Internal server error</response> /// <response code="400">Bad request, could occur for a number of cases, see returned message</response> /// <response code="403">Request is forbidden, could occur for a number of reasons, see returned message</response> /// <response code="404">Not found, the expense report you tried to update can't be found</response> /// <param name="expenseReportId">The expense report id</param> /// <param name="model">The new expense report model</param> /// <returns></returns> /// <remarks>This will update the given expense report id with a new model.</remarks> public void EditExpenseReport(int expenseReportId, ExpenseReportEditModel model, ExpenseReportRowEditModel modelRow, ExpenseReportRowContentCreateModel modelRowContent) { string stringPayload = JsonConvert.SerializeObject(model); var content = new StringContent(stringPayload, Encoding.UTF8, "application/json"); var response = client.PutAsync($"/v1/resourceowner/expensereport/{expenseReportId}", content).Result; response.EnsureSuccessStatusCodeWithProperExceptionMessage(); string stringPayloadRow = JsonConvert.SerializeObject(modelRow); var contentRow = new StringContent(stringPayloadRow, Encoding.UTF8, "application/json"); var responseRow = client.PutAsync($"/v1/resourceowner/expensereport/{expenseReportId}", contentRow).Result; responseRow.EnsureSuccessStatusCodeWithProperExceptionMessage(); string stringPayloadRowContent = JsonConvert.SerializeObject(modelRowContent); var contentRowCont = new StringContent(stringPayloadRowContent, Encoding.UTF8, "application/json"); var responseRowContent = client.PutAsync($"/v1/resourceowner/expensereport/{expenseReportId}", contentRowCont).Result; responseRowContent.EnsureSuccessStatusCodeWithProperExceptionMessage(); }