예제 #1
0
        public IHttpActionResult Post([FromBody] SearchModel model)
        {
            var result = new List <ProductViewModel>();

            var products = productManager.GetEntities();

            if (model != null && !String.IsNullOrEmpty(model.searchWord))
            {
                products = productManager.GetEntities().AsQueryable().
                           Where("Name.Contains(@0) || Number.Contains(@0)", model.searchWord).ToList();
            }

            result = products.ToList().Select(product => new ProductViewModel()
            {
                Id     = product.Id,
                Name   = product.Name,
                Number = product.Number,
            }).OrderBy(o => o.Name).ToList();

            return(Ok(result));
        }