2021-05-29 17:02:16 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using MongoDB.Driver;
|
|
|
|
|
using Retroactiune.Models;
|
|
|
|
|
using Retroactiune.Settings;
|
|
|
|
|
|
|
|
|
|
namespace Retroactiune.Services
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Service that simplifies access to the database for managing FeedbackReceiver items.
|
|
|
|
|
/// <see cref="FeedbackReceiver"/>
|
|
|
|
|
/// </summary>
|
2021-05-29 18:12:36 +00:00
|
|
|
|
public class FeedbackReceiverService : IFeedbackReceiverService
|
2021-05-29 17:02:16 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly IMongoCollection<FeedbackReceiver> _collection;
|
|
|
|
|
private readonly ILogger<FeedbackReceiverService> _logger;
|
|
|
|
|
|
|
|
|
|
public FeedbackReceiverService(IMongoDbSettings settings, ILogger<FeedbackReceiverService> logger)
|
|
|
|
|
{
|
|
|
|
|
var client = new MongoClient(settings.ConnectionString);
|
|
|
|
|
var database = client.GetDatabase(settings.DatabaseName);
|
|
|
|
|
_collection = database.GetCollection<FeedbackReceiver>(settings.FeedbackReceiverCollectionName);
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-29 18:12:36 +00:00
|
|
|
|
public async Task CreateManyAsync(IEnumerable<FeedbackReceiver> items)
|
2021-05-29 17:02:16 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await _collection.InsertManyAsync(items);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
throw new GenericServiceException($"Operation failed: {e.Message}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|