示例#1
0
        public async Task AddProductToListAsync(ProductListItemModel product, bool isPremiumProduct)
        {
            var response = await _messageQueueService.SendUserShopRequest(product.UserId, product.ShopId);

            if (!response.IsAssigned)
            {
                _logger.Error($"User '{product.UserId}' doesn't assigned to shop '{product.ShopId}'");
                throw new Exception($"User '{product.UserId}' doesn't assigned to shop '{product.ShopId}'");
            }

            _logger.Info("Received userShop response from shop");

            var shopProductListId = _unit.ShopProductListRepository
                                    .GetByCondition(x => x.ShopId == product.ShopId).FirstOrDefault().Id;

            try
            {
                await _unit.ProductListRepository.CreateAsync(new ProductLists
                                                              { ProductId = product.ProductId, ShopProductListId = shopProductListId });

                await _unit.SaveAsync();
            }
            catch (Exception ex)
            {
                if (isPremiumProduct)
                {
                    await _messageQueueService.SendDecreasePremiumProductsCountEvent(product.AccountId);
                }

                throw ex;
            }
        }