/// <summary>
        /// Deletes the section
        /// </summary>
        public void DeleteSection(Section section)
        {
            lock (Locker)
            {
                //delete the assigned applications
                using (var uow = _uowProvider.GetUnitOfWork())
                {
                    uow.Database.Execute(
                        "delete from umbracoUser2App where app = @appAlias",
                        new { appAlias = section.Alias });
                    uow.Commit();
                }

                //delete the assigned trees
                var trees = _applicationTreeService.GetApplicationTrees(section.Alias);
                foreach (var t in trees)
                {
                    _applicationTreeService.DeleteTree(t);
                }

                LoadXml(doc =>
                {
                    doc.Root.Elements("add").Where(x => x.Attribute("alias") != null && x.Attribute("alias").Value == section.Alias)
                    .Remove();

                    return(true);
                }, true);

                //raise event
                OnDeleted(section, new EventArgs());
            }
        }
Ejemplo n.º 2
0
        public void WithReadLocked(Action <LockedRepository <TRepository> > action, bool autoCommit = true)
        {
            using (var uow = _uowProvider.GetUnitOfWork(IsolationLevel.RepeatableRead))
            {
                // getting the database creates a scope and a transaction
                // the scope is IsolationLevel.RepeatableRead (because UnitOfWork is)
                // and will throw if outer scope (if any) has a lower isolation level

                foreach (var lockId in _readLockIds)
                {
                    uow.Database.AcquireLockNodeReadLock(lockId);
                }

                using (var repository = _repositoryFactory(uow))
                {
                    action(new LockedRepository <TRepository>(uow, repository));
                    if (autoCommit == false)
                    {
                        return;
                    }
                    uow.Commit();
                } // dispose repository => dispose uow => complete (or not) scope
            }     // dispose uow again => nothing
        }