コード例 #1
1
ファイル: combo.asmx.cs プロジェクト: menasbeshay/ivalley-svn
        private void UpdateUserRank(int UserID)
        {
            ComboUser user = new ComboUser();
            user.GetUserByUserId(UserID);

            UserActivityLog log = new UserActivityLog();
            log.GetActivityDaysByUserID(user.ComboUserID);

            ComboPost posts = new ComboPost();
            posts.GetUserPostsCountByUserID(user.ComboUserID);

            ComboComment comments = new ComboComment();
            comments.GetPostCommentsCountByUserID(user.ComboUserID);

            ComboPostLike postLikes = new ComboPostLike();
            postLikes.GetPostLikesCountByUserID(user.ComboUserID);

            ProfileFollower followers = new ProfileFollower();
            followers.GetProfileFollowersCountByUserID(user.ComboUserID);

            ProfileFollower followings = new ProfileFollower();
            followings.GetProfileFollowingCountByUserID(user.ComboUserID);

            ProfileLiker profileLikes = new ProfileLiker();
            profileLikes.GetProfileLikerCountByUserID(user.ComboUserID);

            int oldRank = user.UserRankID;

            if (Convert.ToInt32(log.GetColumn("TotalActivityDays")) > 365 ||
                Convert.ToInt32(posts.GetColumn("TotalPostCount")) > 3000 ||
                Convert.ToInt32(comments.GetColumn("TotalCount")) > 3000 ||
                Convert.ToInt32(postLikes.GetColumn("TotalPostLikes")) > 3000 ||
                Convert.ToInt32(followers.GetColumn("TotalFollowers")) > 3000 ||
                Convert.ToInt32(followings.GetColumn("TotalFollowings")) > 3000 ||
                Convert.ToInt32(profileLikes.GetColumn("TotalProfileLikes")) > 3000)
            {
                user.UserRankID = 5;
            }
            else if (Convert.ToInt32(log.GetColumn("TotalActivityDays")) > 240 ||
                    Convert.ToInt32(posts.GetColumn("TotalPostCount")) > 2000 ||
                    Convert.ToInt32(comments.GetColumn("TotalCount")) > 2000 ||
                    Convert.ToInt32(postLikes.GetColumn("TotalPostLikes")) > 2000 ||
                    Convert.ToInt32(followers.GetColumn("TotalFollowers")) > 2000 ||
                    Convert.ToInt32(followings.GetColumn("TotalFollowings")) > 2000 ||
                    Convert.ToInt32(profileLikes.GetColumn("TotalProfileLikes")) > 2000)
            {
                user.UserRankID = 4;
            }
            else if (Convert.ToInt32(log.GetColumn("TotalActivityDays")) > 120 ||
                    Convert.ToInt32(posts.GetColumn("TotalPostCount")) > 1000 ||
                    Convert.ToInt32(comments.GetColumn("TotalCount")) > 1000 ||
                    Convert.ToInt32(postLikes.GetColumn("TotalPostLikes")) > 1000 ||
                    Convert.ToInt32(followers.GetColumn("TotalFollowers")) > 1000 ||
                    Convert.ToInt32(followings.GetColumn("TotalFollowings")) > 1000 ||
                    Convert.ToInt32(profileLikes.GetColumn("TotalProfileLikes")) > 1000)
            {
                user.UserRankID = 3;
            }
            else if (Convert.ToInt32(log.GetColumn("TotalActivityDays")) > 30 ||
                    Convert.ToInt32(posts.GetColumn("TotalPostCount")) > 500 ||
                    Convert.ToInt32(comments.GetColumn("TotalCount")) > 500 ||
                    Convert.ToInt32(postLikes.GetColumn("TotalPostLikes")) > 500 ||
                    Convert.ToInt32(followers.GetColumn("TotalFollowers")) > 500 ||
                    Convert.ToInt32(followings.GetColumn("TotalFollowings")) > 500 ||
                    Convert.ToInt32(profileLikes.GetColumn("TotalProfileLikes")) > 500)
            {
                user.UserRankID = 2;
            }

            user.Save();
            if (user.UserRankID > oldRank)
            {
                /**************************/
                // save notification and push it to device
                UserRank old = new UserRank();
                old.LoadByPrimaryKey(oldRank);

                UserRank newrank = new UserRank();
                newrank.LoadByPrimaryKey(user.UserRankID);

                List<Models.UserRankUpdated> arequest = user.DefaultView.Table.AsEnumerable().Select(row =>
                {
                    return new Models.UserRankUpdated
                    {
                        ComboUserID = Convert.ToInt32(row["ComboUserID"]),
                        UserName = user.UserName,
                        DisplayName = user.DisplayName,
                        OldUserRankID = oldRank,
                        NewUserRankID = user.UserRankID,
                        OldRankName = old.Name,
                        NewRankName = newrank.Name,
                        ProfilePic = row["ProfilePic"].ToString()
                    };
                }).ToList();

                ComboNotification notification = new ComboNotification();
                notification.AddNew();
                notification.ComboUserID = user.ComboUserID;
                notification.NotificationType = (int)Combo.Models.NotificationType.UPDATE_USER_RANK; // update rank
                notification.NotificationDate = DateTime.UtcNow;
                notification.NotificationBody = Newtonsoft.Json.JsonConvert.SerializeObject(arequest);
                notification.IsRead = false;
                notification.Save();

                List<Models.ComboNotification> notificationJson = notification.DefaultView.Table.AsEnumerable().Select(row =>
                {
                    return new Models.ComboNotification
                    {
                        ComboNotificationID = Convert.ToInt32(row["ComboNotificationID"]),
                        ComboUserID = Convert.ToInt32(row["ComboUserID"]),
                        IsRead = Convert.ToBoolean(row["IsRead"]),
                        NotificationBody = row["NotificationBody"].ToString(),
                        NotificationDate = Convert.ToDateTime(row["NotificationDate"].ToString()).Subtract(new DateTime(1970, 1, 1)).TotalSeconds,
                        NotificationType = Convert.ToInt32(row["NotificationType"])
                    };
                }).ToList();

                SendGCMNotification(Newtonsoft.Json.JsonConvert.SerializeObject(notificationJson), user.DeviceID);
                /**************************/
            }
        }
