Beispiel #1
0
        public ActionResult FacultyDirectoryCorporateProfile()
        {
            FacultyDirectoryCorporateProfile facultyProfile = new FacultyDirectoryCorporateProfile();

            facultyProfile.rendering = Sitecore.Mvc.Presentation.RenderingContext.CurrentOrNull.Rendering;
            facultyProfile.pageItem  = PageContext.Current.Item;
            facultyProfile.showError = "";

            try
            {
                // Set datasource if it is empty
                if (String.IsNullOrEmpty(facultyProfile.rendering.DataSource))
                {
                    using (new Sitecore.SecurityModel.SecurityDisabler())
                    {
                        //Get current rendering item
                        Sitecore.Layouts.RenderingReference[] renderings = facultyProfile.pageItem.Visualization.GetRenderings(Sitecore.Context.Device, true).Where(r => r.RenderingID == facultyProfile.rendering.RenderingItem.ID).ToArray();

                        // Get the layout definitions and the device
                        Sitecore.Data.Fields.LayoutField  layoutField      = new Sitecore.Data.Fields.LayoutField(facultyProfile.pageItem.Fields[Sitecore.FieldIDs.FinalLayoutField]);
                        Sitecore.Layouts.LayoutDefinition layoutDefinition = Sitecore.Layouts.LayoutDefinition.Parse(layoutField.Value);
                        Sitecore.Layouts.DeviceDefinition deviceDefinition = layoutDefinition.GetDevice(Sitecore.Context.Device.ID.ToString());
                        foreach (Sitecore.Layouts.RenderingReference rendering in renderings)
                        {
                            // Update the renderings datasource value as current item path
                            deviceDefinition.GetRendering(rendering.RenderingID.ToString()).Datasource = facultyProfile.pageItem.ID.ToString();
                            // Save the layout changes
                            facultyProfile.pageItem.Editing.BeginEdit();
                            layoutField.Value = layoutDefinition.ToXml();
                            facultyProfile.pageItem.Editing.EndEdit();
                        }
                    }
                }

                Sitecore.Marketing.Wildcards.WildcardTokenizedString wts    = Sitecore.Marketing.Wildcards.WildcardManager.Provider.GetWildcardUrl(facultyProfile.PageItem, Sitecore.Context.Site);
                System.Collections.Specialized.NameValueCollection   tokens = wts.FindTokenValues(Request.Path.ToLower().Replace(' ', '-'));
                facultyProfile.strPID = tokens["%Person_ID%"];
                if (facultyProfile.strPID != null)
                {
                    facultyProfile.validId = Int32.TryParse(facultyProfile.strPID, out facultyProfile.personID);
                }
                if (facultyProfile.validId && !Sitecore.Context.PageMode.IsExperienceEditorEditing)
                {
                    facultyProfile.person = new HealthIS.Apps.FacultyDirectory.Profile(facultyProfile.personID, HealthIS.Apps.FacultyDirectory.Profile.ProfileType.Research, HealthIS.Apps.FacultyDirectory.Profile.ProfileParts.All);
                }
            }
            catch (Exception ex)
            {
                facultyProfile.showError = "Sorry for the inconvenience.<br />We&rsquo;re performing some maintenance at the moment.";
                Sitecore.Diagnostics.Log.SingleWarn("Error from faculty profile page at " + Request.Url.Host + " - " + ex.Message, this);
                facultyProfile.person = null;
            }
            return(PartialView(facultyProfile));
        }
        public override void Apply(T ruleContext)
        {
            SC.Diagnostics.Assert.ArgumentNotNull(ruleContext, "ruleContext");
            SC.Diagnostics.Assert.ArgumentNotNull(
                ruleContext.Item,
                "ruleContext.Item");
            SC.Data.Fields.LayoutField layoutDetails =
                ruleContext.Item.Fields[SC.FieldIDs.LayoutField];
            SC.Diagnostics.Assert.IsNotNull(layoutDetails, "layoutDetails");

            if (String.IsNullOrEmpty(layoutDetails.Value) ||
                layoutDetails.InnerField.ContainsStandardValue)
            {
                return;
            }

            SC.Layouts.LayoutDefinition layout =
                SC.Layouts.LayoutDefinition.Parse(layoutDetails.Value);
            bool modified = false;

            for (int i = 0; i < layout.Devices.Count; i++)
            {
                SC.Layouts.DeviceDefinition device =
                    layout.Devices[i] as SC.Layouts.DeviceDefinition;
                SC.Diagnostics.Assert.IsNotNull(device, "device");

                for (int j = 0; j < device.Renderings.Count; j++)
                {
                    SC.Layouts.RenderingDefinition rendering =
                        device.Renderings[j] as SC.Layouts.RenderingDefinition;
                    SC.Diagnostics.Assert.IsNotNull(rendering, "rendering");

                    if (String.IsNullOrEmpty(rendering.Datasource) ||
                        !rendering.Datasource.StartsWith("/"))
                    {
                        continue;
                    }

                    SC.Data.Items.Item dataSource =
                        ruleContext.Item.Database.GetItem(rendering.Datasource);

                    if (dataSource == null)
                    {
                        string msg = this
                                     + " : unable to retrieve data source item "
                                     + rendering.Datasource
                                     + " in "
                                     + ruleContext.Item.Paths.FullPath;
                        SC.Diagnostics.Log.Warn(msg, this);
                        continue;
                    }

                    rendering.Datasource = dataSource.ID.ToString();
                    modified             = true;
                }
            }

            if (modified)
            {
                using (new SC.Data.Items.EditContext(ruleContext.Item, false, false))
                {
                    layoutDetails.Value = layout.ToXml();
                }
            }
        }