Esempio n. 1
0
    /// <summary>
    /// Preloads uniSelector and selects actual data.
    /// </summary>
    protected void PreloadUniSelector(bool offerGlobalProducts)
    {
        // Get the active products
        var products = SKUInfoProvider.GetSKUs().Column("SKUID")
                       .WhereIn("SKUID", SKUTaxClassInfoProvider.GetSKUTaxClasses().Column("SKUID").WhereEquals("TaxClassID", mTaxClassId))
                       .WhereNull("SKUOptionCategoryID");

        // Ordinary user can see only product from departments he can access
        if (!cu.IsGlobalAdministrator && !cu.IsAuthorizedPerResource(ModuleName.ECOMMERCE, EcommercePermissions.PRODUCTS_ACCESSALLDEPARTMENTS))
        {
            products.Where(new WhereCondition().WhereNull("SKUDepartmentID")
                           .Or()
                           .WhereIn("SKUDepartmentID", UserDepartmentInfoProvider.GetUserDepartments().Column("DepartmentID").WhereEquals("UserID", cu.UserID)));
        }

        // Restrict site
        var includeGlobal = offerGlobalProducts && (cu.IsGlobalAdministrator || cu.IsAuthorizedPerResource(ModuleName.ECOMMERCE, EcommercePermissions.ECOMMERCE_MODIFYGLOBAL));

        products.OnSite(mCurrentSiteId, includeGlobal);

        if (!DataHelper.DataSourceIsEmpty(products))
        {
            mCurrentValues = TextHelper.Join(";", DataHelper.GetStringValues(products.Tables[0], "SKUID"));
        }

        if (!RequestHelper.IsPostBack())
        {
            uniSelector.Value = mCurrentValues;
        }
    }
    protected void usSites_OnSelectionChanged(object sender, EventArgs e)
    {
        // check 'ConfigurationModify' permission
        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.Ecommerce", "ConfigurationModify"))
        {
            RedirectToAccessDenied("CMS.Ecommerce", "ConfigurationModify");
        }

        string result = ValidateGlobalAndDeskAdmin(userId);

        if (result != String.Empty)
        {
            // Show error message
            ShowError(result);

            return;
        }

        // Remove old items
        string newValues = ValidationHelper.GetString(uniSelector.Value, null);
        string items     = DataHelper.GetNewItemsInList(newValues, currentValues);

        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 departmentId = ValidationHelper.GetInteger(item, 0);
                    UserDepartmentInfoProvider.RemoveUserFromDepartment(departmentId, userId);
                }
            }
        }

        // 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 departmentId = ValidationHelper.GetInteger(item, 0);
                    UserDepartmentInfoProvider.AddUserToDepartment(departmentId, userId);
                }
            }
        }

        // Show message
        ShowChangesSaved();
    }
Esempio n. 3
0
    protected void SaveItems()
    {
        if (mDepartmentInfoObj == null)
        {
            return;
        }

        // Check permissions
        CheckConfigurationModification(mDepartmentInfoObj.DepartmentSiteID);

        // Remove old items
        string newValues = ValidationHelper.GetString(uniSelector.Value, null);
        string items     = DataHelper.GetNewItemsInList(newValues, mCurrentValues);

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

        // Add new items
        items = DataHelper.GetNewItemsInList(mCurrentValues, newValues);
        if (!String.IsNullOrEmpty(items))
        {
            string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (newItems != null)
            {
                // Add all new items to user
                foreach (string item in newItems)
                {
                    int userId = ValidationHelper.GetInteger(item, 0);
                    UserDepartmentInfoProvider.AddUserToDepartment(mDepartmentId, userId);
                }
            }
        }

        lblInfo.Visible = true;
        lblInfo.Text    = GetString("General.ChangesSaved");
    }