private NullResponse PurgeOfflineTransactions(SqliteDatabaseContext databaseContext, IEnumerable <string> transactionIds)
            {
                using (var transaction = databaseContext.BeginTransaction())
                {
                    string purgeMainTransactionTableStatement = string.Format("DELETE FROM {0} WHERE TRANSACTIONID = {1} COLLATE NOCASE;", MainRetailTransactionTableName, TransactionIdParameter);
                    foreach (string transactionId in transactionIds)
                    {
                        SqlQuery query = new SqlQuery(purgeMainTransactionTableStatement);
                        query.Parameters.Add(TransactionIdParameter, transactionId);
                        databaseContext.ExecuteNonQuery(query);
                    }

                    foreach (string tableName in this.GetSatelliteRetailTransactionTableList(databaseContext))
                    {
                        string purgeSatelliteTransactionTableStatement = string.Format("DELETE FROM {0} WHERE TRANSACTIONID = {1} COLLATE NOCASE;", tableName, TransactionIdParameter);
                        foreach (string transactionId in transactionIds)
                        {
                            SqlQuery query = new SqlQuery(purgeSatelliteTransactionTableStatement);
                            query.Parameters.Add(TransactionIdParameter, transactionId);
                            databaseContext.ExecuteNonQuery(query);
                        }
                    }

                    transaction.Commit();
                }

                return(new NullResponse());
            }
            /// <summary>
            /// Saves the transaction log.
            /// </summary>
            /// <param name="request">The request.</param>
            /// <returns>The empty response.</returns>
            private static NullResponse Save(InsertTransactionLogDataRequest request)
            {
                var allTables = new DataTable[] { request.TransactionLogTable };

                request.TransactionLogTable.TableName = "ax.RETAILTRANSACTIONTABLE";
                request.TransactionLogTable.Columns.Add("CREATEDOFFLINE", typeof(int));

                foreach (DataRow row in request.TransactionLogTable.Rows)
                {
                    row["CREATEDOFFLINE"] = 1; // set offline flag to true.
                }

                using (var databaseContext = new SqliteDatabaseContext(request.RequestContext))
                    using (var transaction = databaseContext.BeginTransaction())
                    {
                        foreach (DataTable dataTable in allTables)
                        {
                            databaseContext.SaveTable(dataTable);
                        }

                        transaction.Commit();
                    }

                return(new NullResponse());
            }
            public void Execute()
            {
                using (var databaseContext = new SqliteDatabaseContext(this.request.RequestContext))
                    using (var transaction = databaseContext.BeginTransaction())
                    {
                        foreach (SalesTransaction salesTransaction in this.request.SalesTransactions)
                        {
                            if (!this.request.IgnoreRowVersionCheck)
                            {
                                // no out of the box rowversion support in sqlite, check row version before performing operation
                                DateTime transactionCreatedDateTime = RetrieveTransactionCreatedDateOrThrowOnInvalidRowVersion(databaseContext, salesTransaction.Id, salesTransaction.Version);

                                // updates the created datetime on the entity, since the update query will replace all columns in the db with the values present in the entity
                                salesTransaction.SetProperty(CreatedDateTimeColumName, new DateTimeOffset(transactionCreatedDateTime));
                            }
                        }

                        var salesTransactionDataCollection = SalesTransactionConverter.ConvertToData(
                            this.request.SalesTransactions,
                            serializeData: true);

                        using (DataTable table = CreateSalesTransactionDataTable())
                        {
                            foreach (SalesTransactionData salesTransactionData in salesTransactionDataCollection)
                            {
                                DateTimeOffset createdDateTimeOffset = this.request.SalesTransactions.First(t => t.Id == salesTransactionData.Id).BeginDateTime;

                                AddSalesTransactionDataRow(table, salesTransactionData, createdDateTimeOffset.DateTime);
                            }

                            // saves or updates records
                            databaseContext.SaveTable(table);
                        }

                        transaction.Commit();
                    }
            }
