public ActionResult Delete(int id, FormCollection collection) { var entity = new School(); TryUpdateModel(entity); try { //var result = _db.Delete<School>(id); //if (result > 0) //{ // return RedirectToAction("Index"); //} var result = _db.Update <School>(DbKvs.New().Add("IsDel", true), s => s.Id == id); if (result > 0) { return(RedirectToAction("Index")); } ModelState.AddModelError(string.Empty, "删除失败"); return(View(entity)); } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); return(View(entity)); } }
public async Task <ActionResult> Delete(int id, IFormCollection collection) { var entity = new AppUser(); await TryUpdateModelAsync(entity); try { var result = await _db.UpdateAsync <AppUser>(id, DbKvs.New().Add("IsDelete", true)); if (result > 0) { return(RedirectToAction(nameof(Index))); } else { ModelState.AddModelError(string.Empty, "删除失败"); } } catch (Exception e) { ModelState.AddModelError(string.Empty, e.Message); } return(View(entity)); }
private static DbKvs ResolveNew(NewExpression node) { var kvs = DbKvs.New(); var members = node.Members; var args = node.Arguments; for (var i = 0; i < members.Count; i++) { var key = members[i].Name; var val = args[i].GetValue(); kvs.Add(key, val); } return(kvs); }