Files
Umbraco-CMS/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ConsentRepository.cs

101 lines
3.3 KiB
C#
Raw Normal View History

2020-12-22 10:30:16 +11:00
using System;
2018-03-22 11:24:12 +01:00
using System.Collections.Generic;
2020-09-17 09:42:55 +02:00
using Microsoft.Extensions.Logging;
2018-03-22 11:24:12 +01:00
using NPoco;
using Umbraco.Cms.Core.Cache;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Persistence.Querying;
using Umbraco.Cms.Core.Persistence.Repositories;
using Umbraco.Cms.Core.Scoping;
using Umbraco.Cms.Infrastructure.Persistence.Dtos;
using Umbraco.Cms.Infrastructure.Persistence.Factories;
using Umbraco.Cms.Infrastructure.Persistence.Querying;
using Umbraco.Extensions;
2018-03-22 11:24:12 +01:00
namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
2018-03-22 11:24:12 +01:00
{
/// <summary>
/// Represents the NPoco implementation of <see cref="IConsentRepository"/>.
/// </summary>
2020-12-22 10:30:16 +11:00
internal class ConsentRepository : EntityRepositoryBase<int, IConsent>, IConsentRepository
2018-03-22 11:24:12 +01:00
{
/// <summary>
/// Initializes a new instance of the <see cref="ConsentRepository"/> class.
/// </summary>
2020-09-17 09:42:55 +02:00
public ConsentRepository(IScopeAccessor scopeAccessor, AppCaches cache, ILogger<ConsentRepository> logger)
2018-03-22 11:24:12 +01:00
: base(scopeAccessor, cache, logger)
{ }
/// <inheritdoc />
protected override IConsent PerformGet(int id)
{
throw new NotSupportedException();
}
/// <inheritdoc />
protected override IEnumerable<IConsent> PerformGetAll(params int[] ids)
{
throw new NotSupportedException();
}
/// <inheritdoc />
protected override IEnumerable<IConsent> PerformGetByQuery(IQuery<IConsent> query)
{
var sqlClause = Sql().Select<ConsentDto>().From<ConsentDto>();
var translator = new SqlTranslator<IConsent>(sqlClause, query);
var sql = translator.Translate().OrderByDescending<ConsentDto>(x => x.CreateDate);
return ConsentFactory.BuildEntities(Database.Fetch<ConsentDto>(sql));
}
/// <inheritdoc />
protected override Sql<ISqlContext> GetBaseQuery(bool isCount)
{
throw new NotSupportedException();
}
/// <inheritdoc />
protected override string GetBaseWhereClause()
{
throw new NotSupportedException();
}
/// <inheritdoc />
protected override IEnumerable<string> GetDeleteClauses()
{
throw new NotSupportedException();
}
/// <inheritdoc />
protected override void PersistNewItem(IConsent entity)
{
entity.AddingEntity();
2018-03-22 11:24:12 +01:00
var dto = ConsentFactory.BuildDto(entity);
Database.Insert(dto);
entity.Id = dto.Id;
entity.ResetDirtyProperties();
}
/// <inheritdoc />
protected override void PersistUpdatedItem(IConsent entity)
{
entity.UpdatingEntity();
2018-03-22 11:24:12 +01:00
var dto = ConsentFactory.BuildDto(entity);
Database.Update(dto);
entity.ResetDirtyProperties();
2019-01-17 11:01:23 +01:00
IsolatedCache.Clear(RepositoryCacheKeys.GetKey<IConsent>(entity.Id));
2018-03-22 11:24:12 +01:00
}
/// <inheritdoc />
public void ClearCurrent(string source, string context, string action)
{
var sql = Sql()
.Update<ConsentDto>(u => u.Set(x => x.Current, false))
.Where<ConsentDto>(x => x.Source == source && x.Context == context && x.Action == action && x.Current);
Database.Execute(sql);
}
}
}