public static void UpdateQuota(int itemId, int siteCollectionId, int maxStorage, int warningStorage)
        {
            TaskManager.StartTask("HOSTED_SHAREPOINT_ENTERPRISE", "UPDATE_QUOTA");
            try
            {
                Organization org = (Organization)PackageController.GetPackageItem(itemId);
                if (org == null)
                {
                    return;
                }

                int serviceId = GetHostedSharePointServiceId(org.PackageId);

                HostedSharePointServerEnt hostedSharePointServer = GetHostedSharePointServer(serviceId);

                SharePointEnterpriseSiteCollection sc = GetSiteCollection(siteCollectionId);

                int maxSize     = RecalculateMaxSize(org.MaxSharePointEnterpriseStorage, maxStorage);
                int warningSize = warningStorage;


                sc.MaxSiteStorage = maxSize;
                sc.WarningStorage = maxSize == -1 ? -1 : Math.Min(warningSize, maxSize);
                PackageController.UpdatePackageItem(sc);

                hostedSharePointServer.Enterprise_UpdateQuotas(sc.PhysicalAddress, maxSize,
                                                               warningStorage);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
        public static int SetStorageSettings(int itemId, int maxStorage, int warningStorage, bool applyToSiteCollections)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // place log record
            TaskManager.StartTask("HOSTED_SHAREPOINT_ENTERPRISE", "SET_ORG_LIMITS", itemId);

            try
            {
                Organization org = (Organization)PackageController.GetPackageItem(itemId);
                if (org == null)
                {
                    return(0);
                }

                // set limits
                int realMaxSizeValue = RecalculateStorageMaxSize(maxStorage, org.PackageId);

                org.MaxSharePointEnterpriseStorage = realMaxSizeValue;

                org.WarningSharePointEnterpriseStorage = realMaxSizeValue == -1 ? -1 : Math.Min(warningStorage, realMaxSizeValue);

                // save organization
                UpdateOrganization(org);

                if (applyToSiteCollections)
                {
                    int serviceId = GetHostedSharePointServiceId(org.PackageId);

                    HostedSharePointServerEnt hostedSharePointServer = GetHostedSharePointServer(serviceId);

                    List <SharePointEnterpriseSiteCollection> currentOrgSiteCollection =
                        GetOrganizationSharePointEnterpriseSiteCollections(org.Id);


                    foreach (SharePointEnterpriseSiteCollection siteCollection in currentOrgSiteCollection)
                    {
                        try
                        {
                            SharePointEnterpriseSiteCollection sc = GetSiteCollection(siteCollection.Id);
                            sc.MaxSiteStorage = realMaxSizeValue;
                            sc.WarningStorage = realMaxSizeValue == -1 ? -1 : warningStorage;
                            PackageController.UpdatePackageItem(sc);

                            hostedSharePointServer.Enterprise_UpdateQuotas(siteCollection.PhysicalAddress, realMaxSizeValue,
                                                                           warningStorage);
                        }
                        catch (Exception ex)
                        {
                            TaskManager.WriteError(ex);
                        }
                    }
                }

                return(0);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }