public async Task <int> UpdateInvoiceAsync(int id, AddInvoiceResource entity, CancellationToken cancellationToken = default)
        {
            try
            {
                using (var connection = CreateConnection())
                {
                    string procedureInvoice = "spInvoice_Update";

                    #region Parameters for Invoice Stored Procedure
                    var invoiceParams = new DynamicParameters();
                    invoiceParams.Add("@Id", id, DbType.Int32);
                    invoiceParams.Add("CreatedDate", entity.CreatedDate, DbType.Date);
                    invoiceParams.Add("ConfirmationStatus", entity.ConfirmationStatus, DbType.Boolean);
                    invoiceParams.Add("TotalCost", entity.TotalCost, DbType.Decimal);
                    invoiceParams.Add("CreatedStaffId", entity.CreatedStaffId, DbType.Int32);
                    invoiceParams.Add("AgentId", entity.AgentId, DbType.Int32);
                    invoiceParams.Add("WarehouseId", entity.WarehouseId, DbType.Int32);

                    #endregion

                    string procedureInvoiceProduct = "spInvoiceProduct_Update";

                    #region Parameter for InvoiceProduct Stored Procedure
                    var invoiceProductParams = entity.Products;

                    #endregion
                    connection.Open();

                    using (var transac = connection.BeginTransaction())
                    {
                        int recordsAffected = await connection.ExecuteAsync(
                            sql : procedureInvoice,
                            param : invoiceParams,
                            commandType : CommandType.StoredProcedure,
                            transaction : transac);

                        try
                        {
                            await connection.ExecuteAsync(
                                sql : procedureInvoiceProduct,
                                param : invoiceProductParams,
                                commandType : CommandType.StoredProcedure,
                                transaction : transac
                                );

                            transac.Commit();
                        }
                        catch (Exception ex)
                        {
                            transac.Rollback();
                            throw new Exception(ex.Message, ex);
                        }
                        return(id);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }
 public async Task <IActionResult> UpdateInvoice([FromRoute] int id, [FromBody] AddInvoiceResource invoiceResource, CancellationToken cancellationToken = default)
 {
     return(Ok(await _invoiceService.UpdateInvoiceAsync(id, invoiceResource, cancellationToken)));
 }
 public async Task <IActionResult> PostInvoice([FromBody] AddInvoiceResource invoiceResource, CancellationToken cancellationToken = default)
 {
     return(Ok(await _invoiceService.CreateInvoice(invoiceResource, cancellationToken)));
 }
 public async Task <int> UpdateInvoiceAsync(int id, AddInvoiceResource invoice, CancellationToken cancellationToken = default)
 {
     return(await _invoiceRepository.UpdateInvoiceAsync(id, invoice, cancellationToken));
 }