public RegionSet Update(RegionSet regionSet) { regionSet.LastEdit = DateTime.Now; _client.Cypher .Match("(rs:RegionSet)") .Where((RegionSet rs) => rs.RegionSetId == regionSet.RegionSetId) .Set("rs = {regionSet}") .WithParams(new { regionSet }) .ExecuteWithoutResults(); return(GetFullRegionSet(regionSet.RegionSetId)); }
public RegionSet Create(RegionSet regionSet) { regionSet.RegionSetId = Guid.NewGuid().ToString(); regionSet.LastEdit = DateTime.Now; _client.Cypher .Merge("(u:User { UserId: {OwnerId}})") .Merge("(rs:RegionSet { RegionSetId: {RegionSetId}})") .OnCreate() .Set("rs = {regionSet}") .Merge("(u)-[o:OWNS]->(rs)") .WithParams(new { regionSet.OwnerId, regionSet.RegionSetId, regionSet }) .ExecuteWithoutResults(); return(GetFullRegionSet(regionSet.RegionSetId)); }
public void Delete(RegionSet regionSet) { try { _client.Cypher .OptionalMatch("(rs:RegionSet)-[rel:CONTAINS*]->(n)") .Where((RegionSet rs) => rs.RegionSetId == regionSet.RegionSetId) .Delete("rel, rs, n") .ExecuteWithoutResults(); } catch { throw; } }
public List <Region> GetChildRegions(RegionSet regionSet) { var childRegions = _client.Cypher .Match("(rs:RegionSet)-[:CONTAINS]->(r2:Region)") .Where((RegionSet rs) => rs.RegionSetId == regionSet.RegionSetId) .Return((r2) => r2.CollectAs <Region>()) .Results.FirstOrDefault(); if (childRegions != null && childRegions.Any()) { return(childRegions.ToList()); } else { return(new List <Region>()); } }
public RegionSet CopyRegionSet(string regionSetId, string newOwnerId = null) { RegionSet regionSet = GetFullRegionSet(regionSetId); var copy = regionSet; copy.RegionSetId = string.Empty; if (!string.IsNullOrEmpty(newOwnerId)) { copy.OwnerId = newOwnerId; } copy = Create(copy); Dictionary <string, string> regionIdMap = new Dictionary <string, string>(); Dictionary <string, string> poiIdMap = new Dictionary <string, string>(); foreach (Region r in regionSet.AllRegions) { regionIdMap.Add(r.RegionId, CopyRegion(r.RegionId, copy.RegionSetId).RegionId); } foreach (PointOfInterest p in regionSet.AllPointsOfInterest) { poiIdMap.Add(p.PointOfInterestId, CopyPointOfInterest(p.PointOfInterestId, copy.RegionSetId).PointOfInterestId); } foreach (Region region in regionSet.AllRegions) { var fullRegion = GetFullRegion(region.RegionId); var mappedRegionId = regionIdMap[region.RegionId]; var mappedRegion = GetFullRegion(mappedRegionId); foreach (Region innerRegion in fullRegion.InnerRegions) { var mappedInnerRegionId = regionIdMap[innerRegion.RegionId]; AddRegionRelationship(mappedRegionId, mappedInnerRegionId); } foreach (PointOfInterest poi in fullRegion.PointsOfInterest) { var mappedPointOfInterestId = poiIdMap[poi.PointOfInterestId]; AddPointOfInterest(mappedRegionId, mappedPointOfInterestId); } } return(GetFullRegionSet(copy.RegionSetId)); }