public void UpdateIncidentStatus(string incidentId, string partner, string status)
        {
            this.SecurityHelper.DemandAuthorizedPermissions();

            IPartnerSiteDirectory partnerSiteDirectory = SharePointServiceLocator.Current.GetInstance <IPartnerSiteDirectory>();
            string partnerSiteCollectionUrl            = partnerSiteDirectory.GetPartnerSiteCollectionUrl(partner);

            IBusinessEventTypeConfigurationRepository businessEventTypeConfigRepository
                = SharePointServiceLocator.Current.GetInstance <IBusinessEventTypeConfigurationRepository>();
            string topLevelSiteUrl = businessEventTypeConfigRepository.GetBusinessEventTypeConfiguration("incident").TopLevelSiteRelativeUrl;

            using (SPSite site = new SPSite(string.Format(CultureInfo.CurrentCulture, "{0}/{1}", partnerSiteCollectionUrl, topLevelSiteUrl)))
            {
                using (SPWeb incidentsWeb = site.OpenWeb())
                {
                    foreach (SPWeb web in incidentsWeb.Webs)
                    {
                        try
                        {
                            if (web.Properties["IncidentId"] == incidentId)
                            {
                                web.Properties["Status"] = "Closed";
                                web.Properties.Update();

                                break;
                            }
                        }
                        finally
                        {
                            web.Dispose();
                        }
                    }
                }
            }
        }
Example #2
0
        public void ReturnSearchResults()
        {
            // First query the Partner Site Directory to get entries for each partner
            IPartnerSiteDirectory partnerSiteDirectory = SharePointServiceLocator.Current.GetInstance <IPartnerSiteDirectory>();
            var partnerSites = partnerSiteDirectory.GetAllPartnerSites();

            // Then execute the search query. This logic is performed by the IncidentTaskRepository.
            IIncidentTaskRepository incidentTaskRepository =
                SharePointServiceLocator.Current.GetInstance <IIncidentTaskRepository>();
            var incidentTasks = incidentTaskRepository.GetAllOpenIncidentTasks();

            // Merge the results from both here to get an aggregated view
            var partnerRollupResults = new List <PartnerRollupSearchResult>();

            foreach (PartnerSiteDirectoryEntry entry in partnerSites)
            {
                PartnerRollupSearchResult aResult = new PartnerRollupSearchResult();
                aResult.Partner = entry;

                foreach (IncidentTask incidentTask in incidentTasks)
                {
                    if (incidentTask.Path.StartsWith(entry.SiteCollectionUrl, false, CultureInfo.CurrentCulture))
                    {
                        aResult.IncidentTasks.Add(incidentTask);
                    }
                }

                partnerRollupResults.Add(aResult);
            }

            // Forward the data to the View. The view is then responsible for rendering the list.
            this.view.SetData(partnerRollupResults);
        }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IncidentManagementRepository"/> class.
 /// </summary>
 public IncidentManagementRepository()
 {
     // Retrieve the PartnerID in the constructor. You have to do this here, because, if you want to use this
     // repository in a ListItemEventReceiver, you only have access to the context (spcontext, http context and current user)
     // in the constructor of the splistitemeventreceiver.
     partnerSiteDirectory = SharePointServiceLocator.Current.GetInstance <IPartnerSiteDirectory>();
     partnerId            = partnerSiteDirectory.GetCurrentPartnerId();
 }
        public void Redirect(string queryStringParameterValue)
        {
            IPartnerSiteDirectory partnerSiteDirectory = SharePointServiceLocator.Current.GetInstance <IPartnerSiteDirectory>();
            string siteCollectionUrl = partnerSiteDirectory.GetPartnerSiteCollectionUrl();

            // The default behavior should be to take you the partner's site collection's root Web.
            Uri redirectUrl = new Uri(siteCollectionUrl);

            if (!string.IsNullOrEmpty(siteCollectionUrl))
            {
                redirectUrl = GetPartnerHomePageUrl(siteCollectionUrl, queryStringParameterValue, redirectUrl);
            }

            HttpContext.Current.Response.Redirect(redirectUrl.PathAndQuery);
        }
        public void CreateSubSite(string businessEvent, string eventIdentifier, string entityId)
        {
            this.SecurityHelper.DemandAuthorizedPermissions();

            SubSiteCreationRequest request = new SubSiteCreationRequest();

            request.BusinessEvent = businessEvent;
            request.EventId       = eventIdentifier;
            IPartnerSiteDirectory partnerSiteDirectory = SharePointServiceLocator.Current.GetInstance <IPartnerSiteDirectory>();

            request.SiteCollectionUrl = partnerSiteDirectory.GetPartnerSiteCollectionUrl(entityId);

            ISubSiteCreationRequestRepository repository = SharePointServiceLocator.Current.GetInstance <ISubSiteCreationRequestRepository>();

            repository.AddSubSiteCreationRequest(request);
        }
        /// <summary>
        /// Retrieve the price for a particular SKU that applies to the currently logged on user. This price includes all the discounts that have been
        /// applied to it for the current partner.
        /// </summary>
        /// <param name="sku">The SKU to retrieve pricing for.</param>
        /// <returns>The price.</returns>
        public Price GetPriceBySku(string sku)
        {
            Price price = null;

            //prices are stored per sku and partner
            IPartnerSiteDirectory partnerSiteDirectory =
                SharePointServiceLocator.Current.GetInstance <IPartnerSiteDirectory>();
            string key = string.Format(CultureInfo.InvariantCulture, "{0}:{1}:{2}", typeof(Price).FullName, sku,
                                       partnerSiteDirectory.GetCurrentPartnerId());

            if (cache[key] == null)
            {
                // Impersonate as the AppPool account:
                // As part of the trusted facade, we want to ensure that only the SharePoint server can access
                // the WCF LOB services. In order to check that, we have added a PrincipalPermissionAttribute that demands
                // that the calling account is part of a specific group. The app pool account is also part of that group
                // so we need to impersonate as the app pool account.
                using (HostingEnvironment.Impersonate())
                {
                    // Dispose of the proxy after usage, to ensure the resources are cleaned up:
                    // Creating proxy classes can potentially be a heavy operation, so you might consider
                    // creating a pool of proxy objects.
                    using (DisposableProxy <IPricing> client = GetClient())
                    {
                        price = TransformProxyPriceToPrice(client.Proxy.GetPriceBySku(sku));
                    }
                }

                if (price != null)
                {
                    cache.Add(key, price, null, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(5f),
                              CacheItemPriority.Normal, null);
                }
            }
            else
            {
                price = cache[key] as Price;
            }

            return(price);
        }