private void RenderCurrentList(OrganizationServiceContext context, Guid viewId) { var savedQueryView = new SavedQueryView(context, viewId, LanguageCode); savedQueryView.FetchXml.Element("entity").Add(new XElement("filter", new XAttribute("type", "and"), new XElement("condition", new XAttribute("attribute", PreviousStepEntityPrimaryKeyLogicalName), new XAttribute("operator", "eq"), new XAttribute("value", PreviousStepEntityID)))); var viewConfiguration = new ViewConfiguration(savedQueryView) { DataPagerEnabled = false, FetchXml = savedQueryView.FetchXml.ToString(), LanguageCode = LanguageCode, PortalName = PortalName }; var crmEntityListView = new CrmEntityListView { ID = "CurrentList", LanguageCode = LanguageCode, PortalName = PortalName, ViewConfigurations = new List <ViewConfiguration> { viewConfiguration }, ListCssClass = "table table-striped", SelectMode = EntityGridExtensions.GridSelectMode.Single }; CurrentListPlaceholder.Controls.Add(crmEntityListView); }
private CrmEntityListView GetEntityListView(ControlCollection controls) { CrmEntityListView listView = null; foreach (Control control in controls) { if (control is CrmEntityListView) { listView = (CrmEntityListView)control; break; } else { listView = GetEntityListView(control.Controls); if (listView != null) { break; } } } return(listView); }
protected override void CreateChildControls() { Controls.Clear(); var portalContext = PortalCrmConfigurationManager.CreatePortalContext(PortalName); var serviceContext = PortalCrmConfigurationManager.CreateServiceContext(PortalName); Entity entitylist; bool updateEntityListReference; if (!TryGetEntityList(portalContext, serviceContext, out entitylist, out updateEntityListReference)) { Visible = false; return; } if (updateEntityListReference) { EntityListReference = entitylist.ToEntityReference(); } if (LanguageCode <= 0) { LanguageCode = this.Context.GetPortalSolutionsDetails().OrganizationBaseLanguageCode; } RegisterClientSideDependencies(this); var registerStartupScript = entitylist.GetAttributeValue <string>("adx_registerstartupscript"); if (!string.IsNullOrWhiteSpace(registerStartupScript)) { var html = Mvc.Html.EntityExtensions.GetHtmlHelper(PortalName, Page.Request.RequestContext, Page.Response); var control = new HtmlGenericControl() { }; var script = html.ScriptAttribute(serviceContext, entitylist, "adx_registerstartupscript"); control.InnerHtml = script.ToString(); Controls.Add(control); } var entityName = entitylist.GetAttributeValue <string>("adx_entityname"); var primaryKeyName = entitylist.GetAttributeValue <string>("adx_primarykeyname"); var view = entitylist.GetAttributeValue <string>("adx_view"); // old comma delimited list of views var viewMetadataJson = entitylist.GetAttributeValue <string>("adx_views"); EnableEntityPermissions = entitylist.GetAttributeValue <bool?>("adx_entitypermissionsenabled").GetValueOrDefault(false); if (string.IsNullOrWhiteSpace(entityName)) { throw new ApplicationException("Entity Name (adx_entityname) attribute on Entity List (adx_entitylist) is null or empty. Please specify the logical name of the entity."); } if (!string.IsNullOrWhiteSpace(entityName) && string.IsNullOrWhiteSpace(primaryKeyName)) { primaryKeyName = MetadataHelper.GetEntityPrimaryKeyAttributeLogicalName(serviceContext, entityName); } if (string.IsNullOrWhiteSpace(primaryKeyName)) { throw new ApplicationException(string.Format("The entity primary key logical name couldn't be determined.", entityName)); } if (string.IsNullOrWhiteSpace(view) && string.IsNullOrWhiteSpace(viewMetadataJson)) { throw new ApplicationException("View selection on Entity List (adx_entitylist) is null or empty. Specify the savedquery views."); } var gridMetadataJson = entitylist.GetAttributeValue <string>("adx_settings"); GridMetadata gridMetadata = null; if (!string.IsNullOrWhiteSpace(gridMetadataJson)) { try { gridMetadata = JsonConvert.DeserializeObject <GridMetadata>(gridMetadataJson, new JsonSerializerSettings { ContractResolver = JsonConfigurationContractResolver.Instance, TypeNameHandling = TypeNameHandling.Objects, Converters = new List <JsonConverter> { new GuidConverter() }, Binder = new ActionSerializationBinder() }); } catch (Exception e) { ADXTrace.Instance.TraceError(TraceCategory.Application, e.ToString()); } } var viewConfigurations = new List <ViewConfiguration>(); if (string.IsNullOrWhiteSpace(viewMetadataJson)) { if (string.IsNullOrWhiteSpace(view)) { return; } var viewids = view.Split(','); var viewGuids = viewids.Length < 1 ? null : Array.ConvertAll(viewids, Guid.Parse); if (viewGuids == null || !viewGuids.Any()) { throw new ApplicationException( ResourceManager.GetString("ADX_View_Attribute_On_Entity_List_Contains_Invalid_Data_Exception")); } viewConfigurations = viewGuids.Select( viewGuid => new ViewConfiguration(portalContext, serviceContext, entitylist, entityName, primaryKeyName, viewGuid, gridMetadata, PortalName, LanguageCode, EnableEntityPermissions, PageQueryStringField, FilterQueryStringField, SearchQueryStringField, SortQueryStringField, FilterByUserOptionLabel, ActionLinksColumnWidth, MetadataFilterQueryStringField, DefaultDetailsButtonLabel, ActionLinkDetailsViewTooltipLabel, DefaultCreateButtonLabel, ActionLinkInsertTooltipLabel, DefaultEmptyListText)).ToList(); } else { ViewMetadata viewMetadata = null; try { viewMetadata = JsonConvert.DeserializeObject <ViewMetadata>(viewMetadataJson, new JsonSerializerSettings { ContractResolver = JsonConfigurationContractResolver.Instance, TypeNameHandling = TypeNameHandling.Objects, Binder = new ActionSerializationBinder(), Converters = new List <JsonConverter> { new GuidConverter() } }); } catch (Exception e) { ADXTrace.Instance.TraceError(TraceCategory.Application, e.ToString()); } if (viewMetadata != null && viewMetadata.Views != null && viewMetadata.Views.Any()) { foreach (var viewMeta in viewMetadata.Views) { var viewConfiguration = new ViewConfiguration(portalContext, serviceContext, entitylist, entityName, primaryKeyName, viewMeta.ViewId, gridMetadata, PortalName, LanguageCode, EnableEntityPermissions, PageQueryStringField, FilterQueryStringField, SearchQueryStringField, SortQueryStringField, FilterByUserOptionLabel, ActionLinksColumnWidth, MetadataFilterQueryStringField, DefaultDetailsButtonLabel, ActionLinkDetailsViewTooltipLabel, DefaultCreateButtonLabel, ActionLinkInsertTooltipLabel, DefaultEmptyListText); if (viewMeta.DisplayName != null) { var displayName = Localization.GetLocalizedString(viewMeta.DisplayName, LanguageCode); if (!string.IsNullOrWhiteSpace(displayName)) { viewConfiguration.ViewDisplayName = displayName; } } viewConfigurations.Add(viewConfiguration); } } } var crmEntityListView = new CrmEntityListView { EnableEntityPermissions = EnableEntityPermissions, EntityListReference = EntityListReference, ViewConfigurations = viewConfigurations, ListCssClass = ListCssClass, PortalName = PortalName, LanguageCode = LanguageCode, ViewQueryStringParameterName = ViewQueryStringField, IsGallery = IsGallery }; if (gridMetadata != null) { if (gridMetadata.ErrorDialog != null) { crmEntityListView.ErrorModal = new ViewErrorModal { CloseButtonCssClass = gridMetadata.ErrorDialog.CloseButtonCssClass, CloseButtonText = gridMetadata.ErrorDialog.CloseButtonText.GetLocalizedString(LanguageCode), CssClass = gridMetadata.ErrorDialog.CssClass, DismissButtonSrText = gridMetadata.ErrorDialog.DismissButtonSrText.GetLocalizedString(LanguageCode), Body = gridMetadata.ErrorDialog.Body.GetLocalizedString(LanguageCode), Size = gridMetadata.ErrorDialog.Size, Title = gridMetadata.ErrorDialog.Title.GetLocalizedString(LanguageCode), TitleCssClass = gridMetadata.ErrorDialog.TitleCssClass }; } } Controls.Add(crmEntityListView); }
private void RenderDuplicatesList(OrganizationServiceContext context, Guid viewId, string latitudeFieldName, string longitudeFieldName, double latitude, double longitude, double distance) { var savedQueryView = new SavedQueryView(context, viewId, LanguageCode); var angularDistance = distance / GeoHelpers.EarthRadiusInKilometers; var originLatitudeRadians = GeoHelpers.DegreesToRadians(latitude); var originLongitudeRadians = GeoHelpers.DegreesToRadians(longitude); var minLatitudeRadians = originLatitudeRadians - angularDistance; var maxLatitudeRadians = originLatitudeRadians + angularDistance; var deltaLongitude = Math.Asin(Math.Sin(angularDistance) / Math.Cos(originLatitudeRadians)); var minLongitudeRadians = originLongitudeRadians - deltaLongitude; var maxLongitudeRadians = originLongitudeRadians + deltaLongitude; var minLatitude = GeoHelpers.RadiansToDegrees(minLatitudeRadians); var maxLatitude = GeoHelpers.RadiansToDegrees(maxLatitudeRadians); var minLongitude = GeoHelpers.RadiansToDegrees(minLongitudeRadians); var maxLongitude = GeoHelpers.RadiansToDegrees(maxLongitudeRadians); var minLatitudeCondition = new XElement("condition", new XAttribute("attribute", latitudeFieldName), new XAttribute("operator", "ge"), new XAttribute("value", minLatitude)); var maxLatitudeCondition = new XElement("condition", new XAttribute("attribute", latitudeFieldName), new XAttribute("operator", "le"), new XAttribute("value", maxLatitude)); var minLongitudeCondition = new XElement("condition", new XAttribute("attribute", longitudeFieldName), new XAttribute("operator", "ge"), new XAttribute("value", minLongitude)); var maxLongitudeCondition = new XElement("condition", new XAttribute("attribute", longitudeFieldName), new XAttribute("operator", "le"), new XAttribute("value", maxLongitude)); var notCurrentServiceRequest = new XElement("condition", new XAttribute("attribute", PreviousStepEntityPrimaryKeyLogicalName), new XAttribute("operator", "ne"), new XAttribute("value", PreviousStepEntityID)); savedQueryView.FetchXml.Element("entity").Add(new XElement("filter", new XAttribute("type", "and"), notCurrentServiceRequest, minLatitudeCondition, maxLatitudeCondition, minLongitudeCondition, maxLongitudeCondition)); var viewConfiguration = new ViewConfiguration(savedQueryView) { DataPagerEnabled = false, FetchXml = savedQueryView.FetchXml.ToString(), LanguageCode = LanguageCode, PortalName = PortalName }; var response = context.Execute(new RetrieveMultipleRequest { Query = new FetchExpression(viewConfiguration.FetchXml.ToString()) }) as RetrieveMultipleResponse; if (!response.EntityCollection.Entities.Any()) { _isUnique = true; MoveToNextStep(PreviousStepEntityID); return; } var crmEntityListView = new CrmEntityListView { ID = "DuplicateList", LanguageCode = LanguageCode, PortalName = PortalName, ViewConfigurations = new List <ViewConfiguration> { viewConfiguration }, ListCssClass = "table table-striped", SelectMode = EntityGridExtensions.GridSelectMode.Single }; DuplicateListPlaceholder.Controls.Add(crmEntityListView); }