コード例 #1
0
        /// <summary>
        /// Deletes a website.
        /// </summary>
        /// <param name="tenantId">Identifies the website to delete.</param>
        /// <param name="unitOfWork">Unit of work.</param>
        public void Delete(long tenantId, IUnitOfWork unitOfWork = null)
        {
            // If we don't have a unit of work in place, create one so that website and domain deletion tasks can both be rolled back in the case of failure
            IUnitOfWork localUnitOfWork = unitOfWork == null?_unitOfWorkFactory.CreateUnitOfWork() : null;

            try
            {
                // Delete domains and website
                _domainRepository.DeleteByTenant(tenantId, unitOfWork ?? localUnitOfWork);
                _webRepository.Delete(tenantId, unitOfWork ?? localUnitOfWork);

                // Commit work if local unit of work in place
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Commit();
                }
            }
            catch (ValidationErrorException)
            {
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Rollback();
                }
                throw;
            }
            catch (Exception ex)
            {
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Rollback();
                }
                throw new ValidationErrorException(new ValidationError(null, ApplicationResource.UnexpectedErrorMessage), ex);
            }
        }