Esempio n. 1
0
        public async Task <IActionResult> SendNotification([FromBody] SendMobileNotification model)
        {
            var user = await _userManager.Users.FirstOrDefaultAsync(x => x.Id == model.UserId);

            if (user == null)
            {
                return(Ok());
            }
            // Check if we already have this notification id
            var currentDevices = await _mobileDevices.GetAll().Where(x => x.UserId == model.UserId).ToListAsync();

            if (currentDevices == null || !currentDevices.Any())
            {
                return(Ok());
            }


            foreach (var d in currentDevices)
            {
                await _mobileNotificationService.SendMessage(new MobileNotificationRequest
                {
                    To   = d.Token,
                    Body = model.Message,
                });
            }

            return(Ok());
        }
Esempio n. 2
0
        protected async Task Send(List <string> playerIds, NotificationMessage model, MobileNotificationSettings settings, NotificationOptions requestModel, bool isAdminNotification = false)
        {
            if (playerIds == null || !playerIds.Any())
            {
                return;
            }
            foreach (var token in playerIds)
            {
                await _api.SendMessage(new MobileNotificationRequest()
                {
                    Body  = model.Message,
                    Title = model.Subject,
                    To    = token,
                    Data  = new Dictionary <string, string>(model.Data)
                });
            }

            _logger.LogDebug("Sent message to {0} recipients", playerIds.Count);
        }