예제 #1
0
 public async Task <bool> ContainsPublicCredentials(Guid userId, string credentialName, string credentialData)
 {
     return(await _query
            .Query <Entities.Authentication.Credential>()
            .Where(c => userId.CompareTo(c.OwnerId) == 0)
            .Where(c => c.Name == credentialName)
            .Where(c => c.Data == credentialData)
            .Where(c => c.Visibility == CredentialVisibility.Public)
            .AnyAsync());
 }
예제 #2
0
        public async Task <Farm> GetFarm(Guid farmId)
        {
            var farmEntity = await _query
                             .Query <Entities.Farm>()
                             .Where(farm => farm.Id.CompareTo(farmId) == 0)
                             .FirstOrDefaultAsync();

            return(farmEntity == null
                ? null
                : _transformer.ToModel <Farm>(farmEntity, TransformCommand.Query));
        }
예제 #3
0
        public async Task <User> GetUser(Guid userId)
        {
            var userEntity = await _query
                             .Query <Entities.Identity.User>()
                             .Where(user => user.Id.CompareTo(userId) == 0)
                             .FirstOrDefaultAsync();

            return(userEntity == null
                ? null
                : _transformer.ToModel <User>(userEntity, TransformCommand.Query));
        }
예제 #4
0
        public async Task <HarvestBatch> GetBatch(Guid batchId)
        {
            var batchEntity = await _query
                              .Query <Entities.HarvestBatch>(
                h => h.Farm,
                h => h.Harvests)
                              .Where(h => h.Id.CompareTo(batchId) == 0)
                              .FirstOrDefaultAsync();

            return(batchEntity == null
                ? null
                : _transformer.ToModel <HarvestBatch>(batchEntity, TransformCommand.Query));
        }
예제 #5
0
        public async Task <MultiFactorEventConfiguration> GetMultiFactorConfiguration(string eventLabel)
        {
            var data = await _query
                       .Query <Entities.Authentication.MultiFactorEventConfiguration>()
                       .Where(d => eventLabel == d.EventLabel)
                       .FirstOrDefaultAsync();

            return(_transformer.ToModel <MultiFactorEventConfiguration>(data, TransformCommand.Query));
        }
예제 #6
0
        public async Task <PolluxPolicy[]> GetAllPolicies()
        {
            //pull in all policies, transform them to models
            var policies = (await _query
                            .Query <Entities.Authorization.Policy>(p => p.Parent)
                            .ToListAsync())
                           .TransformQuery <Entities.Authorization.Policy, PolluxPolicy>(_transformer, TransformCommand.Query);

            return(ConstructPolicyTrees(policies));
        }
예제 #7
0
        public async Task <PolluxPolicy> GetPolicyById(Guid policyId)
        {
            var policyEntity = await _query
                               .Query <Entities.Authorization.Policy>(
                p => p.Parent)
                               .Where(p => p.Id.CompareTo(policyId) == 0)
                               .FirstOrDefaultAsync();

            return(policyEntity == null
                ? null
                : _transformer.ToModel <PolluxPolicy>(policyEntity, TransformCommand.Query));
        }
예제 #8
0
        public async Task <ArrayPage <Farmer> > GetAllFarmers(ArrayPageRequest request = null)
        {
            request = request?.Normalize() ?? ArrayPageRequest.CreateNormalizedRequest();
            var dataQuery = _query
                            .Query <Entities.Farmer>(d => d.User, d => d.Farms);

            var longCount = await dataQuery.LongCountAsync();

            var filtered = await dataQuery
                           .OrderBy(c => c.CreatedOn)
                           .Skip((int)(request.PageIndex * request.PageSize))
                           .Take((int)request.PageSize)
                           .ToArrayAsync();

            return(new ArrayPage <Farmer>
            {
                TotalLength = longCount,
                PageIndex = request.PageIndex.Value,
                PageSize = request.PageSize.Value,
                Page = filtered.TransformQuery <Entities.Farmer, Farmer>(
                    _transformer,
                    TransformCommand.Query)
            });
        }
예제 #9
0
        public async Task <ArrayPage <Cooperative> > GetAdminCooperatives(Guid userId, ArrayPageRequest request = null)
        {
            request = request?.Normalize() ?? ArrayPageRequest.CreateNormalizedRequest();
            var dataQuery = _query
                            .Query <Entities.CooperativeAdmin>(c => c.Cooperative.Farms)
                            .Where(c => userId.CompareTo(c.UserId) == 0)
                            .Select(c => c.Cooperative);

            var longCount = await dataQuery.LongCountAsync();

            var filtered = await dataQuery
                           .OrderBy(c => c.CreatedOn)
                           .Skip((int)(request.PageIndex * request.PageSize))
                           .Take((int)request.PageSize)
                           .ToArrayAsync();

            return(new ArrayPage <Cooperative>
            {
                TotalLength = longCount,
                PageIndex = request.PageIndex.Value,
                PageSize = request.PageSize.Value,
                Page = filtered.TransformQuery <Entities.Cooperative, Cooperative>(
                    _transformer,
                    TransformCommand.Query)
            });
        }