Exemple #1
0
    public static List <UserFriendsBO> getFriendsByList(string Userid, string status, string listname)
    {
        MongoCollection <Friends> objCollection = db.GetCollection <Friends>("c_Friends");

        List <UserFriendsBO> lst = new List <UserFriendsBO>();

        foreach (Friends item in objCollection.Find(Query.And(Query.EQ("UserId", ObjectId.Parse(Userid)),
                                                              (Query.EQ("Status", status)), (Query.EQ("BelongsTo", listname))
                                                              )))
        {
            UserFriendsBO objClass = new UserFriendsBO();
            objClass.Id           = item._id.ToString();
            objClass.UserId       = item.UserId.ToString();
            objClass.FriendUserId = item.FriendUserId.ToString();
            objClass.Status       = item.Status;
            objClass.BelongsTo    = item.BelongsTo;

            MongoCollection <User> objCollection2 = db.GetCollection <User>("c_User");
            foreach (User item3 in objCollection2.Find(
                         Query.EQ("_id", ObjectId.Parse(objClass.FriendUserId))
                         ))
            {
                objClass.FirstName = item3.FirstName;
                objClass.LastName  = item3.LastName;
            }

            lst.Add(objClass);
        }

        foreach (Friends item in objCollection.Find(Query.And(Query.EQ("FriendUserId", ObjectId.Parse(Userid)),
                                                              (Query.EQ("Status", status)), (Query.EQ("BelongsTo", listname))
                                                              )))
        {
            UserFriendsBO objClass = new UserFriendsBO();
            objClass.Id           = item._id.ToString();
            objClass.UserId       = item.FriendUserId.ToString();
            objClass.FriendUserId = item.UserId.ToString();
            objClass.Status       = item.Status;
            objClass.BelongsTo    = item.BelongsTo;

            MongoCollection <User> objCollection2 = db.GetCollection <User>("c_User");
            foreach (User item3 in objCollection2.Find(
                         Query.EQ("_id", ObjectId.Parse(objClass.FriendUserId))
                         ))
            {
                objClass.FirstName = item3.FirstName;
                objClass.LastName  = item3.LastName;
            }

            lst.Add(objClass);
        }
        return(lst);
    }