Exemplo n.º 4
0
            /// <summary>
            /// Executes the procedure.
            /// </summary>
            public void Execute()
            {
                const string UpdateDeleteDateQueryCommand = @"
                    UPDATE crt.SALESTRANSACTION SET
                        DELETEDDATETIME = @deteleDateTime
                    WHERE
                        TRANSACTIONID = @transactionId;";

                var query = new SqlQuery(UpdateDeleteDateQueryCommand);

                query.Parameters["@deteleDateTime"] = DateTime.UtcNow;

                using (var databaseContext = new SqliteDatabaseContext(this.request.RequestContext))
                    using (var transaction = databaseContext.BeginTransaction())
                    {
                        foreach (string salesTransactionId in this.request.SalesTransactionIds)
                        {
                            query.Parameters["@transactionId"] = salesTransactionId;
                            databaseContext.ExecuteNonQuery(query);
                        }

                        transaction.Commit();
                    }
            }
            /// <summary>
            /// Executes the procedure.
            /// </summary>
            public void Execute()
            {
                var allTables = new DataTable[]
                {
                    this.request.TransactionTable,
                    this.request.LinesTable,
                    this.request.TaxTable,
                    this.request.RewardPointTable,
                    this.request.ReasonCodeTable,
                    this.request.PropertiesTable,
                    this.request.PaymentTable,
                    this.request.MarkupTable,
                    this.request.InvoiceTable,
                    this.request.InvoiceTable,
                    this.request.IncomeExpenseTable,
                    this.request.DiscountTable,
                    this.request.CustomerOrderTable,
                    this.request.AttributeTable,
                    this.request.AffiliationsTable,
                    this.request.AddressTable,
                    this.request.CustomerAccountDepositTable
                };

                // change table name to match table name in the database
                this.request.TransactionTable.TableName            = "ax.RETAILTRANSACTIONTABLE";
                this.request.PaymentTable.TableName                = "ax.RETAILTRANSACTIONPAYMENTTRANS";
                this.request.LinesTable.TableName                  = "ax.RETAILTRANSACTIONSALESTRANS";
                this.request.IncomeExpenseTable.TableName          = "ax.RETAILTRANSACTIONINCOMEEXPENSETRANS";
                this.request.MarkupTable.TableName                 = "ax.RETAILTRANSACTIONMARKUPTRANS";
                this.request.TaxTable.TableName                    = "ax.RETAILTRANSACTIONTAXTRANS";
                this.request.AttributeTable.TableName              = "ax.RETAILTRANSACTIONATTRIBUTETRANS";
                this.request.AddressTable.TableName                = "ax.RETAILTRANSACTIONADDRESSTRANS";
                this.request.DiscountTable.TableName               = "ax.RETAILTRANSACTIONDISCOUNTTRANS";
                this.request.ReasonCodeTable.TableName             = "ax.RETAILTRANSACTIONINFOCODETRANS";
                this.request.PropertiesTable.TableName             = "crt.RETAILTRANSACTIONPROPERTIES";
                this.request.AffiliationsTable.TableName           = "ax.RETAILTRANSACTIONAFFILIATIONTRANS";
                this.request.RewardPointTable.TableName            = "ax.RETAILTRANSACTIONLOYALTYREWARDPOINTTRANS";
                this.request.CustomerOrderTable.TableName          = "crt.CUSTOMERORDERTRANSACTION";
                this.request.InvoiceTable.TableName                = "ax.RETAILTRANSACTIONORDERINVOICETRANS";
                this.request.CustomerAccountDepositTable.TableName = "ax.RETAILTRANSACTIONCUSTOMERACCOUNTDEPOSITTRANS";

                this.AdaptTransactionTable(this.request.TransactionTable);
                this.AdaptPaymentTable(this.request.PaymentTable);
                this.AdaptInvoiceTable(this.request.InvoiceTable);

                this.AddChannelToTable(this.request.PaymentTable);
                this.AddChannelToTable(this.request.TransactionTable);
                this.AddChannelToTable(this.request.LinesTable);
                this.AddChannelToTable(this.request.MarkupTable);
                this.AddChannelToTable(this.request.TaxTable);
                this.AddChannelToTable(this.request.AttributeTable);
                this.AddChannelToTable(this.request.AddressTable);
                this.AddChannelToTable(this.request.DiscountTable);
                this.AddChannelToTable(this.request.ReasonCodeTable);
                this.AddChannelToTable(this.request.PropertiesTable);
                this.AddChannelToTable(this.request.RewardPointTable);
                this.AddChannelToTable(this.request.AffiliationsTable);
                this.AddChannelToTable(this.request.CustomerOrderTable);
                this.AddChannelToTable(this.request.InvoiceTable);

                using (var databaseContext = new SqliteDatabaseContext(this.request.RequestContext))
                    using (var transaction = databaseContext.BeginTransaction())
                    {
                        foreach (DataTable dataTable in allTables)
                        {
                            databaseContext.SaveTable(dataTable);
                        }

                        transaction.Commit();
                    }
            }