Updated model and Repository class
This commit is contained in:
+2
-2
@@ -9,8 +9,8 @@ namespace TextSender_API.Models;
|
||||
public class User
|
||||
{
|
||||
#region Properties
|
||||
[BsonElement("_id")]
|
||||
public ObjectId UserID { get; set; }
|
||||
// [BsonElement("_id")]
|
||||
public ObjectId Id { get; set; }
|
||||
[BsonElement("firstname")]
|
||||
public string? Firstname { get; set; }
|
||||
[BsonElement("lastname")]
|
||||
|
||||
@@ -3,15 +3,40 @@ using System;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Driver;
|
||||
|
||||
using TextSender_API.Models;
|
||||
|
||||
namespace TextSender_API.Repositories;
|
||||
|
||||
|
||||
public class UserRepository
|
||||
{
|
||||
#region Properties
|
||||
#region Fields
|
||||
private string _connectionString;
|
||||
private string _databaseName;
|
||||
private string _tableName;
|
||||
#endregion
|
||||
|
||||
|
||||
#region Constructors
|
||||
public UserRepository(string connectionString)
|
||||
{
|
||||
this._connectionString = connectionString;
|
||||
this._databaseName = "TextSender";
|
||||
this._tableName = "Users";
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Metods
|
||||
public void CreateUser(User user)
|
||||
{
|
||||
var client = this.InitializeClient();
|
||||
|
||||
var coll = client.GetDatabase(this._databaseName).GetCollection<User>(this._tableName);
|
||||
coll.InsertOne(user);
|
||||
}
|
||||
private MongoClient InitializeClient()
|
||||
{
|
||||
return new MongoClient(this._connectionString);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user