private async Task <Users> Authenticate(LoginModel login) { try { var client = MongoDBClient.Connect(); var database = client.GetDatabase("netCoreAPI"); var collection = database.GetCollection <Users>("users"); var document = await collection.Find(u => u.Username.Equals(login.Username) && u.Password.Equals(login.Password)).FirstOrDefaultAsync(); //Console.WriteLine(document.ToString()); return(document); } catch (Exception exc) { _logger.LogError(exc, "Authenticate"); return(null); } #region Manual Authentication //Users user = null; //// Full Access Admin Example //if (login.Username == "admin" && login.Password == "admin") //{ // user = new Users { name = "Admin M", email = "*****@*****.**", birthdate = DateTime.Parse("Jan 1, 1981") }; //} //if (login.Username == "mohsen" && login.Password == "secret") //{ // //user = await _userManager.FindByEmailAsync(model.Email); // user = new Users { name = "Mohsen M", email = "*****@*****.**" }; //} #endregion }
public MongoDBRepository(MongoDBClient client) { _database = client.GetDatabase("unity"); _scores = _database.GetCollection <ScoreEntry>("scores"); _players = _database.GetCollection <Player>("players"); _maxScoreEntries = 5000; }
public MongoDbRepository(MongoDBClient client) { //Getting the database with name "game" IMongoDatabase database = client.GetDatabase("game"); //Getting collection with name "highscores" _collection = database.GetCollection <HighScore>("highscores"); }
public MongoDbRepository(MongoDBClient client) { //Getting the database with name "game2" IMongoDatabase database = client.GetDatabase("game"); //Getting collection with name "players" _collection = database.GetCollection <Player>("players"); }
public LinkingBankService(ISetting setting, IContext context, ILinkingBankCollection linkingBankCollection, ITransactionCollection transactionCollection, MongoDBClient mongoDBClient) { _Setting = setting; _Context = context; _LinkingBankCollection = linkingBankCollection; _TransactionCollection = transactionCollection; _MongoDBClient = mongoDBClient; }
public ScripletService(IOptions <AppSettings> settings, IMapper mapper, MongoDBClient mongoClient) { var client = mongoClient.MongoClient; var appSettings = settings.Value; var database = client.GetDatabase(appSettings.MongoDB.DatabaseName); _scriplets = database.GetCollection <Scriplet>("Scriplets"); _mongoClient = mongoClient.MongoClient; _settings = settings?.Value; _mapper = mapper; }
public EmployeeService(ISetting setting, IUserCollection userCollection, IContext context, MongoDBClient mongoDBClient , ITransactionCollection transactionCollection, ITransferCollection transferCollection, ILinkingBankCollection linkingBankCollection, IEncrypt Encrypt) { _Setting = setting; _UserCollection = userCollection; _Context = context; _MongoDBClient = mongoDBClient; _TransferCollection = transferCollection; _TransactionCollection = transactionCollection; _LinkingBankCollection = linkingBankCollection; _Encrypt = Encrypt; }
public DeptReminderService(ISetting setting, IUserCollection userCollection, IDeptReminderCollection deptReminderCollection , ILinkingBankCollection linkingBankCollection, MongoDBClient mongoDBClient, IContext context, ITransferCollection transferCollection , ITransactionCollection transactionCollection) { _UserCollection = userCollection; _Setting = setting; _DeptReminderCollection = deptReminderCollection; _LinkingBankCollection = linkingBankCollection; _MongoDBClient = mongoDBClient; _Context = context; _TransferCollection = transferCollection; _TransactionCollection = transactionCollection; }
public void mainTest() { MongoDBClient mongo; mongo = new MongoDBClient(); string jsonQuery = "{ sexo : 'Feminino', desempregado : true }"; List <Curriculos> results = mongo.GetQuery(jsonQuery); foreach (Curriculos cur in results) { Debugger.Break(); } Assert.Fail(); }
public async Task SubscribeAsync() { IDatabase mongo = new MongoDBClient(); var mqttClient = MqttClient.CreateAsync(_hostname).Result; var sess = mqttClient.ConnectAsync().Result; await mqttClient.SubscribeAsync(_topic, MqttQualityOfService.ExactlyOnce); mqttClient.MessageStream.Subscribe(msg => { string msgString = Encoding.UTF8.GetString(msg.Payload); Console.WriteLine(String.Format("[{0}] {1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff"), msgString)); Message messageObject = JsonConvert.DeserializeObject <Message>(msgString); mongo.InsertElectricityReadingToDatabase(messageObject); }); }
public async Task <IActionResult> CheckUserAsync([FromBody] LoginModel login) { if (ModelState.IsValid) { try { var client = MongoDBClient.Connect(); var database = client.GetDatabase("netCoreAPI"); var collection = database.GetCollection <BsonDocument>("users"); var count = collection.CountDocuments(new BsonDocument()); // we don’t need all the data contained in a document. var projection = Builders <BsonDocument> .Projection.Exclude("_id"); var document = await collection.Find(new BsonDocument()).Project(projection).FirstOrDefaultAsync(); //Console.WriteLine(document.ToString()); _logger.LogInformation("CheckUserAsync \n" + document.ToString()); //var doc = document.ToJson(typeof(Users)); var json = Json(document.ToString()); // var j = Json(doc); if (document != null) // result.Succeeded { //var user = Json(document); //var jsonWriterSettings = new MongoDB.Bson.IO.JsonWriterSettings { OutputMode = MongoDB.Bson.IO.JsonOutputMode.Strict }; //var user1 = document.ToJson(jsonWriterSettings); object val = BsonTypeMapper.MapToDotNetValue(document); string jsonString = JsonConvert.SerializeObject(val); var user = JsonConvert.DeserializeObject <Users>(jsonString); return(Ok(new { user })); } return(Unauthorized()); } catch (Exception exc) { _logger.LogError(exc, "CheckUserAsync"); return(Json(exc.Message)); } } return(BadRequest(ModelState)); }
public MongoTransactionCollection(MongoDBClient mongoDBClient) { _MongoDBClient = mongoDBClient; _Collection = mongoDBClient.GetCollection <Transaction>("Transactions"); }
public MongoDeptReminderCollection(MongoDBClient mongoDBClient) { _MongoDBClient = mongoDBClient; _Collection = mongoDBClient.GetCollection <DeptReminder>("DeptReminders"); }
public MongoUserCollection(MongoDBClient mongoDBClient) { _MongoDBClient = mongoDBClient; _Collection = mongoDBClient.GetCollection <User>("Users"); }
public MongoTransferCollection(MongoDBClient mongoDBClient) { _MongoDBClient = mongoDBClient; _Collection = mongoDBClient.GetCollection <Transfer>("Transfers"); }
public MongoLinkingBankCollection(MongoDBClient mongoDBClient) { _MongoDBClient = mongoDBClient; _Collection = mongoDBClient.GetCollection <LinkingBank>("LinkingBanks"); }
public MongoDBRepository(MongoDBClient client) { _database = client.GetDatabase("game"); _collection = _database.GetCollection <Player>("players"); }
public MongoDbRepository(MongoDBClient client) { IMongoDatabase database = client.GetDatabase("gameapi"); _collection = database.GetCollection <Player>("players"); }