Custom search is achieved by setting .CustomSearch(true) and adding a SearchForm action in the Lookup controller which will render the custom SearchForm view
using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Mvc;
using AweCoreDemo.Models;
using Omu.AwesomeMvc; using System.Threading.Tasks; using AweCoreDemo.Data; using AweCoreDemo.Utils.Awesome;
namespace AweCoreDemo.Controllers.Awesome.MultiLookup { public class MealsCustomSearchMultiLookupController : Controller { private readonly MyContext mcx = new MyContext();// mock EF Db context
public MealsCustomSearchMultiLookupController() {
}
// when CustomSearch(true) this action will be rendered instead of the default search public IActionResult SearchForm() { return PartialView(); }
public async Task<IActionResult> GetItems(IEnumerable<int> v) { var items = new List<Meal>();
if (v != null) { items = await mcx.Meals .Where(o => v.Contains(o.Id)).ToListAsync(); }
return Json(items.Select(meal => new KeyContent(meal.Id, meal.Name))); }
public async Task<IActionResult> Search(int[] selected, int[] categories, int page, string search = "") { selected = selected ?? new int[] { }; categories = categories ?? new int[] { };
var query = mcx.Meals .Where(o => o.Name.Contains(search) && !selected.Contains(o.Id));
if (categories.Any()) { query = query.Where(o => categories.Contains(o.Category.Id)); }
var res = await EFAweUtil.BuildListAsync(query, page, keyContentFunc: o => new KeyContent(o.Id, o.Name));
return Json(res); }
public async Task<IActionResult> Selected(int[] selected) { var items = new List<Meal>();