public IHttpActionResult Get(SearchViewModel vm)
        {
            var page = vm.Page.GetValueOrDefault(0);
            var pageSize = vm.PageSize.GetValueOrDefault(10);
            var skipRows = (page - 1) * pageSize;

            var pred = PredicateBuilder.True<Constituent>();
            if (vm.IsUpdated != null) pred = pred.And(p => p.IsUpdated.HasValue == (vm.IsUpdated ?? null));
            if (!string.IsNullOrWhiteSpace(vm.Name)) pred = pred.And(p => p.Name.Contains(vm.Name));
            if (!string.IsNullOrWhiteSpace(vm.FinderNumber)) pred = pred.And(p => p.FinderNumber.Contains(vm.FinderNumber));
            if (!string.IsNullOrWhiteSpace(vm.LookupId)) pred = pred.And(p => p.LookupId.Contains(vm.LookupId));

            var list = db.Constituents.AsQueryable()
                .Where(pred).OrderBy(x => x.Id).Skip(skipRows).Take(pageSize).ProjectTo<ConstituentViewModel>().ToList();

            var totalCount = db.Constituents.Count();
            var filterCount = db.Constituents.Where(pred).Count();
            var TotalPages = (int)Math.Ceiling((decimal)filterCount / pageSize);

            vm.TotalCount = totalCount;
            vm.FilteredCount = filterCount;
            vm.TotalPages = TotalPages;
            vm.Items = list;

            return Ok(vm);
        }
Exemplo n.º 2
0
        public ActionResult GetFoundProducts(string searchString)
        {
            var products = searchString == "" ? _dataManager.Products.GetProducts() : _dataManager.Products.GetProductsByName(searchString);
            var productsCustomers = _dataManager.ProductsCustomers.GetProductsCustomers();

            if (products == null || productsCustomers == null) return RedirectToAction("Index", "Find");

            var model = new SearchViewModel {SearchResultList = new List<IProduct>()};
            model.SearchResultList = (from product in products
                                      join prodCust in productsCustomers
                                          on product.Id equals prodCust.ProductId
                                      where prodCust.CustomerId == (int) Session["UserId"]
                                      select product).ToList();

            return View("GetProducts",model);
        }
Exemplo n.º 3
0
 private void SetSearchResultListModel(ref SearchViewModel model, IEnumerable<IProduct> products)
 {
     model = new SearchViewModel {SearchResultList = new List<IProduct>()};
     foreach (var product in products)
         model.SearchResultList.Add(product);
 }