public async void Create(ICloseable window) { try { if (Model.HasErrors || Model.InvoiceLines.Count == 0) { return; } InvoiceDto invoiceDto = await(NewInvoice ? AppService.CreateAsync(Model.GetInput()) : AppService.UpdateAsync(Model.Id, Model.GetInput())); invoiceDto.PatientName = Model.Patient.Name; if (NewInvoice) { EventAggregator.GetEvent <InvoiceAddedEvent>().Publish(invoiceDto); } else { EventAggregator.GetEvent <InvoiceUpdatedEvent>().Publish(invoiceDto); } window.Close(); } catch (SqliteException sqlEx) { ErrorText = sqlEx.Message; } catch (BusinessException busEx) { ErrorText = busEx.Message; } }
public async Task <ActionResult> CreateInvoice(CreateInvoiceDto dto) { await _invoiceAppService.CreateAsync(dto); foreach (var items in dto.InvoiceDetails) { var check = await _stockService.CheckIfExist(items.ProductId); if (check != null) { check.TotalPieces -= items.TotalPieces; check.Amount -= items.Amount; await _stockService.UpdateAsync(check); } } return(Ok(dto)); }
public async Task PostAsync(string token) { await Task.Run(async() => { charge _params = new charge(); _params.token = token; _params.email = "*****@*****.**"; _params.items = new List <item>(); _params.items.Add(new item() { description = "Ressarcimento Plano 3 CNPJ", price_cents = 69999, quantity = 1 }); _params.payer = new payer() { cpf_cnpj = "91.347.681/0001-14", name = "Severino e Isabelly Casa Noturna Ltda", address = new address() { city = "Birigüi", district = "Vila Isabel Marin", state = "SP", number = "407", street = "Rua Manoel de Carlis", zip_code = "16204-023", }, email = "*****@*****.**", phone = "(18) 2998-6706" }; _params.order_id = Guid.NewGuid().ToString(); var content = JsonConvert.SerializeObject(_params, Formatting.Indented); HttpMessageHandler handler = new HttpClientHandler() { }; var httpClient = new HttpClient(handler) { BaseAddress = new Uri(Iugu_BaseAddress), Timeout = new TimeSpan(0, 2, 0) }; httpClient.DefaultRequestHeaders.Add("ContentType", "application/json"); var plainTextBytes = System.Text.Encoding.UTF8.GetBytes($"{Iugu_API_Token}:{Iugu_Password}"); string val = System.Convert.ToBase64String(plainTextBytes); httpClient.DefaultRequestHeaders.Add("Authorization", "Basic " + val); var stringContent = new StringContent(content, UnicodeEncoding.UTF8, "application/json"); HttpResponseMessage response = httpClient.PostAsync($"{this.Iugu_BaseAddress}/charge", stringContent).Result; string responseResult = String.Empty; using (StreamReader stream = new StreamReader(response.Content.ReadAsStreamAsync().Result)) { responseResult = stream.ReadToEnd(); try { } catch (Exception) { throw; } var json = JsonConvert.DeserializeObject <invoice>(responseResult); var invoice = new CreateUpdateInvoiceDto() { Message = json.message, InvoiceId = json.invoice_id, Success = json.success, Pdf = json.pdf, Url = json.url, }; var result = await _invoiceAppService.CreateAsync(invoice); } }); }