コード例 #1
0
        public virtual async Task <User> GetByEmail(string email, CancellationToken cancellationToken)
        {
            var container = await GetContainer(cancellationToken);

            var query = CosmosDbQueryBuilder <User> .GetQuery(container.Id).Append("c.email = {0}", nameof(email), email);

            var iterator = container.GetItemQueryIterator <User>(query);

            return(await iterator.ReadFirstOrDefault(cancellationToken));
        }
コード例 #2
0
        public virtual async Task <User> GetByUsernameAndPassword(string username, string password, CancellationToken cancellationToken)
        {
            var container = await GetContainer(cancellationToken);

            var query = CosmosDbQueryBuilder <User> .GetQuery(container.Id)
                        .Append("c.username = {0}", nameof(username), username)
                        .Append("c.password = {0}", nameof(password), password);

            var iterator = container.GetItemQueryIterator <User>(query);

            return(await iterator.ReadFirstOrDefault(cancellationToken));
        }
コード例 #3
0
        public virtual async Task <int> CountByParameters(QueryUsersParameters parameters, CancellationToken cancellationToken)
        {
            var container = await GetContainer(cancellationToken);

            var query = CosmosDbQueryBuilder <User> .GetQuery("value count(1)", container.Id)
                        .AppendIf(() => !string.IsNullOrWhiteSpace(parameters.Firstname), "c.firstName = {0}", nameof(parameters.Firstname), parameters.Firstname)
                        .AppendIf(() => !string.IsNullOrWhiteSpace(parameters.Email), "c.email = {0}", nameof(parameters.Email), parameters.Email);

            var iterator = container.GetItemQueryIterator <int>(query);

            return(await iterator.ReadFirstOrDefault(cancellationToken));
        }
コード例 #4
0
        public virtual async Task <IList <User> > QueryByParameters(QueryUsersParameters parameters, CancellationToken cancellationToken)
        {
            var container = await GetContainer(cancellationToken);

            var query = CosmosDbQueryBuilder <User> .GetQuery(container.Id)
                        .AppendIf(() => !string.IsNullOrWhiteSpace(parameters.Firstname), "c.firstName = {0}", nameof(parameters.Firstname), parameters.Firstname)
                        .AppendIf(() => !string.IsNullOrWhiteSpace(parameters.Email), "c.email = {0}", nameof(parameters.Email), parameters.Email)
                        .GetPage(parameters.PageSize, parameters.PageIndex);

            var iterator = container.GetItemQueryIterator <User>(query);

            return(await iterator.ReadAll(cancellationToken).ToListAsync());
        }
コード例 #5
0
        public virtual async Task <IList <Game> > QueryByParameters(QueryParameters parameters, CancellationToken cancellationToken)
        {
            var container = await GetContainer(cancellationToken);

            var query = CosmosDbQueryBuilder <Game> .GetQuery(container.Id)
                        .AppendIf(() => !string.IsNullOrWhiteSpace(parameters.Category), "c.category = {0}", nameof(parameters.Category), parameters.Category)
                        .AppendIf(() => !string.IsNullOrWhiteSpace(parameters.Description), "CONTAINS(c.description, {0}, true)", nameof(parameters.Description), parameters.Description)
                        .AppendIf(() => !string.IsNullOrWhiteSpace(parameters.Name), "CONTAINS(c.name, {0}, true)", nameof(parameters.Name), parameters.Name)
                        .OrderByIf(() => !string.IsNullOrWhiteSpace(parameters.OrderBy), $"c.{parameters.OrderBy.ToCamelCase()}", parameters.IsDescending)
                        .GetPage(parameters.PageSize, parameters.PageIndex);

            var iterator = container.GetItemQueryIterator <Game>(query);

            return(await iterator.ReadAll(cancellationToken).ToListAsync());
        }