Ejemplo n.º 1
0
        public IActionResult test()
        {
            //this.HttpContext.Items.Add(new { db = "db" },db);
            var d = notification.GetDevices();

            if (d != null)
            {
                var playersIdArray = new List <string> {
                };
                foreach (var device in d.players)
                {
                    if (device.tags.Any(tag => tag.Key == "notif" && tag.Value == "false"))
                    {
                        continue;                                                                    // if u desable notif in app settings
                    }
                    foreach (KeyValuePair <string, string> tag in device.tags)
                    {
                        if (tag.Key.Contains("follow"))
                        {
                            var tagVal = Convert.ToInt32(tag.Value);
                            if (db.NabavkeUpdate.Any(n => n.SifraNabavke == tagVal))
                            {
                                if (!playersIdArray.Any(n => n == device.id))
                                {
                                    playersIdArray.Add(device.id);
                                }
                            }
                        }
                    }
                }
                if (playersIdArray.Count() != 0)
                {
                    var resp = notification.CreateNotifications("Nabavka koju pratite je ažurirana!", playersIdArray.ToArray());
                    if (resp == null)
                    {
                        return(BadRequest("no notificatins created!"));
                    }
                    _logger.LogInformation("notification created!");
                    return(Ok("notification created!"));
                }
            }
            _logger.LogInformation("no notificatins created!");
            return(Ok("no notificatins created!"));
        }