예제 #1
0
        /// <summary>
        /// Updates master page.
        /// </summary>
        /// <param name="masterPage">The updated master page.</param>
        /// <param name="unitOfWork">Unit of work.</param>
        public void Update(MasterPage masterPage, IUnitOfWork unitOfWork = null)
        {
            // If we don't have a unit of work in place, create one now so that we can rollback all changes in case of failure
            IUnitOfWork localUnitOfWork = unitOfWork == null?_unitOfWorkFactory.CreateUnitOfWork() : null;

            // Do the page update
            try
            {
                // Prepare master page for update (e.g. set correct sort orders)
                PrepareMasterPage(masterPage);

                // Do the update
                _masterPageRepository.Update(masterPage, unitOfWork ?? localUnitOfWork);

                // Set specified master page as admin and ensure all other master pages belonging to the same tenant do not have master page set as admin.
                // There can only be 1 admin master page.
                if (masterPage.Administration)
                {
                    _masterPageRepository.SetAdminMasterPage(masterPage.TenantId, masterPage.MasterPageId, 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);
            }
        }