Refactoring and password hashing
This commit is contained in:
@@ -1,61 +0,0 @@
|
||||
using System;
|
||||
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Driver;
|
||||
|
||||
using TextSender_API.Models;
|
||||
|
||||
namespace TextSender_API.Repositories;
|
||||
|
||||
|
||||
public class UserRepository
|
||||
{
|
||||
#region Fields
|
||||
private string _connectionString;
|
||||
private string _databaseName;
|
||||
private string _tableName;
|
||||
private readonly IMongoCollection<User> _bookCollection;
|
||||
#endregion
|
||||
|
||||
|
||||
#region Constructors
|
||||
public UserRepository(string connectionString)
|
||||
{
|
||||
this._connectionString = connectionString;
|
||||
this._databaseName = "TextSender";
|
||||
this._tableName = "Users";
|
||||
var client = this.InitializeClient();
|
||||
this._bookCollection = client.GetDatabase(this._databaseName).GetCollection<User>(this._tableName);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Metods
|
||||
public void CreateUser(User user)
|
||||
{
|
||||
this._bookCollection.InsertOne(user);
|
||||
var i = 0;
|
||||
}
|
||||
|
||||
public List<User> RetrieveAllUsers()
|
||||
{
|
||||
return this._bookCollection.Find(_ => true).ToList();
|
||||
}
|
||||
|
||||
public void Update(User user)
|
||||
{
|
||||
var filter = Builders<User>.Filter.Eq(u => u.Id, user.Id);
|
||||
this._bookCollection.ReplaceOne(filter, user);
|
||||
}
|
||||
|
||||
public void Delete(User user)
|
||||
{
|
||||
var filter = Builders<User>.Filter.Eq(u => u.Id, user.Id);
|
||||
this._bookCollection.DeleteOne(filter);
|
||||
}
|
||||
|
||||
private MongoClient InitializeClient()
|
||||
{
|
||||
return new MongoClient(this._connectionString);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
using System;
|
||||
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Driver;
|
||||
|
||||
using TextSender_API.Models;
|
||||
|
||||
namespace TextSender_API.Repositories;
|
||||
|
||||
|
||||
public class UsersRepository
|
||||
{
|
||||
#region Fields
|
||||
private string _connectionString;
|
||||
private string _databaseName;
|
||||
private string _tableName;
|
||||
private readonly IMongoCollection<User> _bookCollection;
|
||||
#endregion
|
||||
|
||||
|
||||
#region Constructors
|
||||
public UsersRepository(string connectionString)
|
||||
{
|
||||
this._connectionString = connectionString;
|
||||
this._databaseName = "TextSender";
|
||||
this._tableName = "users";
|
||||
var client = this.InitializeClient();
|
||||
this._bookCollection = client.GetDatabase(this._databaseName).GetCollection<User>(this._tableName);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Metods
|
||||
public void CreateUser(User user)
|
||||
{
|
||||
this._bookCollection.InsertOne(user);
|
||||
}
|
||||
|
||||
public List<User> RetrieveAllUsers()
|
||||
{
|
||||
return this._bookCollection.Find(_ => true).ToList();
|
||||
}
|
||||
|
||||
public void Update(User user)
|
||||
{
|
||||
var filter = Builders<User>.Filter.Eq(u => u.Id, user.Id);
|
||||
this._bookCollection.ReplaceOne(filter, user);
|
||||
}
|
||||
|
||||
public void Delete(User user)
|
||||
{
|
||||
var filter = Builders<User>.Filter.Eq(u => u.Id, user.Id);
|
||||
this._bookCollection.DeleteOne(filter);
|
||||
}
|
||||
|
||||
private MongoClient InitializeClient()
|
||||
{
|
||||
return new MongoClient(this._connectionString);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
public class SaltRepository
|
||||
{
|
||||
#region Fields
|
||||
private string _connectionString;
|
||||
private string _databaseName;
|
||||
private string _tableName;
|
||||
private readonly IMongoCollection<Salt> _bookCollection;
|
||||
#endregion
|
||||
|
||||
|
||||
#region Constructors
|
||||
public SaltRepository(string connectionString)
|
||||
{
|
||||
this._connectionString = connectionString;
|
||||
this._databaseName = "TextSender";
|
||||
this._tableName = "salt";
|
||||
var client = this.InitializeClient();
|
||||
this._bookCollection = client.GetDatabase(this._databaseName).GetCollection<Salt>(this._tableName);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Metods
|
||||
public void Create(Salt salt)
|
||||
{
|
||||
this._bookCollection.InsertOne(salt);
|
||||
}
|
||||
|
||||
public List<Salt> RetrieveAll()
|
||||
{
|
||||
return this._bookCollection.Find(_ => true).ToList();
|
||||
}
|
||||
|
||||
public void Update(Salt salt)
|
||||
{
|
||||
var filter = Builders<Salt>.Filter.Eq(u => u.Id, salt.Id);
|
||||
this._bookCollection.ReplaceOne(filter, salt);
|
||||
}
|
||||
|
||||
public void Delete(Salt salt)
|
||||
{
|
||||
var filter = Builders<Salt>.Filter.Eq(u => u.Id, salt.Id);
|
||||
this._bookCollection.DeleteOne(filter);
|
||||
}
|
||||
|
||||
private MongoClient InitializeClient()
|
||||
{
|
||||
return new MongoClient(this._connectionString);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user