// GET: Customers public ActionResult Index(CustomerSearchOptions searchOptions) { if (!(Session["User"] is Admin)) { return(View("~/Views/Errors/Unauthorized.cshtml")); } var searchedCustomers = searchOptions .ApplyOn(db.Customers) .ToList(); ViewData["SearchOptions"] = searchOptions; return(View(searchedCustomers)); }
public IQueryable <Customer> SearchCustomer(CustomerSearchOptions options) { if (options == null) { //throw new ArgumentNullException("Null Options"); return(null); } var query = dbContext .Set <Customer>() .AsQueryable(); if (!string.IsNullOrWhiteSpace(options.FirstName)) { query = query.Where(c => c.Firstname == options.FirstName); } if (!string.IsNullOrWhiteSpace(options.LastName)) { query = query.Where(c => c.Lastname == options.LastName); } if (!string.IsNullOrWhiteSpace(options.VatNumber)) { query = query.Where(c => c.VatNumber == options.VatNumber); } if (options.CreatedFrom != default(DateTime)) { query = query.Where(c => c.Created >= options.CreatedFrom); } if (options.CreatedTo != default(DateTime)) { query = query.Where(c => c.Created <= options.CreatedTo); } if (options.CustomerId != null) { query = query.Where(c => c.CustomerId == options.CustomerId.Value); } query = query.Take(500); return(query); }
public IActionResult Search(CustomerSearchOptions options) { if (options == null) { return(BadRequest()); } var customers = customerService .SearchCustomer(options) .ToList(); if (customers == null) { return(NotFound()); } return(Json(customers)); }