예제 #1
0
        public async Task <PricerResponse> StartMonitoring(int userId, string url)
        {
            PricerResponse response = await _pricerService.GetPrice(url);

            if (response.Error != null || response.Price == null)
            {
                return(response);
            }

            _monitorItemService.Create(userId, url, response.ImageUrl, (double)response.Price, response.Title, response.Site);

            return(response);
        }
예제 #2
0
        private async Task CheckPrice(MonitorItem item)
        {
            //Console.WriteLine($"Запущен мониторинг: {item.Email}, {item.LastPrice}");
            //Console.WriteLine(item.Url);
            PricerResponse result = await _pricerService.GetPrice(item.Url);

            //Console.WriteLine($"Для: {item.Email}, {item.LastPrice}");
            //Console.WriteLine(item.Url);
            //Console.WriteLine($"Цена стала: {result.Price}");
            if (result.Error != null)
            {
                return;
            }
            if (result.Price != item.LastPrice)
            {
                string token = _userService.Get(item.UserId).MessageToken;

                double diff      = Math.Abs((double)result.Price - item.LastPrice);
                string direction = result.Price > item.LastPrice ? "выросла" : "снизилась";

                var message = new Message()
                {
                    Token        = token,
                    Notification = new Notification
                    {
                        Title = $"Цена {direction} на {diff} руб.",
                        Body  = $"Изменилась цена на товар: {item.Name}"
                    },
                };
                var messaging = FirebaseMessaging.DefaultInstance;

                _monitorItemService.UpdatePrice(item.UserId, (double)result.Price);

                Console.WriteLine(await messaging.SendAsync(message));
            }
        }