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));
        }
示例#2
0
        public List <UserViewModel> SaveObserverMessage(ChatMessagePayload payload)
        {
            var users = new List <UserViewModel>();

            var message = new ChatMessage()
            {
                UserId    = "Admin",
                Message   = payload.Message,
                Create_At = DateTime.Now,
                IsDriver  = false
            };

            if (payload.IsToAll)
            {
                message.DriverUserId = "ALL";

                users = (from p in _userRepository.GetAllQueryable()
                         select new UserViewModel
                {
                    Id = p.Id,
                    SmartphonePlatform = p.SmartphonePlatform,
                    DeviceId = p.RegistrationId,
                    IsLoggedIn = p.IsLoggedIn
                }).ToList();
            }
            else
            {
                //var toUser = _userRepository.Query(p => p.DriverC == payload.DriverC).FirstOrDefault();
                var toUser = (from p in _userRepository.GetAllQueryable()
                              where p.DriverC == payload.DriverC
                              select new UserViewModel
                {
                    Id = p.Id,
                    SmartphonePlatform = p.SmartphonePlatform,
                    DeviceId = p.RegistrationId,
                    IsLoggedIn = p.IsLoggedIn
                }).FirstOrDefault();
                if (toUser != null)
                {
                    message.DriverUserId = toUser.Id;

                    users.Add(toUser);
                }
                else
                {
                    return(null);
                }
            }

            _chatMessageRepository.Add(message);
            SaveChatMessage();
            return(users);
        }
示例#3
0
        public async Task SendChatMessage(IHttpContext context, ChatMessagePayload body)
        {
            Authenticator.VerifyAuth(context);

            if (body.message == null || body.message.Length == 0)
            {
                await context.SendResponse(HttpStatusCode.BadRequest, new ErrorPayload()
                {
                    message = "Expected a message."
                });

                return;
            }

            await Dispatcher.RunOnMainThread(() => ChatModel.SendChatMessage(body.message));

            await context.SendResponse(HttpStatusCode.OK);
        }
        public HttpResponseMessage DriverSendMessage(ChatMessagePayload payLoad)
        {
            var status = _chatMessagesService.SaveDriverMessage(payLoad);

            if (status)
            {
                //Will implement SignalR to push message to web application here
                //SignalR to All Web clients

                var driverN = _driverService.GetDriverName(payLoad.DriverC);

                var context = GlobalHost.ConnectionManager.GetHubContext <ChatMessageHub>();
                context.Clients.All.chatMessageHub(driverN, payLoad.Message, DateTime.Now, true);

                var notifyContext = GlobalHost.ConnectionManager.GetHubContext <NotifyMessageHub>();
                notifyContext.Clients.All.notifyMessageHub();
            }

            return(base.BuildSuccessResult(HttpStatusCode.OK, status));
        }
示例#5
0
        public bool SaveDriverMessage(ChatMessagePayload payload)
        {
            var user = _userRepository.Query(p => p.DriverC == payload.DriverC).FirstOrDefault();

            if (user != null)
            {
                var message = new ChatMessage()
                {
                    DriverUserId = user.Id,
                    Message      = payload.Message,
                    Create_At    = DateTime.Now,
                    IsDriver     = true
                };

                _chatMessageRepository.Add(message);
                SaveChatMessage();
                return(true);
            }

            return(false);
        }