public ActionResult GetNotes(EntityReference regarding, List <Order> orders, int page, int pageSize = DefaultPageSize) { string portalName = null; var portalContext = PortalCrmConfigurationManager.CreatePortalContext(); var languageCodeSetting = portalContext.ServiceContext.GetSiteSettingValueByName(portalContext.Website, "Language Code"); if (!string.IsNullOrWhiteSpace(languageCodeSetting)) { int languageCode; if (int.TryParse(languageCodeSetting, out languageCode)) { portalName = languageCode.ToString(CultureInfo.InvariantCulture); } } var dataAdapterDependencies = new PortalConfigurationDataAdapterDependencies(requestContext: Request.RequestContext, portalName: portalName); var dataAdapter = new AnnotationDataAdapter(dataAdapterDependencies); var entityMetadata = portalContext.ServiceContext.GetEntityMetadata(regarding.LogicalName, EntityFilters.All); var result = dataAdapter.GetAnnotations(regarding, orders, page, pageSize, entityMetadata: entityMetadata); var totalRecordCount = result.TotalCount; var entityPermissionProvider = new CrmEntityPermissionProvider(); var crmLcid = HttpContext.GetCrmLcid(); var records = result.Select(r => new NoteRecord(r, dataAdapterDependencies, entityPermissionProvider, entityMetadata, true, crmLcid)); var data = new PaginatedGridData(records, totalRecordCount, page, pageSize); return(new JsonResult { Data = data, MaxJsonLength = int.MaxValue }); }
public ActionResult GetActivities(EntityReference regarding, List <Order> orders, int page, int pageSize = DefaultPageSize) { var portalContext = PortalCrmConfigurationManager.CreatePortalContext(); var dataAdapterDependencies = new PortalConfigurationDataAdapterDependencies(requestContext: Request.RequestContext); var dataAdapter = new ActivityDataAdapter(dataAdapterDependencies); var entityMetadata = portalContext.ServiceContext.GetEntityMetadata(regarding.LogicalName, EntityFilters.All); var result = dataAdapter.GetActivities(regarding, orders, page, pageSize, entityMetadata); var entityPermissionProvider = new CrmEntityPermissionProvider(); var crmLcid = HttpContext.GetCrmLcid(); var records = result.Select(r => new ActivityRecord(r, dataAdapterDependencies, entityPermissionProvider, entityMetadata, true, crmLcid)).ToArray(); var data = new PaginatedGridData(records, result.TotalCount, page, pageSize); return(new JsonResult { Data = data, MaxJsonLength = int.MaxValue }); }
private ActionResult GetData(ViewConfiguration viewConfiguration, string sortExpression, string search, string filter, string metaFilter, int page, int pageSize = DefaultPageSize, bool applyRecordLevelFilters = true, bool applyRelatedRecordFilter = false, string filterRelationshipName = null, string filterEntityName = null, string filterAttributeName = null, Guid?filterValue = null, bool overrideMaxPageSize = false, IDictionary <string, string> customParameters = null) { PaginatedGridData data; //Search criteria with length 4000+ causes Generic SQL error Bug#371907 const int maxSearchLength = 3999; var searchCriteria = search?.Length > maxSearchLength?search.Substring(0, maxSearchLength) : search; using (PerformanceProfiler.Instance.StartMarker(PerformanceMarkerName.EntityGridController, PerformanceMarkerArea.Crm, PerformanceMarkerTagName.GetData)) { if (viewConfiguration == null) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, ResourceManager.GetString("Invalid_Request"))); } if (pageSize < 0) { pageSize = DefaultPageSize; } if (pageSize > DefaultMaxPageSize && !overrideMaxPageSize) { ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format( "pageSize={0} is greater than the allowed maximum page size of {1}. Page size has been constrained to {1}.", pageSize, DefaultMaxPageSize)); pageSize = DefaultMaxPageSize; } var dataAdapterDependencies = new PortalConfigurationDataAdapterDependencies(requestContext: Request.RequestContext, portalName: viewConfiguration.PortalName); var website = HttpContext.GetWebsite(); var viewDataAdapter = SetViewDataAdapter(viewConfiguration, sortExpression, searchCriteria, filter, metaFilter, page, applyRecordLevelFilters, applyRelatedRecordFilter, filterRelationshipName, filterEntityName, filterAttributeName, filterValue, customParameters, dataAdapterDependencies, website); var result = viewDataAdapter.FetchEntities(); //If current page doesn't contain any records, but records exist in general, get those records from previous page for further rendering them. if (!result.Records.Any() && result.TotalRecordCount > 0) { viewDataAdapter = SetViewDataAdapter(viewConfiguration, sortExpression, searchCriteria, filter, metaFilter, page - 1, applyRecordLevelFilters, applyRelatedRecordFilter, filterRelationshipName, filterEntityName, filterAttributeName, filterValue, customParameters, dataAdapterDependencies, website); result = viewDataAdapter.FetchEntities(); } if (result.EntityPermissionDenied) { var permissionResult = new EntityPermissionResult(true); return(Json(permissionResult)); } var serviceContext = dataAdapterDependencies.GetServiceContext(); var organizationMoneyFormatInfo = new OrganizationMoneyFormatInfo(dataAdapterDependencies); var crmLcid = HttpContext.GetCrmLcid(); EntityRecord[] records; if (viewConfiguration.EnableEntityPermissions && AdxstudioCrmConfigurationManager.GetCrmSection().ContentMap.Enabled&& viewConfiguration.EntityName != "entitlement") { var crmEntityPermissionProvider = new CrmEntityPermissionProvider(); records = result.Records.Select(e => new EntityRecord(e, serviceContext, crmEntityPermissionProvider, viewDataAdapter.EntityMetadata, true, organizationMoneyFormatInfo: organizationMoneyFormatInfo, crmLcid: crmLcid)).ToArray(); } else { records = result.Records.Select(e => new EntityRecord(e, viewDataAdapter.EntityMetadata, serviceContext, organizationMoneyFormatInfo, crmLcid)).ToArray(); } records = FilterWebsiteRelatedRecords(records, dataAdapterDependencies.GetWebsite()); var totalRecordCount = result.TotalRecordCount; var disabledActionLinks = new List <DisabledItemActionLink>(); // Disable Create Related Record Action Links based on Filter Criteria. disabledActionLinks.AddRange(DisableActionLinksBasedOnFilterCriteria(serviceContext, viewDataAdapter.EntityMetadata, viewConfiguration.CreateRelatedRecordActionLinks, records)); // Disable Item Action Links based on Filter Criteria. disabledActionLinks.AddRange(DisableActionLinksBasedOnFilterCriteria(serviceContext, viewDataAdapter.EntityMetadata, viewConfiguration.ItemActionLinks, records)); data = new PaginatedGridData(records, totalRecordCount, page, pageSize, disabledActionLinks) { CreateActionMetadata = GetCreationActionMetadata(viewConfiguration, dataAdapterDependencies), MoreRecords = result.MoreRecords.GetValueOrDefault() || (totalRecordCount > (page * pageSize)) }; } var json = Json(data); json.MaxJsonLength = int.MaxValue; return(json); }
private ActionResult GetData(ViewConfiguration viewConfiguration, string sortExpression, string search, string filter, string metaFilter, int page, int pageSize = DefaultPageSize, bool applyRecordLevelFilters = true, bool applyRelatedRecordFilter = false, string filterRelationshipName = null, string filterEntityName = null, string filterAttributeName = null, Guid?filterValue = null, bool overrideMaxPageSize = false, string createdOnFilter = null) { if (viewConfiguration == null) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, "Invalid Request.")); } if (pageSize < 0) { pageSize = DefaultPageSize; } viewConfiguration = EnableSearchForPriceList(viewConfiguration); if (pageSize > DefaultMaxPageSize && !overrideMaxPageSize) { Tracing.FrameworkInformation(GetType().FullName, "GetData", "pageSize={0} is greater than the allowed maximum page size of {1}. Page size has been constrained to {1}.", pageSize, DefaultMaxPageSize); pageSize = DefaultMaxPageSize; } var dataAdapterDependencies = new PortalConfigurationDataAdapterDependencies(requestContext: Request.RequestContext, portalName: viewConfiguration.PortalName); #region - DMS Custom Filtering - CustomFetchXml converter = new CustomFetchXml(dataAdapterDependencies.GetServiceContext(), new XrmConnection()); if (metaFilter != null) { if (metaFilter.IndexOf(",date") > 0) { string dateFilterString = metaFilter.Substring(metaFilter.IndexOf("date=") + 5); string[] dateFilters = dateFilterString.Split(new string[] { ",date=" }, StringSplitOptions.None); /*int dateFromIndexStart = metaFilter.LastIndexOf("DateFrom=") + 9; * int dateFromIndexEnd = metaFilter.LastIndexOf("&DateTo=") + 8; * dateFilter = metaFilter.Substring(metaFilter.IndexOf("date=") + 5); * int fieldNameIndex = metaFilter.LastIndexOf("&field=") + 7; * string dateFromValue = metaFilter.Substring(dateFromIndexStart, 10); * string dateToValue = metaFilter.Substring(dateFromIndexEnd, 10); * string entityFieldName = metaFilter.Substring(fieldNameIndex, (metaFilter.Length - fieldNameIndex));*/ foreach (string dateFilter in dateFilters) { string[] dateFilterValues = dateFilter.Split('&'); DateTime?dateFromValue = dateFilterValues[0].Split('=')[1] != "" ? (DateTime?)Convert.ToDateTime(dateFilterValues[0].Split('=')[1]) : null; DateTime?dateToValue = dateFilterValues[1].Split('=')[1] != "" ? (DateTime?)Convert.ToDateTime(dateFilterValues[1].Split('=')[1]) : null; string entityFieldName = dateFilterValues[2].Split('=')[1]; viewConfiguration = converter.SetCustomFetchXml(viewConfiguration, dateFromValue, dateToValue, entityFieldName); int start = metaFilter.LastIndexOf(",date"); metaFilter = metaFilter.Substring(0, start); } } if (metaFilter.IndexOf(",prospect") > 0) { int start = metaFilter.LastIndexOf(",prospect"); viewConfiguration = converter.FilterProspect(viewConfiguration); metaFilter = metaFilter.Substring(0, start); } if (metaFilter.IndexOf(",statecode") > 0) { int start = metaFilter.LastIndexOf(",statecode"); string statecode = metaFilter.Substring(metaFilter.IndexOf("statecode=") + 10); viewConfiguration = converter.FilterRecordsbyStateCode(viewConfiguration, statecode); metaFilter = metaFilter.Substring(0, start); } if (metaFilter.IndexOf(",vehiclecolor") > 0) { int start = metaFilter.LastIndexOf(",vehiclecolor"); string vehicleColor = metaFilter.Substring(metaFilter.IndexOf("vehiclecolor=") + 13); viewConfiguration = converter.FilterRecordsbyVehicleColor(viewConfiguration, vehicleColor); metaFilter = metaFilter.Substring(0, start); } } viewConfiguration = converter.CustomFilterViews(viewConfiguration); // viewConfiguration = converter.FilterRootBusinessUnitRecords(viewConfiguration); #endregion //disable related record filtering for Vehicle Lookup in PO var serviceContext2 = dataAdapterDependencies.GetServiceContext(); SavedQueryView queryView = viewConfiguration.GetSavedQueryView(serviceContext2); if (queryView.Name == "Vehicle Lookup - PO Portal View") { applyRecordLevelFilters = false; } var viewDataAdapter = applyRelatedRecordFilter && (!string.IsNullOrWhiteSpace(filterRelationshipName) && !string.IsNullOrWhiteSpace(filterEntityName)) ? new CustomViewAdapter(viewConfiguration, dataAdapterDependencies, filterRelationshipName, filterEntityName, filterAttributeName, filterValue ?? Guid.Empty, page, search, sortExpression, filter, metaFilter, applyRecordLevelFilters) : new CustomViewAdapter(viewConfiguration, dataAdapterDependencies, page, search, sortExpression, filter, metaFilter, applyRecordLevelFilters); var result = viewDataAdapter.CustomFetchEntities(viewConfiguration); var resultRecords = result.Records; // var filteredRecords = converter.FilterSharedEntityScope(viewConfiguration, result.Records); // var globalRecords = converter.FilterRootBusinessUnitRecords(viewConfiguration, filterEntityName, filterRelationshipName, filterValue, search); //var combinedResults = filteredRecords.Union(globalRecords); // combinedResults = combinedResults.GroupBy(x => x.Id).Select(y => y.First()); //Custom Order By /* string[] order = sortExpression.Split(' '); * var count = 0; * * foreach (var combinedResult in resultRecords) * { * foreach (var attributes in combinedResult.Attributes) * { * var name = attributes.Key; * if (name.Equals(order[0])) * { * count++; * * var value = attributes.Value; * var valueType = value.GetType().Name; * if (valueType == "String") * { * if (order[1] == "DESC") * resultRecords = resultRecords.OrderByDescending(x => x.Contains(order[0]) ? x.Attributes[order[0]] : ""); * else * resultRecords = resultRecords.OrderBy(x => x.Contains(order[0]) ? x.Attributes[order[0]] : ""); * } * else if (valueType == "Money") * { * if (order[1] == "DESC") * resultRecords = resultRecords.OrderByDescending(x => x.Contains(order[0]) ? x.GetAttributeValue<Money>(order[0]).ToString() : ""); * else * resultRecords = resultRecords.OrderBy(x => x.Contains(order[0]) ? x.GetAttributeValue<Money>(order[0]).ToString() : ""); * } * else if (valueType == "OptionSetValue") * { * if (order[1] == "DESC") * resultRecords = resultRecords.OrderByDescending(x => x.Contains(order[0]) ? x.FormattedValues[order[0]] : ""); * else * resultRecords = resultRecords.OrderBy(x => x.Contains(order[0]) ? x.FormattedValues[order[0]] : ""); * } * else if (valueType == "EntityReference") * { * if (order[1] == "DESC") * resultRecords = resultRecords.OrderByDescending(x => x.GetAttributeValue<EntityReference>(order[0]) != null ? x.GetAttributeValue<EntityReference>(order[0]).Name : ""); * else * resultRecords = resultRecords.OrderBy(x => x.GetAttributeValue<EntityReference>(order[0]) != null ? x.GetAttributeValue<EntityReference>(order[0]).Name : ""); * } * break; * } * } * * if (count > 0) * break; * } * //Custom Order By Ends Here*/ if (result.EntityPermissionDenied) { var permissionResult = new EntityPermissionResult(true); return(Json(permissionResult)); } IEnumerable <EntityRecord> records; if (viewConfiguration.EnableEntityPermissions && AdxstudioCrmConfigurationManager.GetCrmSection().ContentMap.Enabled) { var serviceContext = dataAdapterDependencies.GetServiceContext(); var crmEntityPermissionProvider = new CrmEntityPermissionProvider(); records = resultRecords.Select(e => new EntityRecord(e, serviceContext, crmEntityPermissionProvider, viewDataAdapter.EntityMetadata, true)); } else { records = resultRecords.Select(e => new EntityRecord(e, viewDataAdapter.EntityMetadata)); } var totalRecordCount = result.TotalRecordCount; var data = new PaginatedGridData(records, totalRecordCount, page, pageSize); var json = Json(data); json.MaxJsonLength = int.MaxValue; // return(json); }
private ActionResult GetData(ViewConfiguration viewConfiguration, string sortExpression, string search, string filter, string metaFilter, int page, int pageSize = DefaultPageSize, bool applyRecordLevelFilters = true, bool applyRelatedRecordFilter = false, string filterRelationshipName = null, string filterEntityName = null, string filterAttributeName = null, Guid?filterValue = null, bool overrideMaxPageSize = false) { if (viewConfiguration == null) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, "Invalid Request.")); } if (pageSize < 0) { pageSize = DefaultPageSize; } if (pageSize > DefaultMaxPageSize && !overrideMaxPageSize) { Tracing.FrameworkInformation(GetType().FullName, "GetData", "pageSize={0} is greater than the allowed maximum page size of {1}. Page size has been constrained to {1}.", pageSize, DefaultMaxPageSize); pageSize = DefaultMaxPageSize; } var dataAdapterDependencies = new PortalConfigurationDataAdapterDependencies(requestContext: Request.RequestContext, portalName: viewConfiguration.PortalName); var viewDataAdapter = applyRelatedRecordFilter && (!string.IsNullOrWhiteSpace(filterRelationshipName) && !string.IsNullOrWhiteSpace(filterEntityName)) ? new ViewDataAdapter(viewConfiguration, dataAdapterDependencies, filterRelationshipName, filterEntityName, filterAttributeName, filterValue ?? Guid.Empty, page, search, sortExpression, filter, metaFilter, applyRecordLevelFilters) : new ViewDataAdapter(viewConfiguration, dataAdapterDependencies, page, search, sortExpression, filter, metaFilter, applyRecordLevelFilters); var result = viewDataAdapter.FetchEntities(); if (result.EntityPermissionDenied) { var permissionResult = new EntityPermissionResult(true); return(Json(permissionResult)); } IEnumerable <EntityRecord> records; if (viewConfiguration.EnableEntityPermissions && AdxstudioCrmConfigurationManager.GetCrmSection().ContentMap.Enabled) { var serviceContext = dataAdapterDependencies.GetServiceContext(); var crmEntityPermissionProvider = new CrmEntityPermissionProvider(); records = result.Records.Select(e => new EntityRecord(e, serviceContext, crmEntityPermissionProvider, viewDataAdapter.EntityMetadata, true)); } else { records = result.Records.Select(e => new EntityRecord(e, viewDataAdapter.EntityMetadata)); } var totalRecordCount = result.TotalRecordCount; var data = new PaginatedGridData(records, totalRecordCount, page, pageSize); var json = Json(data); json.MaxJsonLength = int.MaxValue; return(json); }