Beispiel #1
0
        public IHttpActionResult Search(string search = "")
        {
            string query;
            IEnumerable <string> airports;

            if (IsFaaCode(search))
            {
                query    = $"SELECT airportname FROM `travel-sample` WHERE type = 'airport' AND faa = '{search.ToUpper()}'";
                airports = _context.Query <Airport>()
                           .Where(x => x.Faa == search.ToUpper())
                           .Select(x => x.Airportname);
            }
            else if (IsIcaoCode(search))
            {
                query    = $"SELECT airportname FROM `travel-sample` WHERE type = 'airport' AND icao = '{search.ToUpper()}'";
                airports = _context.Query <Airport>()
                           .Where(x => x.Icao == search.ToUpper())
                           .Select(x => x.Airportname);
            }
            else
            {
                query    = $"SELECT airportname FROM `travel-sample` WHERE type = 'airport' AND airportname LIKE '%{search}%'";
                airports = _context.Query <Airport>()
                           .Where(x => x.Airportname.Contains(search))
                           .Select(x => x.Airportname);
            }

            var airportNames = airports.ToList();
            var data         = airportNames.Select(airportname => new { airportname }).ToArray();

            return(Content(HttpStatusCode.OK, new Result(data, query)));
        }
Beispiel #2
0
        /// <summary>
        /// Loads all permissions the subject has granted to all clients.
        /// </summary>
        /// <param name="subject">The subject.</param>
        /// <returns>The permissions.</returns>
        public Task <IEnumerable <Consent> > LoadAllAsync(string subject)
        {
            var query =
                from c in _context.Query <ConsentWrapper>()
                where c.Model.Subject == subject
                select c.Model;

            return(Task.FromResult <IEnumerable <Consent> >(query.ToArray()));
        }
        /// <summary>
        /// Retrieves all data for a subject identifier.
        /// </summary>
        /// <param name="subject">The subject identifier.</param>
        /// <returns>
        /// A list of token metadata
        /// </returns>
        public Task <IEnumerable <ITokenMetadata> > GetAllAsync(string subject)
        {
            var query =
                from item in _context.Query <TokenWrapper>()
                where item.Model.SubjectId == subject
                select item.Model;
            var list = query.ToArray();

            return(Task.FromResult(list.Cast <ITokenMetadata>()));
        }
        /// <summary>
        /// Switches between two different queries depending on support for collections on the current version of Couchbase.
        /// </summary>
        /// <typeparam name="TBase">Base type to query if collections are not supported.</typeparam>
        /// <typeparam name="TCollection">Type to query if collections are supported. Should be annotated with <see cref="CouchbaseCollectionAttribute"/>.</typeparam>
        protected async Task <IQueryable <TBase> > SwitchIfCollectionsSupportedAsync <TBase, TCollection>(IBucketContext bucketContext)
            where TCollection : TBase
        {
            var versionProvider = TestSetup.Cluster.ClusterServices.GetRequiredService <IClusterVersionProvider>();
            var clusterVersion  = await versionProvider.GetVersionAsync() ?? FeatureVersions.DefaultVersion;

            if (clusterVersion.Version < new Version(7, 0, 0))
            {
                return(bucketContext.Query <TBase>());
            }

            return((IQueryable <TBase>)bucketContext.Query <TCollection>());
        }
Beispiel #5
0
        public void Delete(string id)
        {
            var airline = _bucketContext
                          .Query <Airline>()
                          .FirstOrDefault(x => N1QlFunctions.Meta(x).Id == id);

            if (airline == null)
            {
                return;
            }

            _bucketContext.Remove(airline);
        }
Beispiel #6
0
        /// <summary>
        /// Determines whether origin is allowed.
        /// </summary>
        /// <param name="origin">The origin.</param>
        /// <returns></returns>
        public Task <bool> IsOriginAllowedAsync(string origin)
        {
            var query =
                from client in _context.Query <ClientWrapper>()
                from url in client.Model.AllowedCorsOrigins
                select url;

            var urls = new List <string>();

            foreach (var url in query)
            {
                urls.Add(GetOrigin(url));
            }

            var result = urls.Contains(origin, StringComparer.OrdinalIgnoreCase);

            if (result)
            {
                _logger.LogInformation("Client list checked and origin: {0} is allowed", origin);
            }
            else
            {
                _logger.LogInformation("Client list checked and origin: {0} is not allowed", origin);
            }

            return(Task.FromResult(result));
        }
Beispiel #7
0
 public List <Person> GetAll()
 {
     return(_context.Query <Person>()
            .ScanConsistency(ScanConsistency.RequestPlus) // waiting for the indexing to complete before it returns a response
            .OrderBy(p => p.Name)
            .ToList());
 }
Beispiel #8
0
        /// <summary>
        /// Gets all scopes.
        /// </summary>
        /// <returns>
        /// List of scopes
        /// </returns>
        public Task <IEnumerable <Scope> > FindScopesAsync(IEnumerable <string> scopeNames)
        {
            if (scopeNames == null)
            {
                throw new ArgumentNullException("scopeNames");
            }

            var list = new List <Scope>();

            foreach (var scopeName in scopeNames)
            {
                var scopes = from s in _context.Query <ScopeWrapper>()
                             where s.Model.Name == scopeName
                             select s.Model;

                list.AddRange(scopes);
            }

            return(Task.FromResult <IEnumerable <Scope> >(list));
        }
        /// <summary>
        /// Finds a client by id
        /// </summary>
        /// <param name="clientId">The client id</param>
        /// <returns>
        /// The client
        /// </returns>
        public Task <Client> FindClientByIdAsync(string clientId)
        {
            var id    = ClientWrapper.ClientWrapperId(clientId);
            var query =
                from client in _context.Query <ClientWrapper>()
                where client.Id == id && client.Model.Enabled
                select client.Model;

            var first = query.SingleOrDefault();

            return(Task.FromResult(first));
        }
Beispiel #10
0
 public IQueryable <T> FindAll()
 {
     return(_context.Query <T>()
            .ScanConsistency(ScanConsistency.RequestPlus) // waiting for the indexing to complete before it returns a response
            );
 }
        public async Task <int> Count(Expression <Func <T, bool> > filter = null)
        {
            var query = _context.Query <T>().Where(t => t.Type == typeof(T).Name).Where(filter).Count();

            return(await Task.FromResult(query));
        }
        public async Task <IList <T> > GetList(Expression <Func <T, bool> > filter = null)
        {
            var query = filter == null?_context.Query <T>().Where(t => t.Type == typeof(T).Name.ToLower()) : _context.Query <T>().Where(t => t.Type == typeof(T).Name.ToLower()).Where(filter);

            return(await Task.FromResult(query.ToList()));
        }