private async Task <bool> SendNotificationToAndroidDevice(Notification notification) { var devices = await _deviceStausRepository.GetDeviceStatus(notification.ReceiverUserId, (int)DeviceOs.Android); if (devices == null || devices.Count < 1) { return(false); } var payloadToSend = JsonConvert.SerializeObject(new NotificationBasicInformation { Type = notification.Type, message = notification.Text, title = notification.Title, MessageId = notification.MessageId }); ConfigureGcmBroker(); _gcmBroker.Start(); SendAndroidNotification(devices.Select(s => s.RegistrationId).ToList(), payloadToSend); var updated = await _notificationRepository.UpdateNotificationStatus(notification.NotificationId, (int)NotificationStatus.Sent); _gcmBroker.Stop(); return(true); }
public async Task <List <string> > GetDiviceIds(string userId) { try { List <string> deviceIds = new List <string>(); var devices = await _deviceStatusRepository.GetDeviceStatus(userId); foreach (var device in devices) { deviceIds.Add(device.RegistrationId); } return(deviceIds); } catch (Exception ex) { throw new Exception("Error getting device id" + ex); } }