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;
|
2021-02-09 10:22:42 +01:00
|
|
|
using Umbraco.Cms.Core.Cache;
|
|
|
|
|
using Umbraco.Cms.Core.Models;
|
|
|
|
|
using Umbraco.Cms.Core.Persistence.Querying;
|
|
|
|
|
using Umbraco.Cms.Core.Persistence.Repositories;
|
2021-02-15 11:41:12 +01:00
|
|
|
using Umbraco.Cms.Core.Scoping;
|
2021-02-12 13:36:50 +01:00
|
|
|
using Umbraco.Cms.Infrastructure.Persistence.Dtos;
|
|
|
|
|
using Umbraco.Cms.Infrastructure.Persistence.Factories;
|
|
|
|
|
using Umbraco.Cms.Infrastructure.Persistence.Querying;
|
2021-02-09 13:32:34 +01:00
|
|
|
using Umbraco.Extensions;
|
2018-03-22 11:24:12 +01:00
|
|
|
|
2021-02-12 13:36:50 +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)
|
|
|
|
|
{
|
2019-06-28 09:19:11 +02:00
|
|
|
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)
|
|
|
|
|
{
|
2019-06-28 09:19:11 +02:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|