Exemple #1
0
    protected void SaveSites()
    {
        // Check 'GlobalModify' permission
        CheckPollsModifyPermission(0);

        // Remove old items
        string newValues   = ValidationHelper.GetString(usSites.Value, null);
        string items       = DataHelper.GetNewItemsInList(newValues, currentValues);
        bool   falseValues = false;

        if (!String.IsNullOrEmpty(items))
        {
            string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (newItems != null)
            {
                // Add all new items to site
                foreach (string item in newItems)
                {
                    int siteId = ValidationHelper.GetInteger(item, 0);

                    // Remove poll from site
                    PollInfoProvider.RemovePollFromSite(pollId, siteId);
                }
            }
        }

        // Add new items
        items = DataHelper.GetNewItemsInList(currentValues, newValues);
        if (!String.IsNullOrEmpty(items))
        {
            string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (newItems != null)
            {
                // Add all new items to site
                foreach (string item in newItems)
                {
                    int      siteId = ValidationHelper.GetInteger(item, 0);
                    SiteInfo si     = SiteInfoProvider.GetSiteInfo(siteId);

                    if (si != null)
                    {
                        // Check if site has license permission to assign poll to the site
                        if (!PollInfoProvider.LicenseVersionCheck(si.DomainName, FeatureEnum.Polls, ObjectActionEnum.Insert))
                        {
                            ShowError(GetString("LicenseVersion.Polls"));
                            falseValues = true;
                            continue;
                        }
                        else
                        {
                            // If poll is not in site, add it to the site
                            PollInfoProvider.AddPollToSite(pollId, si.SiteID);
                        }
                    }
                }
            }
        }

        // If there were some errors, reload uniselector
        if (falseValues)
        {
            usSites.Value = GetPollSites();
            usSites.Reload(true);
        }

        ShowChangesSaved();
    }