Exemplo n.º 1
0
        public void Create(string email, string url, double price)
        {
            var item = new MonitorItem()
            {
                Email = email, Url = url, LastPrice = price
            };

            _context.Add(item);
            _context.SaveChanges();
        }
Exemplo n.º 2
0
        public void Create(int userId, string url, string image, double price, string name, string site)
        {
            var item = new MonitorItem()
            {
                UserId     = userId,
                Url        = url,
                Name       = name,
                LastPrice  = price,
                FirstPrice = price,
                Site       = site,
                ImageUrl   = image,
            };

            _context.Add(item);
            _context.SaveChanges();
        }
Exemplo n.º 3
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));
            }
        }