Exemple #2
0
    public string[] GetFriendsName(string prefixText, int count)
    {
        List <string>             lst           = new List <string>();
        string                    uid           = Session["UserId"].ToString();
        MongoCollection <Friends> objCollection = BaseClass.db.GetCollection <Friends>("c_Friends");
        var query = Query.And(
            Query.EQ("Status", Global.CONFIRMED),      //Query.Or(
            Query.EQ("UserId", ObjectId.Parse(uid))    //, Query.EQ("UserId", UserId))
            );
        var query2 = Query.And(
            Query.EQ("Status", Global.CONFIRMED),         //Query.Or(
            Query.EQ("FriendUserId", ObjectId.Parse(uid)) //, Query.EQ("UserId", UserId))
            );
        var query3 = Query.Or(
            query,       //Query.Or(
            query2       //, Query.EQ("UserId", UserId))
            );

        foreach (Friends item in objCollection.Find(query))
        {
            MongoCollection <User> objUserCollection = BaseClass.db.GetCollection <User>("c_User");

            UserFriendsBO objClass  = new UserFriendsBO();
            var           Namequery = Query.Or(
                Query.Matches("FirstName", BsonRegularExpression.Create(new System.Text.RegularExpressions.Regex("^(?i)" + prefixText + ""))),
                Query.Matches("LastName", BsonRegularExpression.Create(new System.Text.RegularExpressions.Regex("^(?i)" + prefixText + ""))));
            var queryid = Query.And(
                Query.EQ("_id", ObjectId.Parse(item.FriendUserId.ToString())))
            ;
            var queryu = Query.And(Namequery, queryid);
            foreach (User Useritem in objUserCollection.Find(queryid))
            {
                objClass.Id           = item._id.ToString();
                objClass.FirstName    = Useritem.FirstName;
                objClass.LastName     = Useritem.LastName;
                objClass.FriendUserId = item.UserId.ToString();
                objClass.UserId       = item.FriendUserId.ToString();
                objClass.Status       = item.Status;
                //objClass.BelongsTo = Useritem.BelongsTo;
                break;
            }
            //lst.Add(objClass.FirstName + " " + objClass.LastName);
            lst.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(objClass.FirstName + " " + objClass.LastName, objClass.UserId.ToString()));
        }
        foreach (Friends item in objCollection.Find(query2))
        {
            MongoCollection <User> objUserCollection = BaseClass.db.GetCollection <User>("c_User");

            UserFriendsBO objClass  = new UserFriendsBO();
            var           Namequery = Query.Or(
                Query.Matches("FirstName", BsonRegularExpression.Create(new System.Text.RegularExpressions.Regex("^(?i)" + prefixText + ""))),
                Query.Matches("LastName", BsonRegularExpression.Create(new System.Text.RegularExpressions.Regex("^(?i)" + prefixText + ""))));
            var queryid = Query.And(
                Query.EQ("_id", ObjectId.Parse(item.UserId.ToString())))
            ;

            var queryu = Query.And(Namequery, queryid);
            foreach (User Useritem in objUserCollection.Find(queryid))
            {
                objClass.Id           = item._id.ToString();
                objClass.FirstName    = Useritem.FirstName;
                objClass.LastName     = Useritem.LastName;
                objClass.FriendUserId = item.UserId.ToString();
                objClass.UserId       = item.FriendUserId.ToString();
                objClass.Status       = item.Status;
                //objClass.BelongsTo = Useritem.BelongsTo;
                break;
            }
            //lst.Add(objClass.FirstName + " " + objClass.LastName);
            lst.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(objClass.FirstName + " " + objClass.LastName, objClass.FriendUserId.ToString()));
        }

        /*var result = objCollection.Find(query2);
         * if (!result.Any())
         * {
         *
         * }*/
        /* var result = objCollection.Find(query);
         * if (!result.Any())
         * {
         *
         *   ////////////////////////////////////////////////////
         *   query = Query.And(
         *      Query.EQ("Status", Global.CONFIRMED), //Query.Or(
         *      Query.EQ("FriendUserId", ObjectId.Parse(uid))//, Query.EQ("UserId", UserId))
         *     );
         *   foreach (Friends item in objCollection.Find(query))
         *   {
         *
         *
         *       MongoCollection<User> objUserCollection = BaseClass.db.GetCollection<User>("c_User");
         *
         *       UserFriendsBO objClass = new UserFriendsBO();
         *       var Namequery = Query.Or(
         *        Query.Matches("FirstName", BsonRegularExpression.Create(new System.Text.RegularExpressions.Regex("^(?i)" + prefixText + ""))),
         *        Query.Matches("LastName", BsonRegularExpression.Create(new System.Text.RegularExpressions.Regex("^(?i)" + prefixText + ""))));
         *       var query2 = Query.And(
         *           Query.EQ("_id", ObjectId.Parse(item.UserId.ToString())), Namequery)
         *           ;
         *       foreach (User Useritem in objUserCollection.Find(query2))
         *       {
         *           objClass.Id = item._id.ToString();
         *           objClass.FirstName = Useritem.FirstName;
         *           objClass.LastName = Useritem.LastName;
         *           objClass.FriendUserId = item.UserId.ToString();
         *           objClass.UserId = item.FriendUserId.ToString();
         *           objClass.Status = item.Status;
         *           //objClass.BelongsTo = Useritem.BelongsTo;
         *           break;
         *       }
         *       //lst.Add(objClass.FirstName + " " + objClass.LastName);
         *       lst.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(objClass.FirstName + " " + objClass.LastName, objClass.FriendUserId.ToString()));
         *
         *   }
         * }
         * else
         * {
         *   foreach (Friends item in objCollection.Find(query))
         *   {
         *
         *
         *       MongoCollection<User> objUserCollection = BaseClass.db.GetCollection<User>("c_User");
         *
         *       UserFriendsBO objClass = new UserFriendsBO();
         *       var Namequery = Query.Or(
         *       Query.Matches("FirstName", BsonRegularExpression.Create(new System.Text.RegularExpressions.Regex("^(?i)" + prefixText + ""))),
         *       Query.Matches("LastName", BsonRegularExpression.Create(new System.Text.RegularExpressions.Regex("^(?i)" + prefixText + ""))));
         *
         *       var query2 = Query.And(
         *           Query.EQ("_id", ObjectId.Parse(item.FriendUserId.ToString())), Namequery
         *           );
         *       foreach (User Useritem in objUserCollection.Find(query2))
         *       {
         *           objClass.Id = item._id.ToString();
         *           objClass.FirstName = Useritem.FirstName;
         *           objClass.LastName = Useritem.LastName;
         *           objClass.FriendUserId = item.FriendUserId.ToString();
         *           objClass.UserId = item.UserId.ToString();
         *           objClass.Status = item.Status;
         *           break;
         *       }
         *       //lst.Add(objClass.FirstName + " " + objClass.LastName);
         *       lst.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(objClass.FirstName + " " + objClass.LastName, objClass.FriendUserId.ToString()));
         *
         *
         *   }
         *   ///////////////////////////////////////////
         *   query = Query.And(
         * Query.EQ("Status", Global.CONFIRMED), //Query.Or(
         * Query.EQ("FriendUserId", ObjectId.Parse(uid))//, Query.EQ("UserId", UserId))
         * );
         *   foreach (Friends item2 in objCollection.Find(query))
         *   {
         *
         *
         *       MongoCollection<User> objUserCollection2 = BaseClass.db.GetCollection<User>("c_User");
         *
         *       UserFriendsBO objClass2 = new UserFriendsBO();
         *       var Namequery = Query.Or(
         *       Query.Matches("FirstName", BsonRegularExpression.Create(new System.Text.RegularExpressions.Regex("^(?i)" + prefixText + ""))),
         *       Query.Matches("LastName", BsonRegularExpression.Create(new System.Text.RegularExpressions.Regex("^(?i)" + prefixText + ""))));
         *
         *       var query22 = Query.And(
         *           Query.EQ("_id", ObjectId.Parse(item2.UserId.ToString())), Namequery
         *           );
         *       foreach (User Useritem in objUserCollection2.Find(query22))
         *       {
         *           objClass2.Id = item2._id.ToString();
         *           objClass2.FirstName = Useritem.FirstName;
         *           objClass2.LastName = Useritem.LastName;
         *           objClass2.FriendUserId = item2.UserId.ToString();
         *           objClass2.UserId = item2.FriendUserId.ToString();
         *           objClass2.Status = item2.Status;
         *           break;
         *       }
         *       //lst.Add(objClass2.FirstName +" " +objClass2.LastName);
         *       lst.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(objClass2.FirstName + " " + objClass2.LastName, objClass2.FriendUserId.ToString()));
         *   }
         * }*/
        return(lst.Distinct().Take(10).ToArray());
    }