public ActionResult Create(FormCollection collection) { var entity = new School(); TryUpdateModel(entity); try { entity.CreateBy = "132"; entity.UpdateBy = "132"; entity.Owner = "132"; var result = _db.InsertIfNotExists(entity, s => s.SchoolName == entity.SchoolName); 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> Create(IFormCollection collection) { var entity = new AppUser(); await TryUpdateModelAsync(entity); if (ModelState.IsValid) { try { var result = _db.InsertIfNotExists(entity, u => u.No == entity.No); if (result > 0) { return(RedirectToAction(nameof(Index))); } ModelState.AddModelError(string.Empty, "创建失败"); } catch (Exception e) { ModelState.AddModelError(string.Empty, e.Message); } } await InitUi(); return(View(entity)); }