38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
using Microsoft.Extensions.Logging;
|
|
|
|
using DomainResults.Common;
|
|
|
|
using MongoDB.Bson.Serialization;
|
|
using MongoDB.Driver;
|
|
using DataProviders.Collections.Abstractions;
|
|
using DomainObjects.Documents.Content;
|
|
|
|
namespace DataProviders.Collections
|
|
{
|
|
|
|
public interface IContentDataProvider {
|
|
(ContentDocument?, IDomainResult) Get(Guid siteId);
|
|
}
|
|
|
|
public class ContentDataProvider : CollectionDataProviderBase<ContentDocument>, IContentDataProvider {
|
|
|
|
private const string _databaseName = "reactredux";
|
|
private const string _collectionName = "content";
|
|
public ContentDataProvider(
|
|
ILogger<CollectionDataProviderBase<ContentDocument>> logger,
|
|
IMongoClient client,
|
|
IIdGenerator idGenerator,
|
|
ISessionService sessionService) : base(logger, client, idGenerator, sessionService, _databaseName, _collectionName) {
|
|
}
|
|
|
|
public (ContentDocument?, IDomainResult) Get(Guid siteId) {
|
|
var (list, result) = GetWithPredicate(x => x.Id == siteId, x => x);
|
|
|
|
if (!result.IsSuccess || list == null)
|
|
return (null, result);
|
|
|
|
return (list.First(), result);
|
|
}
|
|
}
|
|
}
|