Esempio n. 1
0
        public async Task <List <Entities.User> > GetByUsername(string userName)
        {
            DocumentClient client = await _documentClientFactory.GetClient();

            FeedOptions queryOptions = new FeedOptions {
                MaxItemCount = -1
            };

            IQueryable <Entities.User> userQuery = client.CreateDocumentQuery <Entities.User>(
                CreateDocumentCollectionUri(), queryOptions)
                                                   .Where(u => u.UserName == userName);

            return(userQuery.ToList());
        }
        public async void MainTest()
        {
            var config     = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
            var dbSettings = Options.Create(new DocumentDbSettings
            {
                AuthKey    = config["AuthKey"],
                DatabaseId = config["DatabaseId"],
                Uri        = config["Uri"],
                MaxRetryAttemptsOnThrottledRequests = int.Parse(config["MaxRetryAttemptsOnThrottledRequests"]),
                MaxRetryWaitTimeInSeconds           = int.Parse(config["MaxRetryWaitTimeInSeconds"])
            });
            var documentClientFactory = new DocumentClientFactory(dbSettings);
            var documentClient        = documentClientFactory.GetClient();

            try
            {
                await new DatabaseProviderTestFixture(documentClientFactory).RunOrderedTest();

                await new GenericCollectionProviderTestFixture(documentClientFactory).RunOrderedTest();

                await new GenericRepositoryTestFixture(documentClientFactory).RunOrderedTest();
            }
            finally
            {
                documentClient.DeleteDatabaseAsync(
                    UriFactory.CreateDatabaseUri(documentClientFactory.GetDatabaseId()))
                .Wait();
            }
        }
Esempio n. 3
0
        public async Task InitializeStorage()
        {
            DocumentClient client = await _documentClientFactory.GetClient();

            await client.CreateDatabaseIfNotExistsAsync(new Database { Id = DatabaseName });

            await client.CreateDocumentCollectionIfNotExistsAsync(UriFactory.CreateDatabaseUri(DatabaseName), new DocumentCollection { Id = UserService.CollectionName });

            await client.CreateDocumentCollectionIfNotExistsAsync(UriFactory.CreateDatabaseUri(DatabaseName), new DocumentCollection { Id = ArtistService.CollectionName });
        }
Esempio n. 4
0
        public async Task <List <ClassificationCategory> > GetByUserId(string userId)
        {
            DocumentClient client = await _documentClientFactory.GetClient();

            FeedOptions queryOptions = new FeedOptions {
                MaxItemCount = -1
            };

            IQueryable <ClassificationCategory> categoryQuery = client.CreateDocumentQuery <ClassificationCategory>(
                CreateDocumentCollectionUri(), queryOptions)
                                                                .Where(u => u.UserId == userId);

            return(categoryQuery.ToList());
        }
Esempio n. 5
0
        public async Task <List <Artist> > Search(string userId, ArtistSearchCriteria criteria)
        {
            DocumentClient client = await _documentClientFactory.GetClient();

            FeedOptions queryOptions = new FeedOptions {
                MaxItemCount = 20
            };

            StringBuilder builder = new StringBuilder();

            builder.Append("SELECT a.Id, a.Name FROM a ");
            for (int i = 0; i < criteria.Classifications.Count; i++)
            {
                builder.Append($"JOIN c{i} IN a.Classifications ");
            }
            builder.Append($"WHERE CONTAINS(UPPER(a.Name), UPPER('{criteria.Name}')) ");
            for (int i = 0; i < criteria.Classifications.Count; i++)
            {
                var classification = criteria.Classifications[i];
                builder.Append($"AND c{i}.ClassificationCategoryId = '{classification.ClassificationCategoryId}' ");
                if (!string.IsNullOrWhiteSpace(classification.ClassificationTagId))
                {
                    builder.Append($"AND c{i}.ClassificationTagId = '{classification.ClassificationTagId}' ");
                }
                if (classification.RangeValue.HasValue)
                {
                    builder.Append($"AND c{i}.RangeValue = {classification.RangeValue} ");
                }
            }
            builder.Append("ORDER BY a.Name");


            IQueryable <Artist> artistQuery = client.CreateDocumentQuery <Artist>(
                CreateDocumentCollectionUri(), builder.ToString(), queryOptions);

            return(artistQuery.ToList());
        }