30 lines
807 B
C#
30 lines
807 B
C#
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using GameAuthApi.Models;
|
|
using Microsoft.Extensions.Configuration;
|
|
using MongoDB.Driver;
|
|
|
|
namespace GameAuthApi.Services;
|
|
|
|
public class SpawnableService
|
|
{
|
|
private readonly IMongoCollection<Spawnable> _spawnables;
|
|
|
|
public SpawnableService(IConfiguration config)
|
|
{
|
|
var client = new MongoClient(config["MongoDB:ConnectionString"]);
|
|
var db = client.GetDatabase(config["MongoDB:DatabaseName"]);
|
|
_spawnables = db.GetCollection<Spawnable>("Spawnables");
|
|
}
|
|
|
|
public async Task CreateAsync(Spawnable spawnable)
|
|
{
|
|
await _spawnables.InsertOneAsync(spawnable);
|
|
}
|
|
|
|
public async Task<List<Spawnable>> GetAllAsync()
|
|
{
|
|
return await _spawnables.Find(_ => true).ToListAsync();
|
|
}
|
|
}
|