using System; using System.Collections.Generic; using Microsoft.Extensions.Logging; 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.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Factories; using Umbraco.Cms.Infrastructure.Persistence.Querying; using Umbraco.Core.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement { /// /// Represents the NPoco implementation of . /// internal class ConsentRepository : EntityRepositoryBase, IConsentRepository { /// /// Initializes a new instance of the class. /// public ConsentRepository(IScopeAccessor scopeAccessor, AppCaches cache, ILogger logger) : base(scopeAccessor, cache, logger) { } /// protected override Guid NodeObjectTypeId => throw new NotSupportedException(); /// protected override IConsent PerformGet(int id) { throw new NotSupportedException(); } /// protected override IEnumerable PerformGetAll(params int[] ids) { throw new NotSupportedException(); } /// protected override IEnumerable PerformGetByQuery(IQuery query) { var sqlClause = Sql().Select().From(); var translator = new SqlTranslator(sqlClause, query); var sql = translator.Translate().OrderByDescending(x => x.CreateDate); return ConsentFactory.BuildEntities(Database.Fetch(sql)); } /// protected override Sql GetBaseQuery(bool isCount) { throw new NotSupportedException(); } /// protected override string GetBaseWhereClause() { throw new NotSupportedException(); } /// protected override IEnumerable GetDeleteClauses() { throw new NotSupportedException(); } /// protected override void PersistNewItem(IConsent entity) { entity.AddingEntity(); var dto = ConsentFactory.BuildDto(entity); Database.Insert(dto); entity.Id = dto.Id; entity.ResetDirtyProperties(); } /// protected override void PersistUpdatedItem(IConsent entity) { entity.UpdatingEntity(); var dto = ConsentFactory.BuildDto(entity); Database.Update(dto); entity.ResetDirtyProperties(); IsolatedCache.Clear(RepositoryCacheKeys.GetKey(entity.Id)); } /// public void ClearCurrent(string source, string context, string action) { var sql = Sql() .Update(u => u.Set(x => x.Current, false)) .Where(x => x.Source == source && x.Context == context && x.Action == action && x.Current); Database.Execute(sql); } } }