/// <summary> /// Constructor /// </summary> public ViewLayout(ViewConfiguration configuration, EntityView view = null, string portalName = null, int languageCode = 0, bool addSelectColumn = false, bool addActionsColumn = false, string selectColumnHeaderText = "") { Configuration = configuration; var serviceContext = PortalCrmConfigurationManager.CreateServiceContext(portalName); if (view == null) { view = Configuration.GetEntityView(serviceContext, languageCode); } View = view; ViewName = view.Name; Id = view.Id; SortExpression = view.SortExpression; var overrideColumns = new List <ViewColumn>(); if (addSelectColumn) { overrideColumns.Add(new ViewColumn("col-select", selectColumnHeaderText ?? string.Empty, null, 20, 0, true, ViewColumnType.Select)); } if (Configuration.ColumnOverrides.Any()) { foreach (var columnA in View.Columns) { var match = false; foreach (var columnB in Configuration.ColumnOverrides) { if (columnA.LogicalName == columnB.AttributeLogicalName) { match = true; overrideColumns.Add(new ViewColumn(columnB.AttributeLogicalName, string.IsNullOrWhiteSpace(columnB.DisplayName) ? columnA.Name : columnB.DisplayName, null, columnB.Width == 0 ? columnA.Width : columnB.Width, 0, columnA.SortDisabled)); } } if (!match) { overrideColumns.Add(new ViewColumn(columnA.LogicalName, columnA.Name, columnA.Metadata, columnA.Width, 0, columnA.SortDisabled)); } } } else { overrideColumns.AddRange(View.Columns.Select(c => new ViewColumn(c.LogicalName, c.Name, c.Metadata, c.Width, 0, c.SortDisabled))); } if (addActionsColumn) { overrideColumns.Add(new ViewColumn("col-action", configuration.ActionColumnHeaderText ?? "<span class='sr-only'>Actions</span>", null, configuration.ActionLinksColumnWidth, 0, true, ViewColumnType.Actions)); } ColumnsTotalWidth = overrideColumns.Sum(c => c.Width); // Adjust the widths to be percentage based foreach (var column in overrideColumns) { var columnWidth = overrideColumns.FirstOrDefault(o => o.LogicalName == column.LogicalName); if (columnWidth == null) { continue; } var width = Convert.ToDouble(columnWidth.Width) / ColumnsTotalWidth * 100; column.WidthAsPercent = width; } Columns = overrideColumns; if (configuration.EnableEntityPermissions && AdxstudioCrmConfigurationManager.GetCrmSection().ContentMap.Enabled) { var insertActionEnabled = configuration.InsertActionLink.Enabled; var createViewActionLinks = configuration.ViewActionLinks.Where(viewAction => viewAction.Enabled && viewAction.Type == LinkActionType.Insert); if (insertActionEnabled || createViewActionLinks.Any()) { var crmEntityPermissionProvider = new CrmEntityPermissionProvider(configuration.PortalName); var canCreate = crmEntityPermissionProvider.TryAssert(serviceContext, CrmEntityPermissionRight.Create, configuration.EntityName); if (insertActionEnabled) { configuration.InsertActionLink.Enabled = canCreate; } foreach (var action in createViewActionLinks) { action.Enabled = canCreate; } } } // Produce a secure configuration converted to a Base64 string var configurationJson = JsonConvert.SerializeObject(configuration, new JsonSerializerSettings { Converters = new List <JsonConverter> { new UrlBuilderConverter() } }); var configurationByteArray = Encoding.UTF8.GetBytes(configurationJson); var protectedByteArray = MachineKey.Protect(configurationByteArray, "Secure View Configuration"); Base64SecureConfiguration = Convert.ToBase64String(protectedByteArray); }