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); /**************************/ } }
public bool CanGetNotification(int userID, int senderID) { bool canNotified = false; if (IsColumnNull(ColumnNames.ReceiveNotificationType)) canNotified = true; else if (ReceiveNotificationType == 2) canNotified = true; else { ProfileFollower follower = new ProfileFollower(); if (follower.LoadByPrimaryKey(senderID, userID) && ReceiveNotificationType == 1) canNotified = true; } return canNotified; }
private void SendFollowersBirthdaysNotifications(int UserID) { ProfileFollower followers = new ProfileFollower(); ComboUser NotifiedUser = new ComboUser(); NotifiedUser.GetUserByUserId(UserID); followers.GetProfileFollowersByUserID(UserID); for (int i = 0; i < followers.RowCount; i++) { ComboUser current = new ComboUser(); current.GetUserByUserId(followers.ComboFollowerID); List<Models.ComboUser> info = current.DefaultView.Table.AsEnumerable().Select(row => { return new Models.ComboUser { ComboUserID = Convert.ToInt32(row["ComboUserID"]), UserName = row["UserName"].ToString(), DisplayName = row["DisplayName"].ToString(), Password = row["Password"].ToString(), Email = row["Email"].ToString(), Bio = row["Bio"].ToString(), ProfileImgID = row.IsNull("ProfileImgID") ? 0 : Convert.ToInt32(row["ProfileImgID"]), CoverImgID = row.IsNull("CoverImgID") ? 0 : Convert.ToInt32(row["CoverImgID"]), GenderID = row.IsNull("GenderID") ? 0 : Convert.ToInt32(row["GenderID"]), IsActivated = row.IsNull("IsActivated") ? false : Convert.ToBoolean(row["IsActivated"]), ExternalIDType = row.IsNull("ExternalIDType") ? 0 : Convert.ToInt32(row["ExternalIDType"]), ExternalID = row["ExternalID"].ToString(), DeviceID = row["DeviceID"].ToString(), ProfilePic = row["ProfilePic"].ToString(), CoverPic = row["CoverPic"].ToString(), UserRankID = Convert.ToInt32(row["UserRankID"]), BirthDate = row.IsNull("BirthDate") ? DateTime.MinValue : Convert.ToDateTime(row["BirthDate"]), Country = row["Country"].ToString(), Phone = row["Phone"].ToString(), Website = row["Website"].ToString(), CountryFlagPath = row["CountryFlagPath"].ToString(), Location = row["Location"].ToString(), IsPrivateAccount = row.IsNull("IsPrivateAccount") ? false : Convert.ToBoolean(row["IsPrivateAccount"]), }; }).ToList(); ComboNotification notification = new ComboNotification(); notification.AddNew(); notification.ComboUserID = NotifiedUser.ComboUserID; notification.NotificationType = (int)Combo.Models.NotificationType.FOLLOWER_BIRTHDAY; // like notification.NotificationDate = DateTime.UtcNow; notification.NotificationBody = Newtonsoft.Json.JsonConvert.SerializeObject(info); 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), NotifiedUser.DeviceID); followers.MoveNext(); } }
public void ToggleFollowFriend(int userId, int FollowerId) { Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; bool follow = false; ProfileFollower follower = new ProfileFollower(); if (!follower.LoadByPrimaryKey(userId, FollowerId)) { follower.AddNew(); follower.ComboFollowerID = FollowerId; follower.ComboUserID = userId; follower.IsRequestApproved = true; follower.Save(); follow = true; } else { follower.MarkAsDeleted(); follower.Save(); } if (follow) { /**************************/ // save notification and push it to device ComboUser creator = new ComboUser(); ComboUser commentor = new ComboUser(); creator.GetUserByUserId(userId); commentor.GetUserByUserId(FollowerId); List<Models.FollowRequest> arequest = follower.DefaultView.Table.AsEnumerable().Select(row => { return new Models.FollowRequest { ComboFriendID = Convert.ToInt32(row["ComboFollowerID"]), ComboUserID = Convert.ToInt32(row["ComboUserID"]), ComboUserName = commentor.UserName, ComboDisplayName = commentor.DisplayName, ProfilePic = creator.GetColumn("ProfilePic").ToString(), FriendProfilePic = commentor.GetColumn("ProfilePic").ToString(), IsFollowUser = follow }; }).ToList(); ComboNotification notification = new ComboNotification(); notification.AddNew(); notification.ComboUserID = creator.ComboUserID; if (follow) notification.NotificationType = (int)Combo.Models.NotificationType.FOLLOW_FIREND; // follow friend else notification.NotificationType = (int)Combo.Models.NotificationType.UNFOLLOW_FRIEND; // unfollow friend notification.NotificationDate = DateTime.UtcNow; notification.NotificationBody = Newtonsoft.Json.JsonConvert.SerializeObject(arequest); notification.IsRead = false; notification.Save(); NotificationUserSettings settings = new NotificationUserSettings(); settings.LoadByPrimaryKey(creator.ComboUserID, (int)Combo.Models.NotificationType.FOLLOW_FIREND); bool notify = false; if (settings.RowCount == 0) notify = true; else notify = settings.CanGetNotification(creator.ComboUserID, commentor.ComboUserID, (int)Combo.Models.NotificationType.FOLLOW_FIREND); if (notify) { 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); }
public void ToggleBlockUser(int userId, int BlockedUserID) { Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; bool block = false; BlockedUser blocked = new BlockedUser(); if (!blocked.LoadByPrimaryKey(userId, BlockedUserID)) { blocked.AddNew(); blocked.BlockedUserID = BlockedUserID; blocked.ComboUserID = userId; blocked.Save(); block = true; } else { blocked.MarkAsDeleted(); blocked.Save(); } if (block) { ProfileFollower _1stfollow = new ProfileFollower(); ProfileFollower _2ndfollow = new ProfileFollower(); if (_1stfollow.LoadByPrimaryKey(userId, BlockedUserID)) { _1stfollow.MarkAsDeleted(); _1stfollow.Save(); } if (_2ndfollow.LoadByPrimaryKey(BlockedUserID, userId)) { _2ndfollow.MarkAsDeleted(); _2ndfollow.Save(); } } _response.Entity = null; SetContentResult(_response); }
public void GetProfileFollowing(int userID, int pageIndex) { Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; ProfileFollower user = new ProfileFollower(); user.GetProfileFollowingByUserID(userID); List<Models.ComboUser> Users = user.DefaultView.Table.AsEnumerable().Select(row => { return new Models.ComboUser { ComboUserID = Convert.ToInt32(row["ComboUserID"]), UserName = row["UserName"].ToString(), DisplayName = row["DisplayName"].ToString(), Password = row["Password"].ToString(), Email = row["Email"].ToString(), Bio = row["Bio"].ToString(), ProfileImgID = row.IsNull("ProfileImgID") ? 0 : Convert.ToInt32(row["ProfileImgID"]), CoverImgID = row.IsNull("CoverImgID") ? 0 : Convert.ToInt32(row["CoverImgID"]), GenderID = row.IsNull("GenderID") ? 0 : Convert.ToInt32(row["GenderID"]), IsActivated = row.IsNull("IsActivated") ? false : Convert.ToBoolean(row["IsActivated"]), ExternalIDType = row.IsNull("ExternalIDType") ? 0 : Convert.ToInt32(row["ExternalIDType"]), ExternalID = row["ExternalID"].ToString(), DeviceID = row["DeviceID"].ToString(), ActivationCode = row.IsNull("ActivationCode") ? Guid.Empty : new Guid(row["ActivationCode"].ToString()), PassResetCode = row.IsNull("PassResetCode") ? Guid.Empty : new Guid(row["PassResetCode"].ToString()), ProfilePic = row["ProfilePic"].ToString(), }; }).Skip(pageIndex * FollowersPageSize).Take(FollowersPageSize).ToList(); _response.Entity = Users; SetContentResult(_response); //return _response; }