Ejemplo n.º 1
0
        public async Task <dynamic> GetUserTransportations(Guid userId, DateTime periodStart, DateTime periodEnd)
        {
            var userTransportationRelationship             = new UserTransportationRelationship("user", "transportation");
            var transportationCapturedLocationRelationship =
                new TransportationCapturedLocationRelationship("transportation", "capturedLocation");

            var query = new CypherFluentQuery(_graphClientFunc)
                        .Match("(user:User{azureId: {userId}})")
                        .WithParam("userId", userId)
                        .MatchRelationship(userTransportationRelationship)
                        .Match("(transportation:Transportation)")
                        .MatchRelationship(transportationCapturedLocationRelationship)
                        .Where("capturedLocation.capturedDateTimeUtc >= {periodStart} " +
                               "AND capturedLocation.capturedDateTimeUtc <= {periodEnd}")
                        .WithParam("periodStart",
                                   periodStart.ToUniversalTime().Subtract(DateTime.MinValue.AddYears(1969)).TotalSeconds)
                        .WithParam("periodEnd",
                                   periodEnd.ToUniversalTime().Subtract(DateTime.MinValue.AddYears(1969)).TotalSeconds)
                        .Return((transportation, capturedLocation) => new
            {
                transportation    = transportation.As <Transportation>(),
                capturedLocations = capturedLocation.CollectAs <CapturedLocation>()
            });
            var result = await _repositoryPolicy.ExecuteAsync(async() => await query.ResultsAsync);

            return(result);
        }
Ejemplo n.º 2
0
        private async Task FluentQueryMethod(Dictionary <Guid, List <CapturedLocation> > locationDictionary)
        {
            var cypherFluentQuery   = _cypherFluentQuery;
            var transportationCount = 0;
            var locationCount       = 0;

            foreach (var transportationLocations in locationDictionary)
            {
                if (transportationCount != 0)
                {
                    cypherFluentQuery = cypherFluentQuery.With("1 as dummy");
                }

                var transportation = new Transportation {
                    TransportationId = transportationLocations.Key
                };
                var transportationKey = $"transportation_{transportationCount}";

                cypherFluentQuery = cypherFluentQuery.MatchEntity(transportation, transportationKey);

                foreach (var location in transportationLocations.Value)
                {
                    var locationKey  = $"capturedLocation_{locationCount}";
                    var relationship = new TransportationCapturedLocationRelationship(transportationKey, locationKey);
                    cypherFluentQuery = cypherFluentQuery
                                        .CreateEntity(location, locationKey)
                                        .CreateRelationship(relationship);

                    locationCount++;
                }

                transportationCount++;
            }

            await cypherFluentQuery.ExecuteWithoutResultsAsync();
        }