Files
Umbraco-CMS/src/Umbraco.Infrastructure/Services/Implement/DomainService.cs
Mole 2bf86acf38 V9: Place notifications in the same namespace (#10231)
* Gather all notifications in Umbraco.Cms.Core.Notifications

* Rename notifications to match convention

* Move and rename missed notifications

* Move the three remaining public notification into Umbraco.Cms.Core.Notifications
2021-05-11 14:33:49 +02:00

106 lines
3.7 KiB
C#

using System.Collections.Generic;
using Microsoft.Extensions.Logging;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Core.Persistence.Repositories;
using Umbraco.Cms.Core.Scoping;
namespace Umbraco.Cms.Core.Services.Implement
{
public class DomainService : RepositoryService, IDomainService
{
private readonly IDomainRepository _domainRepository;
public DomainService(IScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory,
IDomainRepository domainRepository)
: base(provider, loggerFactory, eventMessagesFactory)
{
_domainRepository = domainRepository;
}
public bool Exists(string domainName)
{
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
{
return _domainRepository.Exists(domainName);
}
}
public Attempt<OperationResult> Delete(IDomain domain)
{
EventMessages eventMessages = EventMessagesFactory.Get();
using (IScope scope = ScopeProvider.CreateScope())
{
var deletingNotification = new DomainDeletingNotification(domain, eventMessages);
if (scope.Notifications.PublishCancelable(deletingNotification))
{
scope.Complete();
return OperationResult.Attempt.Cancel(eventMessages);
}
_domainRepository.Delete(domain);
scope.Complete();
scope.Notifications.Publish(new DomainDeletedNotification(domain, eventMessages).WithStateFrom(deletingNotification));
}
return OperationResult.Attempt.Succeed(eventMessages);
}
public IDomain GetByName(string name)
{
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
{
return _domainRepository.GetByName(name);
}
}
public IDomain GetById(int id)
{
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
{
return _domainRepository.Get(id);
}
}
public IEnumerable<IDomain> GetAll(bool includeWildcards)
{
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
{
return _domainRepository.GetAll(includeWildcards);
}
}
public IEnumerable<IDomain> GetAssignedDomains(int contentId, bool includeWildcards)
{
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
{
return _domainRepository.GetAssignedDomains(contentId, includeWildcards);
}
}
public Attempt<OperationResult> Save(IDomain domainEntity)
{
EventMessages eventMessages = EventMessagesFactory.Get();
using (IScope scope = ScopeProvider.CreateScope())
{
var savingNotification = new DomainSavingNotification(domainEntity, eventMessages);
if (scope.Notifications.PublishCancelable(savingNotification))
{
scope.Complete();
return OperationResult.Attempt.Cancel(eventMessages);
}
_domainRepository.Save(domainEntity);
scope.Complete();
scope.Notifications.Publish(new DomainSavedNotification(domainEntity, eventMessages).WithStateFrom(savingNotification));
}
return OperationResult.Attempt.Succeed(eventMessages);
}
}
}