Beispiel #1
0
        /// <summary>
        /// Saves the user extra information
        /// </summary>
        /// <param name="u"></param>
        /// <returns></returns>
        public static UserInfo Save(UserInfo u)
        {
            using (EntityContext ctx = new EntityContext())
            {
                u.ValidateAndRaise();

                UserInfo existing = ctx.UserInfos.Where(ui => ui.UserId == u.UserId).FirstOrDefault();
                if (existing == null)
                {
                    ctx.UserInfos.AddObject(u);
                }
                else
                {
                    existing.ContactEmail         = u.ContactEmail;
                    existing.PhoneCel             = u.PhoneCel;
                    existing.PhoneHome            = u.PhoneHome;
                    existing.PhoneOffice          = u.PhoneOffice;
                    existing.PhoneOfficeExtension = u.PhoneOfficeExtension;
                    existing.FirstName            = u.FirstName;
                    existing.LastName             = u.LastName;
                    existing.Gender = u.Gender;
                    existing.NotificationsAvailability = u.NotificationsAvailability;
                    existing.Locale = u.Locale;
                }
                ctx.SaveChanges();

                // Notify connected endpoints.
                PubnubFactory.GetInstance().Publish(PubnubFactory.Channels.Users, u);


                return(u);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Notifies users that have set up their notification alert setting.
        /// </summary>
        /// <param name="baseCheckin"></param>
        private static void NotifyWaitingList(Checkin baseCheckin)
        {
            Pubnub pub = PubnubFactory.GetInstance();

            //pub.Publish(PubnubFactory.Channels.GeneralNotification, new { Class = "AvailableNotification", UserId = user.UserId });
            using (EntityContext ctx = new EntityContext())
            {
                List <int> checkedInUsers = ctx.Checkins.Where(c => !c.EndTime.HasValue).Select(c => c.UserId).ToList();
                List <int> availableUsers = ctx.UserInfos.Where(u => !checkedInUsers.Contains(u.UserId) &&
                                                                u.NotificationsAvailability.HasValue &&
                                                                u.NotificationsAvailability.Value &&
                                                                u.UserId != baseCheckin.UserId)
                                            .Select(u => u.UserId)
                                            .ToList();
                availableUsers.ForEach(user => {
                    pub.Publish(PubnubFactory.Channels.GeneralNotification, new { Class = "AvailableNotification", UserId = user });
                });
            }
        }
Beispiel #3
0
        /// <summary>
        /// Sends messages based on the notification type.
        /// </summary>
        /// <param name="notify"></param>
        /// <param name="checkin"></param>
        public static void Notify(NotificationType notify, Checkin checkin)
        {
            Pubnub nub = PubnubFactory.GetInstance();

            nub.Publish(PubnubFactory.Channels.CheckinHistory, new CheckinNotification(checkin, notify));
            nub.Publish(PubnubFactory.Channels.CheckinCurrent, checkin);

            switch (notify)
            {
            case NotificationType.Checkin:
                // Insert custom actions based on the type here.

                break;

            case NotificationType.Checkout:
                // Insert custom actions based on the type here.
                NotifyBlockingUsers(checkin, checkin.GetCheckinsIBlock());
                NotifyWaitingList(checkin);
                break;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Notifies the users that are blocking the specified checkin/space.
        /// At the moment it sends IM and Email regardless of the users' preferences
        /// </summary>
        /// <param name="baseCheckin"></param>
        /// <param name="checkins"></param>
        private static void NotifyBlockingUsers(Checkin baseCheckin, List <Checkin> checkins)
        {
            List <UserInfo> userInfos = new List <UserInfo>();
            List <User>     users     = new List <User>();
            List <int>      userIds   = checkins.Select(c => c.UserId).ToList();
            UserInfo        requestingUser;

            using (EntityContext ctx = new EntityContext())
            {
                requestingUser = ctx.UserInfos.Where(ui => ui.UserId == baseCheckin.UserId).FirstOrDefault();

                userInfos = ctx.UserInfos.Where(ui => userIds.Contains(ui.UserId)).ToList();
                users     = ctx.Users.Where(ui => userIds.Contains(ui.UserId)).ToList();
            }

            Pubnub pub = PubnubFactory.GetInstance();

            users.ForEach(user =>
            {
                // Notify via email
                EmailerFactory.SendMail(user.Email, i18n.Notification_EmailTitle, string.Format(i18n.Notification_EmailMessage, requestingUser.FullName));

                // Notify via UI (if the user has it open)
                pub.Publish(PubnubFactory.Channels.GeneralNotification, new { Class = "BlockNotification", UserId = user.UserId, RequestingUser = requestingUser.UserId });
            });

            userInfos.ForEach(ui => {
                if (!string.IsNullOrEmpty(ui.ContactEmail))
                {
                    // Notify via IM
                    MessageQueue.Save(new MessageQueue()
                    {
                        To = ui.ContactEmail, Text = string.Format(i18n.Notification_IMMessage, requestingUser.FullName)
                    });
                }
            });


            TropoFactory.CreateSession();
        }