Updated model and Repository class
This commit is contained in:
+2
-2
@@ -9,8 +9,8 @@ namespace TextSender_API.Models;
|
|||||||
public class User
|
public class User
|
||||||
{
|
{
|
||||||
#region Properties
|
#region Properties
|
||||||
[BsonElement("_id")]
|
// [BsonElement("_id")]
|
||||||
public ObjectId UserID { get; set; }
|
public ObjectId Id { get; set; }
|
||||||
[BsonElement("firstname")]
|
[BsonElement("firstname")]
|
||||||
public string? Firstname { get; set; }
|
public string? Firstname { get; set; }
|
||||||
[BsonElement("lastname")]
|
[BsonElement("lastname")]
|
||||||
|
|||||||
@@ -3,15 +3,40 @@ using System;
|
|||||||
using MongoDB.Bson;
|
using MongoDB.Bson;
|
||||||
using MongoDB.Driver;
|
using MongoDB.Driver;
|
||||||
|
|
||||||
|
using TextSender_API.Models;
|
||||||
|
|
||||||
namespace TextSender_API.Repositories;
|
namespace TextSender_API.Repositories;
|
||||||
|
|
||||||
|
|
||||||
public class UserRepository
|
public class UserRepository
|
||||||
{
|
{
|
||||||
#region Properties
|
#region Fields
|
||||||
|
private string _connectionString;
|
||||||
|
private string _databaseName;
|
||||||
|
private string _tableName;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region Constructors
|
#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
|
#endregion
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user