コード例 #2
0
ファイル: combo.asmx.cs プロジェクト: menasbeshay/ivalley-svn
        public void ToggleLikeFriend(int userId, int LikerId)
        {
            Models.ComboResponse _response = new Models.ComboResponse();
            _response.bool_result = true;
            _response.ErrorCode = 0;
            _response.ErrorMsg = "";
            bool like = false;

            ProfileLiker Liker = new ProfileLiker();
            if (!Liker.LoadByPrimaryKey(userId, LikerId))
            {
                Liker.AddNew();
                Liker.ComboLikerID = LikerId;
                Liker.ComboUserID = userId;
                Liker.Save();
                like = true;
            }
            else
            {
                Liker.MarkAsDeleted();
                Liker.Save();
            }

            /**************************/
            // save notification and push it to device
            ComboUser creator = new ComboUser();
            ComboUser P_Liker = new ComboUser();
            creator.LoadByPrimaryKey(userId);
            P_Liker.LoadByPrimaryKey(LikerId);

            ComboNotification notification = new ComboNotification();
            notification.AddNew();
            notification.ComboUserID = creator.ComboUserID;
            if (like)
                notification.NotificationType = (int)Combo.Models.NotificationType.LIKE_PROFILE; // Like friend
            else
                notification.NotificationType = (int)Combo.Models.NotificationType.UNLIKE_PROFILE; // unLike friend
            notification.NotificationDate = DateTime.UtcNow;
            notification.NotificationBody = Newtonsoft.Json.JsonConvert.SerializeObject("[{'ComboUserID':" + creator.ComboUserID + ",'ComboFriendID':" + P_Liker.ComboUserID + ",'ComboUsername:'******'" + ",'ComboDisplayName:'" + P_Liker.DisplayName + "', 'IsFollowUser' : " + like + "}]");
            notification.IsRead = false;
            notification.Save();

            List<Models.ComboNotification> notificationJson = notification.DefaultView.Table.AsEnumerable().Select(row =>
            {
                return new Models.ComboNotification
                {
                    ComboNotificationID = Convert.ToInt32(row["ComboNotificationID"]),
                    ComboUserID = Convert.ToInt32(row["ComboUserID"]),
                    IsRead = Convert.ToBoolean(row["IsRead"]),
                    NotificationBody = row["NotificationBody"].ToString(),
                    NotificationDate = Convert.ToDateTime(row["NotificationDate"].ToString()).Subtract(new DateTime(1970, 1, 1)).TotalSeconds,
                    NotificationType = Convert.ToInt32(row["NotificationType"])
                };
            }).ToList();

            SendGCMNotification(Newtonsoft.Json.JsonConvert.SerializeObject(notificationJson), creator.DeviceID);
            /**************************/

            _response.Entity = null;
            SetContentResult(_response);
        }