Пример #1
0
        public HttpResponseMessage ObserverSendMessage(ChatMessagePayload payLoad)
        {
            var users = _chatMessagesService.SaveObserverMessage(payLoad);

            //---------------------------
            // ANDROID GCM NOTIFICATIONS
            //---------------------------
            var gcmDevices = (from p in users
                              where p.SmartphonePlatform == "android"
                              select new
            {
                DeviceId = p.DeviceId,
                IsLoggedIn = p.IsLoggedIn
            }).ToList();

            if (gcmDevices.Any())
            {
                //Android_PushNotification(gcmDeviceIds, payLoad.Message);
                foreach (var gcmDevice in gcmDevices)
                {
                    if (int.Parse(gcmDevice.IsLoggedIn) == 1)
                    {
                        PushNotification(gcmDevice.DeviceId, payLoad.Message);
                    }
                }
            }

            ////-------------------------
            //// APPLE iOS NOTIFICATIONS
            ////-------------------------
            var apnsDeviceIds = (from p in users
                                 where p.SmartphonePlatform == "ios"
                                 select new
            {
                DeviceId = p.DeviceId,
                IsLoggedIn = p.IsLoggedIn
            }).ToList();

            if (apnsDeviceIds.Any())
            {
                foreach (var apnsDeviceId in apnsDeviceIds)
                {
                    if (int.Parse(apnsDeviceId.IsLoggedIn) == 1)
                    {
                        IOS_PushNotification(apnsDeviceId.DeviceId, payLoad.Message);
                    }
                }
            }
            //SignalR to All Web clients
            var driverN = payLoad.DriverC != "0" ? _driverService.GetDriverName(payLoad.DriverC) : "ALL";

            var context = GlobalHost.ConnectionManager.GetHubContext <ChatMessageHub>();

            context.Clients.All.chatMessageHub(driverN, payLoad.Message, DateTime.Now, false);

            return(base.BuildSuccessResult(HttpStatusCode.OK, true));
        }