示例#1
0
        public async Task <IActionResult> UpdateAsync([FromBody] UpdateInvoiceRequest model)
        {
            var invoice = new PayInvoice.Client.Models.Invoice.UpdateInvoiceModel
            {
                Id                = model.Id,
                MerchantId        = User.GetMerchantId(),
                EmployeeId        = User.GetEmployeeId(),
                Number            = model.Number,
                ClientName        = model.Client,
                ClientEmail       = model.Email,
                Amount            = model.Amount,
                SettlementAssetId = model.SettlementAssetId,
                DueDate           = model.DueDate,
                Note              = model.Note
            };

            try
            {
                await _invoiceService.UpdateAsync(invoice, model.IsDraft);

                if (model.IsDraft)
                {
                    await _realtimeNotificationsService.SendInvoiceUpdateAsync(new InvoiceUpdateMessage()
                    {
                        MerchantId = User.GetMerchantId(),
                        InvoiceId  = invoice.Id,
                        Status     = "DraftUpdated"
                    });
                }
            }
            catch (InvalidOperationException ex)
            {
                return(BadRequest(ErrorResponse.Create(ex.Message)));
            }

            var result = await GetInvoiceModelById(invoice.Id);

            return(Json(result));
        }
 private Task ProcessMessageAsync(InvoiceUpdateMessage message)
 {
     return(_realtimeNotificationsService.SendInvoiceUpdateAsync(message));
 }