Exemple #1
0
        public HttpResponseMessage login(LoginModal model)
        {
            PushNotify _notify = new PushNotify();

            // Check last session exist or not
            if (_userManager.IsAlreadySessionExist(model))
            {
                //remove the all previous sessions of user
                _userManager.ExpirePreviousSessions(model);
                //var lastSession = _userManager.GetLastSessionDetails(model);
                //// if exist then send a notification that your session has expired
                //if (lastSession != null)
                //{

                //if (lastSession.DeviceType == DeviceType.Android)
                //{
                //    var gcmModel = new GCM_Session_Expired()
                //    {
                //        GCM_ID = "GCM_SESSION_EXPIRED",
                //        Message = Messages.GCM_SESSION_EXPIRED
                //    };
                //    var notificationStack = new NotificationStackModel()
                //    {
                //        UserId = lastSession.UserId,
                //        Priority = Priority.High,
                //        Status = BLL.Models.NotificationStatus.Pending,
                //        DeviceId = lastSession.DeviceToken,
                //        Message = gcmModel,
                //    };
                //    var notificatioStack = _notificationStackManager.AddOrUpdateStack(notificationStack);
                //}
                // }
            }
            var result = _userManager.AuthenticateUserOnMobile(model);

            if (result.Status == ActionStatus.Successfull)
            {
                try
                {
                    if (result.Object.DeviceType == (short)DeviceType.IOS)
                    {
                        PushNotifier.NotifyIOSUser(result.Object.DeviceToken, "Login successfully", NotificationType.MessageAlert);
                    }
                }
                catch (Exception ex)
                {
                    _errorLogManager.LogStringExceptionToDatabase(ex.Message);
                }
                return(new JsonContent("Login Successfull", result.Status, result.Object).ConvertToHttpResponseOK());
            }
            return(new JsonContent(result.Message, result.Status).ConvertToHttpResponseOK());
        }
Exemple #2
0
        public bool ProcessNotificationQueue(int userId, string token = null, NotificationHandler method = null)
        {
            try
            {
                //Process High Priority Notification
                var highPriorityNotification = Context.NotificationStacks.Where(x => x.UserId == userId && x.Status != (int)NotificationStatus.Seen && x.Priority == (int)Priority.High).OrderBy(x => x.Priority).ToList();
                if (highPriorityNotification.Count != 0)
                {
                    using (var manager = new PushNotify().Configure())
                    {
                        foreach (var notificationStack in highPriorityNotification)
                        {
                            manager.NotifyAndroidUser(string.IsNullOrEmpty(token) ? notificationStack.User.DeviceToken : token, notificationStack.Message, NotificationType.MessageAlert);
                        }
                    }
                    return(true);
                }

                //Process Low Priority Notification
                var lowPriorityNotification = Context.NotificationStacks.Where(x => x.UserId == userId && x.Status != (int)NotificationStatus.Seen && x.Priority != (int)Priority.High).OrderBy(x => x.Priority).ToList();
                if (lowPriorityNotification.Count != 0)
                {
                    using (var manager = new PushNotify().Configure())
                    {
                        foreach (var notificationStack in lowPriorityNotification)
                        {
                            manager.NotifyAndroidUser(string.IsNullOrEmpty(token) ? notificationStack.User.DeviceToken : token, notificationStack.Message, NotificationType.MessageAlert);
                        }
                    }
                    return(true);
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }