Example #1
0
        public async Task ListProductsDicrepancies()
        {
            var dbProducts = _dbProductRepository.GetProducts();
            var wcProducts = await _wcProductService.GetProductsAsync();

            foreach (var wcProduct in wcProducts.Where(p => p.Availability?.Any() == true))
            {
                var dbProduct = dbProducts.FirstOrDefault(p => int.TryParse(wcProduct.Sku, out int id) && p.Id == id);
                if (dbProduct == null)
                {
                    continue;
                }

                (var price, var salePrice) = _priceCalculator.GetPrice(dbProduct);
                if (price == null)
                {
                    continue;
                }

                if (wcProduct.SalePrice != salePrice)
                {
                    _logger.LogInformation($"{wcProduct.Name} - {wcProduct.Sku}. Site/database: {salePrice} / {price}");
                }
            }

            var notFoundProducts = dbProducts
                                   .Where(dbProduct => !wcProducts.Any(wcProduct => int.TryParse(wcProduct.Sku, out int id) && dbProduct.Id == id))
                                   .ToList();

            var notFoundProductsStr = string.Join("\r\n", notFoundProducts.Select(product => $"{product.Name} - {product.Id}"));

            notFoundProducts.ForEach(product => _logger.LogInformation($"Not found product: {product.Name} - {product.Id}"));
        }
Example #2
0
        public async Task <Direction> GetDirectionAsync(double originLat, double originLng, double destinationLat,
                                                        double destinationLng, int?vehicleTypeId = null, DateTime?date = default(DateTime?), bool forEta = false, Tariff overriddenTariff = null)
        {
            var result = new Direction();

            var direction = await _client.GetDirectionsAsync(
                originLat, originLng, destinationLat, destinationLng,
                date).ConfigureAwait(false);

            if (direction.Distance.HasValue)
            {
                if (direction.Duration.HasValue)
                {
                    var paddedDuration = (int)Math.Ceiling((direction.Duration.Value * _appSettings.Data.EtaPaddingRatio) / 60);
                    result.Duration = Math.Max(1, paddedDuration);
                }

                result.Distance = direction.Distance;

                if (!forEta)
                {
                    result.Price = _priceCalculator.GetPrice(
                        direction.Distance,
                        date ?? DateTime.Now,
                        direction.Duration, vehicleTypeId,
                        overriddenTariff);

                    result.FormattedPrice = result.Price == null
                        ? string.Empty
                        : string.Format(new CultureInfo(_appSettings.Data.PriceFormat), "{0:C}", result.Price.Value);
                }

                result.FormattedDistance = FormatDistance(result.Distance);
            }

            return(result);
        }
 public decimal GetPrice() => _priceCalculator.GetPrice(_books);