40 lines
1.1 KiB
C#
40 lines
1.1 KiB
C#
using Core.DomainObjects.Documents;
|
|
using DataProviders.Abstractions;
|
|
using DomainResults.Common;
|
|
using Microsoft.Extensions.Logging;
|
|
using MongoDB.Bson.Serialization;
|
|
using MongoDB.Driver;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace DataProviders {
|
|
|
|
public interface IContentDataProvider {
|
|
(Content?, IDomainResult) Get(Guid id);
|
|
}
|
|
|
|
|
|
public class ContentDataProvider : DataProviderBase<Content>, IContentDataProvider {
|
|
|
|
private const string _collectionName = "content";
|
|
public ContentDataProvider(
|
|
ILogger<DataProviderBase<Content>> logger,
|
|
IMongoClient client,
|
|
IIdGenerator idGenerator,
|
|
ISessionService sessionService) : base(logger, client, idGenerator, sessionService) {
|
|
}
|
|
|
|
public (Content?, IDomainResult) Get(Guid id) {
|
|
var (list, result) = GetWithPredicate(x => x.Id == id, _collectionName);
|
|
|
|
if (!result.IsSuccess || list == null || list.Count == 0)
|
|
return (null, result);
|
|
|
|
return (list.First(), result);
|
|
}
|
|
}
|
|
}
|