public Guid Execute(string firstEntity, Guid firstId, string intersectionEntity, string secondEntity, Guid secondId) { var newId = Guid.NewGuid(); var firstAttributeInIntersection = RelationshipUtility.GetFirstIntersectionAttribute(firstEntity, secondEntity); var secondAttributeInIntersection = RelationshipUtility.GetSecondIntersectionAttribute(firstEntity, secondEntity); GenericValuesService.SetContextFile(intersectionEntity); var intersectionSet = GenericValuesService.GetStoredData(); foreach (var item in intersectionSet.Values) { item.Values[firstAttributeInIntersection] = Guid.Parse((string)item.Values[firstAttributeInIntersection]); item.Values[secondAttributeInIntersection] = Guid.Parse((string)item.Values[secondAttributeInIntersection]); } var record = intersectionSet.Values.FirstOrDefault(k => k.Values.ContainsKey(firstAttributeInIntersection) && k.Values.ContainsKey(secondAttributeInIntersection) && (Guid)k.Values[firstAttributeInIntersection] == firstId && (Guid)k.Values[secondAttributeInIntersection] == secondId); if (record != null) { throw new Exception("Records already associated"); } GenericValuesService.SetContextFile(firstEntity); var firstEntitySet = GenericValuesService.GetStoredData(); GenericValuesService.SetContextFile(secondEntity); var secondEntitySet = GenericValuesService.GetStoredData(); var firstRecord = firstEntitySet.Values.First(k => k.Id == firstId); var secondRecord = secondEntitySet.Values.First(k => k.Id == secondId); GenericValuesService.SetContextFile(intersectionEntity); intersectionSet.Values.Add(new DataRecord(newId, new Dictionary <string, object>() { { firstAttributeInIntersection, firstId }, { secondAttributeInIntersection, secondId } })); GenericValuesService.SaveStoredData(intersectionSet); return(newId); }
public DataSet Execute(string firstEntity, Guid mainId, string intersectionEntity, string secondEntity) { var firstAttributeInIntersection = RelationshipUtility.GetFirstIntersectionAttribute(firstEntity, secondEntity); var secondAttributeInIntersection = RelationshipUtility.GetSecondIntersectionAttribute(firstEntity, secondEntity); GenericValuesService.SetContextFile(intersectionEntity); var currentIntersectionValues = GenericValuesService.GetStoredData() ?? new DataSet(); foreach (var item in currentIntersectionValues.Values) { item.Values["Id"] = item.Id; } foreach (var item in currentIntersectionValues.Values) { item.Values[firstAttributeInIntersection] = Guid.Parse((string)item.Values[firstAttributeInIntersection]); item.Values[secondAttributeInIntersection] = Guid.Parse((string)item.Values[secondAttributeInIntersection]); } var filteredIntersectionValues = currentIntersectionValues.Values .Where(k => (Guid)k.Values[secondAttributeInIntersection] == mainId) .Select(k => (Guid)k.Values[firstAttributeInIntersection]) .ToList(); var returnInstance = new DataSet(firstEntity); if (filteredIntersectionValues.Any()) { GenericValuesService.SetContextFile(firstEntity); var currentRelatedValues = GenericValuesService.GetStoredData() ?? new DataSet(); var relatedRecordValues = currentRelatedValues.Values .Where(k => filteredIntersectionValues.IndexOf(k.Id) > -1) .ToList(); returnInstance.Values = relatedRecordValues; //returnInstance.EntityLogicalName = intersectionEntity; } return(returnInstance); }
public void Execute(string firstEntity, Guid firstId, string intersectionEntity, string secondEntity, Guid secondId) { var firstAttributeInIntersection = RelationshipUtility.GetFirstIntersectionAttribute(firstEntity, secondEntity); var secondAttributeInIntersection = RelationshipUtility.GetSecondIntersectionAttribute(firstEntity, secondEntity); GenericValuesService.SetContextFile(intersectionEntity); var intersectionSet = GenericValuesService.GetStoredData(); foreach (var item in intersectionSet.Values) { item.Values[firstAttributeInIntersection] = Guid.Parse((string)item.Values[firstAttributeInIntersection]); item.Values[secondAttributeInIntersection] = Guid.Parse((string)item.Values[secondAttributeInIntersection]); } var record = intersectionSet.Values.First(k => k.Values.ContainsKey(firstAttributeInIntersection) && k.Values.ContainsKey(secondAttributeInIntersection) && (Guid)k.Values[firstAttributeInIntersection] == firstId && (Guid)k.Values[secondAttributeInIntersection] == secondId); intersectionSet.Values.Remove(record); GenericValuesService.SaveStoredData(intersectionSet); }