Пример #1
0
        public UsersDbContext(IOptions <MongoDBAppSettings> config)
        {
            // Uses the config.
            Config = config.Value;

            // Gets values out of the config.
            var MongoDatabaseName     = Config.MongoUserDatabaseName;
            var MongoAuthDatabaseName = Config.MongoAuthDatabaseName;
            var MongoUsername         = Config.MongoUsername;
            var MongoPassword         = Config.MongoPassword;
            var MongoPort             = Config.MongoPort;
            var MongoHost             = Config.MongoHost;

            // Creates a model to log into the mongodb.
            //MongoCredential credential = MongoCredential.CreateCredential
            //(MongoAuthDatabaseName,
            // MongoUsername,
            // MongoPassword);

            // Connects to the Db.
            var settings = new MongoClientSettings
            {
                //Credential = credential,
                Server = new MongoServerAddress(MongoHost, Convert.ToInt32(MongoPort))
            };

            _client = new MongoClient(settings);

            // Gets the corrext db.
            _database = _client.GetDatabase("Users");
        }
        public ProjectDbContext(IOptions <MongoDBAppSettings> config)
        {
            // Uses the config.
            Config = config.Value;

            // Gets values out of the config.
            var MongoDatabaseName     = Config.MongoUserDatabaseName;
            var MongoAuthDatabaseName = Config.MongoAuthDatabaseName;
            var MongoUsername         = Config.MongoUsername;
            var MongoPassword         = Config.MongoPassword;
            var MongoPort             = Config.MongoPort;
            var MongoHost             = Config.MongoHost;

            // Creates a model to log into the mongodb.
            //MongoCredential credential = MongoCredential.CreateCredential
            //(MongoAuthDatabaseName,
            // MongoUsername,
            // MongoPassword);

            // Connects to the Db.
            var settings = new MongoClientSettings
            {
                //Credential = credential,
                Server = new MongoServerAddress(MongoHost, Convert.ToInt32(MongoPort))
            };

            _client = new MongoClient(settings);

            // Gets the corrext db.
            _database = _client.GetDatabase(config.Value.MongoDatabaseName);

            //if (IsEmpty())
            //{
            //    // TODO: insert template project instead of empty project.
            //    ProjectsCollection.InsertOne(new ProjectModel() { Name = "Can Be Deleted After Inserting Template" });
            //}
        }