Exemplo n.º 1
0
        public IActionResult GetCpusWithFilter(
            [FromQuery] BasePartFiltringParameters basePartFiltringParameters)
        {
            if (basePartFiltringParameters == null)
            {
                return(BadRequest());
            }

            var cpuEntities = database.Read <CpuEntity>(basePartFiltringParameters);

            return(Ok(cpuEntities));
        }
        /// <summary>
        /// Returns filtered entities
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public IEnumerable <TEntity> Read <T>(BasePartFiltringParameters parameters)
        {
            var cpuCollection = entities as IEnumerable <TEntity>;

            if (parameters.MinPrice.HasValue)
            {
                cpuCollection = cpuCollection.Where(c => c.Price >= parameters.MinPrice);
            }
            if (parameters.MaxPrice.HasValue)
            {
                cpuCollection = cpuCollection.Where(c => c.Price <= parameters.MaxPrice);
            }

            return(cpuCollection.ToList());
        }