reactredux/webapi/DataProviders/Collections/ContentDataProvider.cs

38 lines
1.1 KiB
C#

using Microsoft.Extensions.Logging;
using DomainResults.Common;
using MongoDB.Bson.Serialization;
using MongoDB.Driver;
using DataProviders.Abstractions;
using Core.DomainObjects.Documents;
namespace DataProviders.Collections {
public interface IContentDataProvider {
(Content?, IDomainResult) Get(Guid siteId, string locale);
}
public class ContentDataProvider : CollectionDataProviderBase<Content>, IContentDataProvider {
private const string _collectionName = "content";
public ContentDataProvider(
ILogger<CollectionDataProviderBase<Content>> logger,
IMongoClient client,
IIdGenerator idGenerator,
ISessionService sessionService) : base(logger, client, idGenerator, sessionService) {
}
public (Content?, IDomainResult) Get(Guid siteId, string locale) {
var (list, result) = GetWithPredicate(x => x.SiteId == siteId
&& (x.Localization.Locale == null || x.Localization.Locale.ToLower() == locale.ToLower()), 0, 0, _collectionName);
if (!result.IsSuccess || list == null)
return (null, result);
return (list.First(), result);
}
}
}