public override async Task <PostResponse> AsyncSetter(string token) { using (var context = new Storage.TMSEntities()) { var coa = context.GL_GetCOACombineTransactionVW.ToList(); var vouchers = context.Vouchers.ToList(); foreach (var voucher in vouchers) { var detailVoucher = VoucherDetailBodyRequests(voucher, coa); var body = new VoucherPostRequestBody { branch = new GeneralDto { id = voucher.Branch.RefNo, name = voucher.Branch.BranchDescription }, desc = voucher.Description, date = voucher.VoucherDate, voucher_detail = detailVoucher }; await(string.IsNullOrEmpty(voucher.RefNo) ? Create(body, voucher) : Update(voucher.RefNo, body, voucher)); context.SaveChanges(); } return(new PostResponse { NoOfRecordEffected = 10, Status = ResponseStatus.Ok.ToString() }); } //Storage.Voucher }
private async Task Create(VoucherPostRequestBody body, Voucher voucher) { var response = _client.PostAsJsonAsync("api/Voucher", body).Result; response.EnsureSuccessStatusCode(); var contentResult = await response.Content.ReadAsAsync <VoucherPostResponse>(); voucher.RefNo = contentResult._id; voucher.UpdatedOn = DateTime.Now; }