public static List <User> GetUsers(int numberUsersToReturn = 999999, string databaseName = null)
        {
            //var db = InitDB.GetMongoDBClient().GetDatabase("followInstagram");
            var db = InitDB.GetMongoDBClient().GetDatabase(databaseName);


            var         collectionLocation = db.GetCollection <User>("locationUsers");
            List <User> usersLocationList  = collectionLocation.Find("{isUnFollow: false}").Sort("{dateFollowing: 1}").Limit(numberUsersToReturn).ToList();

            var collectionHashtag = db.GetCollection <User>("hashtagUsers");
            //List<User> usersHashtagList = collectionHashtag.Find("{isUnFollow: false}").Sort("{dateFollowing: 1}").ToList();
            List <User> usersHashtagList = collectionHashtag.Find("{isUnFollow: false}").ToList();


            // usersHashtagList.Sort((x, y) => DateTime.Compare(x.dateFollowing, y.dateFollowing));

            //List<User> usersHashtagList = collectionHashtag.Find("{isUnFollow: false}").Sort("{dateFollowing: 1}").Limit(numberUsersToReturn).ToList();
            //List<User> usersHashtagList = collectionHashtag.Find("{isUnFollow : true}").Sort("{dateFollowing: -1}").Limit(numberUsersToReturn).ToList();

            var usersList = usersLocationList.Concat(usersHashtagList).ToList();

            Message.Info(string.Format("- Following users got succesfully ({0}). [CRUDMongo.GetUsers()]", usersList.Count()));

            return(usersList);
        }
        public static void CreateUser(List <User> usersList, string typeSearch, string databaseName = null)
        {
            //var db = InitDB.GetMongoDBClient().GetDatabase("followInstagram");
            var db = InitDB.GetMongoDBClient().GetDatabase(databaseName);


            if (typeSearch == "location")
            {
                var collection = db.GetCollection <User>("locationUsers");
                foreach (var user in usersList)
                {
                    collection.InsertOne(user);
                }
            }
            else if (typeSearch == "userName")
            {
                var collection = db.GetCollection <User>("nameUsers");
                foreach (var user in usersList)
                {
                    collection.InsertOne(user);
                }
            }
            else if (typeSearch == "hashtag")
            {
                var collection = db.GetCollection <User>("hashtagUsers");
                foreach (var user in usersList)
                {
                    collection.InsertOne(user);
                }
            }

            Message.Info("- Users stored succesfully.");
        }
        public static void CreateRequeriment(Requeriment requeriment, string databaseName = null)
        {
            //var db = InitDB.GetMongoDBClient().GetDatabase("followInstagram");
            var db = InitDB.GetMongoDBClient().GetDatabase(databaseName);

            var collection = db.GetCollection <Requeriment>("requeriments");

            collection.InsertOne(requeriment);

            Message.Info("- Requeriment stored succesfully.");
        }
        /*
         * public static void RemoveUser(List<User> usersList)
         * {
         *  var db = InitDB.GetMongoDBClient().GetDatabase("JOBS");
         *
         *  var collection = db.GetCollection<User>("jobOffers");
         *
         *  foreach (var user in usersList)
         *  {
         *      collection.DeleteOne(u => u.Id == user.Id);
         *  }
         *  //collection.DeleteOne(a => a.Id==id);
         * }*/

        public static void CreatePublication(List <Publication> publicationList, string databaseName = null)
        {
            //var db = InitDB.GetMongoDBClient().GetDatabase("followInstagram");
            var db = InitDB.GetMongoDBClient().GetDatabase(databaseName);

            var collection = db.GetCollection <Publication>("Publications");

            foreach (var publication in publicationList)
            {
                collection.InsertOne(publication);
            }
        }
        /// <summary>
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public static List <User> GetUsersByUserName(string username, string databaseName = null)
        {
            //var db = InitDB.GetMongoDBClient().GetDatabase("followInstagram");
            var db = InitDB.GetMongoDBClient().GetDatabase(databaseName);

            var         collectionLocation = db.GetCollection <User>("locationUsers");
            List <User> usersLocationList  = collectionLocation.Find("{Name: '" + username + "'}").Sort("{dateFollowing: 1}").Limit(2222).ToList();


            var         collectionHashtag = db.GetCollection <User>("hashtagUsers");
            List <User> usersHashtagList  = collectionHashtag.Find("{Name: '" + username + "'}").Sort("{dateFollowing: 1}").ToList();

            var usersList = usersLocationList.Concat(usersHashtagList).ToList();

            return(usersList);
        }
        /// <summary>
        /// Return the users of database that fulfill the attribute(json format) passed by parameter
        /// </summary>
        /// <param name="attribute"></param>
        /// <returns></returns>
        public static List <User> GetUsersByAttribute(string attribute, string databaseName = null)
        {
            //var db = InitDB.GetMongoDBClient().GetDatabase("followInstagram");
            var db = InitDB.GetMongoDBClient().GetDatabase(databaseName);

            var         collectionLocation = db.GetCollection <User>("locationUsers");
            List <User> usersLocationList  = collectionLocation.Find(attribute).Sort("{dateFollowing: 1}").Limit(2222).ToList();

            var         collectionHashtag = db.GetCollection <User>("hashtagUsers");
            List <User> usersHashtagList  = collectionHashtag.Find(attribute).Sort("{dateFollowing: 1}").ToList();

            Message.Info("- Users with attribute: '" + attribute + "' got succesfully.");

            var usersList = usersLocationList.Concat(usersHashtagList).ToList();

            return(usersList);
        }
        public static void UpdateUsers(List <User> usersList, string databaseName = null)
        {
            //var db = InitDB.GetMongoDBClient().GetDatabase("followInstagram");
            var db = InitDB.GetMongoDBClient().GetDatabase(databaseName);

            foreach (var user in usersList)
            {
                if (user.IsLocationSearch)
                {
                    var collection = db.GetCollection <User>("locationUsers");
                    collection.ReplaceOne(u => u.Id == user.Id, user);
                }

                else if (user.IsHashtagSearch)
                {
                    var collection = db.GetCollection <User>("hashtagUsers");
                    collection.ReplaceOne(u => u.Id == user.Id, user);
                }
            }


            Message.Info("- Users updated succesfully.");
        }
        public static List <User> GetAllUsers(int numberUsersToReturn = 5555, string databaseName = null)
        {
            //var db = InitDB.GetMongoDBClient().GetDatabase("followInstagram");
            var db = InitDB.GetMongoDBClient().GetDatabase(databaseName);


            var         collectionLocation = db.GetCollection <User>("locationUsers");
            List <User> usersLocationList  = collectionLocation.Find("{isUnFollow: true}").Sort("{dateFollowing: 1}").Limit(numberUsersToReturn).ToList();


            var         collectionHashtag = db.GetCollection <User>("hashtagUsers");
            List <User> usersHashtagList  = collectionHashtag.Find("{isUnFollow: true}").Sort("{dateFollowing: 1}").ToList();
            // List<User> usersHashtagList = collectionHashtag.Find("{isUnFollow: false}").Sort("{dateFollowing: 1}").Limit(numberUsersToReturn).ToList();
            //List<User> usersHashtagList = collectionHashtag.Find("{isUnFollow : true}").Sort("{dateFollowing: -1}").Limit(numberUsersToReturn).ToList();



            //Message.Info("- Users got succesfully.");

            var usersList = usersLocationList.Concat(usersHashtagList).ToList();

            return(usersList);
        }