Example #1
0
            /// <summary>
            /// Invoke the method to save drop and declare transactions.
            /// </summary>
            /// <param name="request">Request context.</param>
            /// <returns>Returns response for save drop and declare.</returns>
            private static SaveDropAndDeclareServiceResponse SaveDropAndDeclareTransactions(SaveDropAndDeclareServiceRequest request)
            {
                StoreOperationServiceHelper.ValidateTenderDeclarationCountingDifference(request);

                DropAndDeclareTransaction tenderDropAndDeclare = StoreOperationServiceHelper.ConvertTenderDropAndDeclareTransaction(request);

                // If the previously created drop transaction response did not get received due to network connection issue.
                // On client retry, check if it was already saved. If true, returns saved object.
                var getDropAndDeclareTransactionDataRequest = new GetDropAndDeclareTransactionDataRequest(tenderDropAndDeclare.Id, QueryResultSettings.SingleRecord);
                DropAndDeclareTransaction transaction       = request.RequestContext.Runtime.Execute <EntityDataServiceResponse <DropAndDeclareTransaction> >(getDropAndDeclareTransactionDataRequest, request.RequestContext).PagedEntityCollection.FirstOrDefault();

                if (transaction != null)
                {
                    var getDropAndDeclareTransactionTenderDetailsDataRequest = new GetDropAndDeclareTransactionTenderDetailsDataRequest(tenderDropAndDeclare.Id, QueryResultSettings.AllRecords);
                    transaction.TenderDetails = request.RequestContext.Runtime.Execute <EntityDataServiceResponse <TenderDetail> >(getDropAndDeclareTransactionTenderDetailsDataRequest, request.RequestContext).PagedEntityCollection.Results;
                }
                else
                {
                    var saveDropAndDeclareTransactionDataRequest = new SaveDropAndDeclareTransactionDataRequest(tenderDropAndDeclare);
                    transaction = request.RequestContext.Runtime.Execute <SingleEntityDataServiceResponse <DropAndDeclareTransaction> >(saveDropAndDeclareTransactionDataRequest, request.RequestContext).Entity;
                }

                return(new SaveDropAndDeclareServiceResponse(transaction));
            }
Example #2
0
            /// <summary>
            /// Save drop and declare transaction.
            /// </summary>
            /// <param name="request">Drop and declare transaction data service request.</param>
            /// <returns>A SingleEntityDataServiceResponse containing the saved DropAndDeclareTransaction object.</returns>
            private SingleEntityDataServiceResponse <DropAndDeclareTransaction> SaveDropAndDeclareTransaction(SaveDropAndDeclareTransactionDataRequest request)
            {
                ThrowIf.Null(request, "request");
                ThrowIf.Null(request.DropAndDeclareTransaction, "request.DropAndDeclareTransaction");

                DropAndDeclareTransaction dropAndDeclareTransaction = request.DropAndDeclareTransaction;

                Tuple <PagedResult <DropAndDeclareTransaction>, ReadOnlyCollection <TenderDetail> > results;

                using (var transactionTable = new DataTable(RetailTransactionTableType))
                    using (var tenderDeclarationTable = new DataTable(TenderDeclarationTransType))
                        using (var tenderDropTable = new DataTable(TenderDropTransType))
                            using (var reasonCodeTable = new DataTable(RetailTransactionInfoCodeTransTableType))
                            {
                                TransactionLog transaction = this.Convert(dropAndDeclareTransaction);

                                RetailTransactionTableSchema.PopulateSchema(transactionTable);
                                TenderDropAndDeclareTableSchema.PopulateTenderDeclarationSchema(tenderDeclarationTable);
                                TenderDropAndDeclareTableSchema.PopulateBankTenderDropSchema(tenderDropTable);
                                TenderDropAndDeclareTableSchema.PopulateReasonCodeSchema(reasonCodeTable);

                                // Fill the transaction header details.
                                TransactionLogDataManager.FillData(request.RequestContext, transaction, transactionTable);

                                // File the transaction line details.
                                if (dropAndDeclareTransaction.TransactionType == TransactionType.BankDrop ||
                                    dropAndDeclareTransaction.TransactionType == TransactionType.SafeDrop)
                                {
                                    this.FillTenderDataTable(transaction.Id, dropAndDeclareTransaction, tenderDropTable, request.RequestContext);
                                }
                                else if (dropAndDeclareTransaction.TransactionType == TransactionType.TenderDeclaration)
                                {
                                    this.FillTenderDataTable(transaction.Id, dropAndDeclareTransaction, tenderDeclarationTable, request.RequestContext);

                                    // Fill captured reason code details for [Tender Declaration] store operation
                                    this.FillReasonCodeLines(transaction.Id, dropAndDeclareTransaction, reasonCodeTable, -1m, request.RequestContext);
                                }

                                var parameters = new ParameterSet();

                                parameters[DatabaseAccessor.ChannelIdVariableName] = request.RequestContext.GetPrincipal().ChannelId;
                                parameters["@tvp_Transaction"]        = transactionTable;
                                parameters["@tvp_TenderDeclareTrans"] = tenderDeclarationTable;
                                parameters["@tvp_TenderDropTrans"]    = tenderDropTable;
                                parameters["@tvp_ReasoncodeLine"]     = reasonCodeTable;

                                int errorCode;
                                using (var sqlServerDatabaseContext = new SqlServerDatabaseContext(request))
                                {
                                    results = sqlServerDatabaseContext.ExecuteStoredProcedure <DropAndDeclareTransaction, TenderDetail>(InsertTenderDropAndDeclareSprocName, parameters, null, out errorCode);
                                }

                                if (errorCode != (int)DatabaseErrorCodes.Success)
                                {
                                    throw new StorageException(StorageErrors.Microsoft_Dynamics_Commerce_Runtime_CriticalStorageError, errorCode, "Unable to save tender drop and declare operation.");
                                }
                            }

                DropAndDeclareTransaction savedTransaction = results.Item1.FirstOrDefault();

                if (savedTransaction == null)
                {
                    throw new StorageException(StorageErrors.Microsoft_Dynamics_Commerce_Runtime_CriticalStorageError, "Unable to retrieve newly created tender drop and declare operation after save.");
                }

                savedTransaction.TenderDetails = results.Item2;

                return(new SingleEntityDataServiceResponse <DropAndDeclareTransaction>(savedTransaction));
            }