Example #1
0
        /// <summary>
        /// Handles the SaveChanges event of the EditSaveControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void EditSaveControl_SaveChanges(object sender, SaveControl.SaveEventArgs e)
        {
            // Validate form
            if (!this.Page.IsValid)
            {
                e.RunScript = false;
                return;
            }

            try
            {
                // Always load, since we need application data
                SiteDto dto = (SiteDto)Session[_SiteEditSessionKey];

                if (dto == null && SiteId != Guid.Empty)
                {
                    if (NeedCopy)
                    {
                        dto = new SiteDto();
                    }
                    else
                    {
                        dto = CMSContext.Current.GetSiteDto(SiteId, true);
                    }
                }
                else if (dto == null && SiteId == Guid.Empty)
                {
                    dto = new SiteDto();
                }

                // Put a dictionary key that can be used by other tabs
                IDictionary dic = new ListDictionary();
                dic.Add(_SiteDtoDestinationString, dto);

                dto.EnforceConstraints = false;

                ViewControl.SaveChanges(dic);

                // get saveddto from the dictionary
                dto = (SiteDto)dic[_SiteDtoDestinationString];

                // Save modifications
                if (dto.HasChanges())
                {
                    if (dto.Site.Count > 0)
                    {
                        // update siteId for the GlobalVariable rows that have just been addded
                        SiteDto.main_GlobalVariablesRow[] variableRows = (SiteDto.main_GlobalVariablesRow[])dto.main_GlobalVariables.Select("", "", DataViewRowState.Added);
                        if (variableRows != null && variableRows.Length > 0)
                        {
                            foreach (SiteDto.main_GlobalVariablesRow row in variableRows)
                            {
                                row.SiteId = dto.Site[0].SiteId;
                            }
                        }
                    }

                    dto.EnforceConstraints = true;

                    CMSContext.Current.SaveSite(dto);

                    if (NeedCopy && SiteId != Guid.Empty)
                    {
                        CopyHelper helper = new CopyHelper();

                        //Menu copy
                        helper.CopySiteMenu(SiteId, dto.Site[0].SiteId);

                        //Folders and pages copy
                        helper.CopySiteContent(SiteId, dto.Site[0].SiteId);
                    }
                }

                // Call commit changes
                ViewControl.CommitChanges(dic);
            }
            catch (SiteImportExportException ex)
            {
                e.RunScript = false;
                DisplayErrorMessage(ex.Message);
            }
            finally
            {
                // we don't need to store Dto in session any more
                Session.Remove(_SiteEditSessionKey);
            }
        }