コード例 #1
0
            private static NullResponse SaveCart(SaveCartDataRequest request)
            {
                ThrowIf.Null(request, "request");
                ThrowIf.Null(request.SalesTransactions, "request.SalesTransactions");

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

                using (DataTable table = new DataTable(SalesTransactionTableTypeName))
                {
                    SalesTransactionData.FillSchemaForSave(table);
                    foreach (SalesTransactionData salesTransactionData in salesTransactionDataCollection)
                    {
                        table.Rows.Add(salesTransactionData.CreateDataRow(table));
                    }

                    ParameterSet parameters = new ParameterSet();
                    parameters[SalesTransactionTableTypeVariableName] = table;
                    parameters["@b_IgnoreRowVersionCheck"]            = request.IgnoreRowVersionCheck;

                    try
                    {
                        int errorCode;
                        using (var databaseContext = new SqlServerDatabaseContext(request))
                        {
                            errorCode = databaseContext.ExecuteStoredProcedureNonQuery(SaveSalesTransactionSprocName, parameters);
                        }

                        if (errorCode == (int)DatabaseErrorCodes.VersionMismatchError)
                        {
                            throw new StorageException(StorageErrors.Microsoft_Dynamics_Commerce_Runtime_ObjectVersionMismatchError, errorCode, "Version mismatch while saving transaction.");
                        }

                        if (errorCode != (int)DatabaseErrorCodes.Success)
                        {
                            throw new StorageException(StorageErrors.Microsoft_Dynamics_Commerce_Runtime_CriticalStorageError, errorCode, "Unable to save transactions.");
                        }
                    }
                    catch (DatabaseException databaseException)
                    {
                        throw new StorageException(
                                  StorageErrors.Microsoft_Dynamics_Commerce_Runtime_CriticalStorageError,
                                  (int)databaseException.ErrorCode,
                                  databaseException,
                                  "Unable to save transactions.");
                    }
                }

                return(new NullResponse());
            }
コード例 #2
0
            /// <summary>
            /// Creates a data table for sales transaction.
            /// </summary>
            /// <returns>The data table for the sales transaction table.</returns>
            private static DataTable CreateSalesTransactionDataTable()
            {
                DataTable table = new DataTable(SalesTransactionTableName);

                SalesTransactionData.FillSchemaForSave(table);

                // add fields not present in the default schema
                DataColumn createdDateTimeColumn = new DataColumn(CreatedDateTimeColumName, typeof(DateTime))
                {
                    DefaultValue = DateTime.UtcNow
                };

                table.Columns.Add(createdDateTimeColumn);
                table.Columns.Add(ModifiedDateTimeColumnName, typeof(DateTime));

                return(table);
            }