22 lines
665 B
C#
22 lines
665 B
C#
using Microsoft.Extensions.Configuration;
|
|
using models.Core;
|
|
using MongoDB.Driver;
|
|
|
|
namespace data.Tickets;
|
|
|
|
public class Save(IConfiguration config)
|
|
{
|
|
public void Execute(Ticket ticket)
|
|
{
|
|
if (String.IsNullOrEmpty(config.GetSection("Mongo:ConnectionString").Value))
|
|
{
|
|
throw new Exception("No MongoDB connection string");
|
|
}
|
|
|
|
var client = new MongoClient(config.GetSection("Mongo:ConnectionString").Value);
|
|
var database = client.GetDatabase(config.GetSection("Mongo:Database").Value);
|
|
var collection = database.GetCollection<Ticket>("tickets");
|
|
|
|
collection.InsertOne(ticket);
|
|
}
|
|
} |