public IActionResult GridGetItems(GridParams g, string search = "") { var query = Db.Dinners.Where(o => o.Name.Contains(search)).AsQueryable();
var model = new GridModelBuilder<Dinner>(query, g) { KeyProp = o => o.Id, // needed for api select, update, tree, nesting, EF Map = MapToGridModel, GetItem = () => Db.Get<Dinner>(Convert.ToInt32(g.Key)), // used when calling api.update (signalrSync.js) };
return Json(model.Build()); }
[HttpPost] public IActionResult Save(DinnerInput input) { // custom validation example if (ModelState.IsValid && input.Name.Contains("asdf")) { ModelState.AddModelError("Name", "Name can't contain asdf"); }
if (ModelState.IsValid) { var isCreate = !input.Id.HasValue;
var ent = isCreate ? new Dinner() : Db.Dinners.FirstOrDefault(o => o.Id == input.Id);
if (ent == null) { throw new Exception("Item doesn't exist anymore, id:" + input.Id); }