Ejemplo n.º 1
0
        public async Task <ActionResult <IEnumerable <Bicycle> > > GetAll([FromQuery] UserParams userParams)
        {
            string qString = Request.QueryString.Value;
            var    lambda  = LambdaBuilder <Bicycle> .Builder(Request.QueryString.Value);

            var bicycles = _context.Bicycle.Include(p => p.Paint).OrderByDescending(u => u.Customerid).AsQueryable();

            if (lambda != null)
            {
                bicycles = bicycles.Where(lambda);
                if (Request.Query["paint"].Count > 0)
                {
                    Expression paintEx = Expression.Default(typeof(bool));

                    var parameters        = Expression.Parameter(typeof(Bicycle), typeof(Bicycle).Name);
                    MemberExpression mem  = Expression.Property(parameters, typeof(Bicycle).GetProperty("Paint"));
                    var      prop         = Expression.Property(mem, "Colorlist");
                    string[] paintFilters = Request.Query["paint"][0].Split("|");
                    foreach (string f in paintFilters)
                    {
                        ConstantExpression cons = Expression.Constant(f);
                        paintEx = Expression.Or(paintEx, Expression.Equal(prop, cons));
                    }
                    Expression <Func <Bicycle, bool> > ex = Expression.Lambda <Func <Bicycle, bool> >(paintEx, parameters);
                    bicycles = bicycles.Where(ex);
                }
            }
            // do some filtering...
            // ...
            // ..
            await TimeStampTransaction();

            return(Ok(await PageList <Bicycle> .CreateAsync(bicycles, userParams.PageNumber, userParams.PageSize)));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <IEnumerable <Component> > > GetAll([FromQuery] UserParams userParams)
        {
            var lambda = LambdaBuilder <Component> .Builder(Request.QueryString.Value);

            var components = _context.Component.OrderByDescending(u => u.Componentid).AsQueryable();

            if (lambda != null)
            {
                components = components.Where(lambda);
            }

            await TimeStampTransaction();

            return(Ok(await PageList <Component> .CreateAsync(components, userParams.PageNumber, userParams.PageSize)));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> GetAll([FromQuery] UserParams userParams)
        {
            var lambda = LambdaBuilder <Customer> .Builder(Request.QueryString.Value);

            var customers = _context.Customer.OrderByDescending(u => u.Customerid).AsQueryable();

            if (lambda != null)
            {
                customers = customers.Where(lambda);
            }
            // do some filtering...
            // ...
            // ..

            await TimeStampTransaction();

            return(Ok(await PageList <Customer> .CreateAsync(customers, userParams.PageNumber, userParams.PageSize)));
        }