Example #1
0
        public void AddVistor(string appName, ObjectId userId, string toUserId, string like, long appId)
        {
            var toUserIdObj = new ObjectId(toUserId);

            if (userId == toUserIdObj)
                return;

            if (like == "like")
            {
                var userLikeInfo = new UserLikeInfo
                {
                    UserId = userId,
                    ToUserId = toUserIdObj,
                    DateCreated = DateTime.Now
                };

                _userLikesDataProvider.InsertUserLike(appName, userLikeInfo);

                var userEventInfo = new UserEventInfo
                {
                    UserId = toUserIdObj,
                    EventType = 2,
                    DateCreated = DateTime.Now
                };

                _userDataProvider.InsertUserEvent(appName, userEventInfo);
            }
            else
            {
                var userVisitInfo = new UserVisitInfo
                {
                    UserId = userId,
                    ToUserId = toUserIdObj,
                    DateCreated = DateTime.Now,
                    DateModified = DateTime.Now
                };

                _userVisitsDataProvider.UpsertUserVisit(appName, userVisitInfo);
                _userVisitsDataProvider.SetUserVisit(appName, toUserIdObj);

                var fromUserInfo = _userDataProvider.GetDatingBookUserInfo(appName, userId);
                var toUserInfo = _userDataProvider.GetDatingBookUserInfo(appName, toUserIdObj);
                var appInfo = _appsDataProvider.GetAppInfo(appId);

                string msg = string.Format("{0} has watched your profile !", fromUserInfo.FirstName);

                _facebookDataProvider.SendFacebookAppNotification(toUserInfo.FacebookId, msg, msg, appInfo.AppAccessToken);
            }
        }
        public UserVisitInfo UpsertUserVisit(string appName, UserVisitInfo userVisitInfo)
        {
            var dataBase = _serverWrapper.ServerConnection.GetDatabase(appName);
            var collection = dataBase.GetCollection<UserVisitInfo>(USER_VISITS_COLLECTION_NAME);

            collection.EnsureIndex(new IndexKeysBuilder().Ascending("user_id", "to_user_id"), IndexOptions.SetUnique(true));

            var selectQuery = Query.And(Query.EQ("user_id", userVisitInfo.UserId),
                                        Query.EQ("to_user_id", userVisitInfo.ToUserId));

            var result = collection.FindOne(selectQuery);

            if (result == null)
                collection.Insert(userVisitInfo);
            else
                collection.Update(selectQuery, Update.Set("date_modified", userVisitInfo.DateModified));

            return userVisitInfo;
        }