示例#1
0
        private async Task ProcessAsync(EShopType shopType)
        {
            var bufferedData = await _bufferService.GetBufferAsync(shopType);

            await _bufferService.ClearBufferAsync(shopType);

            if (bufferedData.Count == 0)
            {
                return;
            }
            var transaction = await _transactionFactory.CreateAsync(bufferedData[0].ClientCity,
                                                                    bufferedData[0].TransactionDateTime, bufferedData[0].PaymentType, bufferedData[0].ClientPostCode);

            var shop = await _shopFactory.CreateAsync(bufferedData[0].ShopName, bufferedData[0].ShopType, bufferedData[0].ShopPostCode, bufferedData[0].ShopCity);

            shop.Transactions.Add(transaction);
            transaction.Shop = shop;
            foreach (var rawData in bufferedData)
            {
                var product = await _productFactory.CreateAsync(rawData.Price, rawData.Product, rawData.Quantity);

                var transactionProduct = await _transactionProductFactory.CreateAsync(product, transaction);

                transaction.TransactionProducts.Add(transactionProduct);
                product.TransactionProducts.Add(transactionProduct);
                await _productRepository.AddAsync(product);

                await _transactionProductRepository.AddAsync(transactionProduct);
            }
            await _transactionRepository.AddAsync(transaction);

            await _shopRepository.AddAsync(shop);

            await _unitOfWork.SaveAsync();
        }