69 lines
1.8 KiB
C#
69 lines
1.8 KiB
C#
using MongoDB.Driver;
|
|
|
|
using TextSender_API.Models;
|
|
|
|
namespace TextSender_API.Repositories;
|
|
|
|
|
|
public class ContactCreationQueueepository : BaseRepository
|
|
{
|
|
#region Fields
|
|
private readonly IMongoCollection<ContactCreationQueue> _bookCollection;
|
|
#endregion
|
|
|
|
|
|
#region Constructors
|
|
public ContactCreationQueueepository(string connectionString)
|
|
{
|
|
this._connectionString = connectionString;
|
|
this._tableName = "contactCreationQueue";
|
|
var client = this.InitializeClient();
|
|
this._bookCollection = client.GetDatabase(this._databaseName).GetCollection<ContactCreationQueue>(this._tableName);
|
|
}
|
|
#endregion
|
|
|
|
#region Metods
|
|
public Tuple<bool, ContactCreationQueue> Exists(string id)
|
|
{
|
|
var allQueue = this.RetrieveAll();
|
|
var result = allQueue.FirstOrDefault(q => q.Id!.Equals(id));
|
|
|
|
if (result != null)
|
|
{
|
|
return new Tuple<bool, ContactCreationQueue>(true, result!);
|
|
}
|
|
else
|
|
{
|
|
return new Tuple<bool, ContactCreationQueue>(false, new ContactCreationQueue());
|
|
}
|
|
}
|
|
|
|
public void Create(ContactCreationQueue queue)
|
|
{
|
|
this._bookCollection.InsertOne(queue);
|
|
}
|
|
|
|
public List<ContactCreationQueue> RetrieveAll()
|
|
{
|
|
return this._bookCollection.Find(_ => true).ToList();
|
|
}
|
|
|
|
public void Update(ContactCreationQueue queue)
|
|
{
|
|
var filter = Builders<ContactCreationQueue>.Filter.Eq(q => q.Id, queue.Id);
|
|
this._bookCollection.ReplaceOne(filter, queue);
|
|
}
|
|
|
|
public void Delete(ContactCreationQueue queue)
|
|
{
|
|
var filter = Builders<ContactCreationQueue>.Filter.Eq(q => q.Id, queue.Id);
|
|
this._bookCollection.DeleteOne(filter);
|
|
}
|
|
|
|
private MongoClient InitializeClient()
|
|
{
|
|
return new MongoClient(this._connectionString);
|
|
}
|
|
#endregion
|
|
}
|