public void ToggleNotificationIsRead(int id, bool isRead) { Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; ComboNotification notification = new ComboNotification(); if (notification.LoadByPrimaryKey(id)) { notification.IsRead = isRead; notification.Save(); } _response.Entity = null; SetContentResult(_response); }
public void RespondToRequestFollowFriend(int userId, int FollowerId, bool IsApproved, int NotificationID) { Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; bool follow = false; ProfileFollower follower = new ProfileFollower(); follower.LoadByPrimaryKey(userId, FollowerId); if (IsApproved) { follower.IsRequestApproved = IsApproved; follower.Save(); follow = true; } else { follower.MarkAsDeleted(); follower.Save(); } ComboNotification toDelete = new ComboNotification(); toDelete.LoadByPrimaryKey(NotificationID); toDelete.MarkAsDeleted(); toDelete.Save(); /**************************/ // save notification and push it to device if (IsApproved) { 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 = creator.UserName, ComboDisplayName = creator.DisplayName, ProfilePic = creator.GetColumn("ProfilePic").ToString(), FriendProfilePic = commentor.GetColumn("ProfilePic").ToString(), IsFollowUser = follow }; }).ToList(); ComboNotification notification = new ComboNotification(); notification.AddNew(); notification.ComboUserID = commentor.ComboUserID; notification.NotificationType = (int)Combo.Models.NotificationType.ACCEPT_FOLLOW_REQUEST; // accept follow friend notification.NotificationDate = DateTime.UtcNow; notification.NotificationBody = Newtonsoft.Json.JsonConvert.SerializeObject(arequest); notification.IsRead = false; notification.Save(); NotificationUserSettings settings = new NotificationUserSettings(); settings.LoadByPrimaryKey(commentor.ComboUserID, (int)Combo.Models.NotificationType.FOLLOW_FIREND); bool notify = false; if (settings.RowCount == 0) notify = true; else notify = settings.CanGetNotification(commentor.ComboUserID, creator.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), commentor.DeviceID); } } /**************************/ _response.Entity = null; SetContentResult(_response); }