using AweCoreDemo.Data; using AweCoreDemo.Models; using AweCoreDemo.Utils.Awesome; using Microsoft.AspNetCore.Mvc; using Omu.AwesomeMvc; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks;
namespace AweCoreDemo.Controllers.Awesome.MultiLookup { public class MealsMultiLookupController : Controller { private readonly MyContext mcx = new MyContext();// mock EF Db context
public MealsMultiLookupController() {
}
public async Task<IActionResult> GetItems(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 page, string search) { selected = selected ?? new int[] { };
var query = mcx.Meals.Filter(search, o => o.Name).Where(o => !selected.Contains(o.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>();
using AweCoreDemo.Data; using AweCoreDemo.Models; using AweCoreDemo.Utils.Awesome; using Microsoft.AspNetCore.Mvc; using Omu.AwesomeMvc; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks;
namespace AweCoreDemo.Controllers.Awesome.MultiLookup { public class MealsCustomItemMultiLookupController : Controller { private readonly MyContext mcx = new MyContext();// mock EF Db context
public MealsCustomItemMultiLookupController() {
}
public IActionResult SearchForm() { return PartialView(); }
public async Task<IActionResult> GetItems(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 page, string search) { selected = selected ?? new int[] { };
var query = mcx.Meals.Include(o => o.Category) .Where(o => !selected.Contains(o.Id));
query = query.Filter(search, o => o.Name);
var res = await EFAweUtil.BuildListAsync( query, page, setContentFunc: (items) => this.RenderPartialView("items", items));
return Json(res); }
public async Task<IActionResult> Selected(IEnumerable<int> selected) { var query = mcx.Meals.AsQueryable();
var res = await EFAweUtil.BuildListAsync( query, setContentFunc: (items) => this.RenderPartialView("items", items));
return Json(res); }
// used by the details button, in items view public async Task<IActionResult> Details(int id) { return PartialView(await mcx.FindAsync<Meal>(id)); } } }