/// <summary> /// Commits the StockCount transactions to AX. /// </summary> /// <param name="context">The request context.</param> /// <param name="journalId">The journal identifier.</param> /// <param name="transactions">A collection of stock count transactions to commit to AX.</param> /// <returns>The response object.</returns> public static CommitStockCountTransactionsServiceResponse CommitStockCountTransactions(RequestContext context, string journalId, IEnumerable <StockCountJournalTransaction> transactions) { // Save the StockCount transactions into DB before commiting to AX. AddUpdateStockCount(journalId, context, transactions); var stockCountJournal = ConstructAxStockJournal(context, journalId); var commitStockCountsRequest = new CommitStockCountJournalRealtimeRequest(stockCountJournal); StockCountJournal commitedStockCounts = context.Execute <SingleEntityDataServiceResponse <StockCountJournal> >(commitStockCountsRequest).Entity; var removeStockCountTrans = new List <StockCountJournalTransaction>(); if (commitedStockCounts != null) { foreach (var transactionLine in stockCountJournal.StockCountTransactionLines) { StockCountJournalTransaction updatedLine = commitedStockCounts.StockCountTransactionLines .FirstOrDefault( line => string.Equals( line.TrackingGuid.ToString(), transactionLine.TrackingGuid.ToString(), StringComparison.OrdinalIgnoreCase) && line.UpdatedInAx); if (updatedLine != null) { removeStockCountTrans.Add(updatedLine); } } } // This deletes both the journals and transactions. var deleteDataRequest = new DeleteStockCountJournalsDataRequest(commitedStockCounts.JournalId); context.Runtime.Execute <NullResponse>(deleteDataRequest, context); return(new CommitStockCountTransactionsServiceResponse()); }
/// <summary> /// Commits stock count journals in AX. /// </summary> /// <param name="request">The request.</param> /// <returns>The <see cref="StockCountJournal"/> journal.</returns> private static SingleEntityDataServiceResponse <StockCountJournal> CommitStockCountJournal(CommitStockCountJournalRealtimeRequest request) { var transactionClient = new TransactionService.TransactionServiceClient(request.RequestContext); StockCountJournal stockCountJournal = transactionClient.CommitStockCounts(request.Journal); return(new SingleEntityDataServiceResponse <StockCountJournal>(stockCountJournal)); }