public ActionResult Edit(int id, WebAuthorityCommands entity) { try { if (ModelState.IsValid) { var old = webAuthorityCommandsRepository.Find(id); old.ActionName = entity.ActionName; old.ClassName = entity.ClassName; old.Name = entity.Name; old.Feature = entity.Feature; old.LastModifyTime = DateTime.Now; webAuthorityCommandsRepository.Update(old); MvcExtensions.ReloadWebAuthorityCommands(); return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "请认真填写表单!"); return(View(entity)); } } catch (Exception) { ModelState.AddModelError("", "数据处理出错,请重新提交!"); return(View(entity)); } }
public ActionResult Create(WebAuthorityCommands entity) { try { if (ModelState.IsValid) { if (webAuthorityCommandsRepository.Find(i => i.Name.ToLower() == entity.Name.ToLower()) != null) { ModelState.AddModelError("", "这个按钮按钮已经在数据库里存在,请重新填写!"); return(View(entity)); } List <WebAuthorityCommands> list = webAuthorityCommandsRepository.GetModel().ToList(); var total = list.BinaryOr(i => i.Flag); var valid = GetValidNumber(total); entity.Flag = valid; if (valid == 0) { valid = webAuthorityCommandsRepository.GetModel().Max(i => i.Flag); entity.Flag = valid << 1; } webAuthorityCommandsRepository.Insert(entity); MvcExtensions.ReloadWebAuthorityCommands(); return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "请认真填写表单!"); return(View(entity)); } } catch (Exception) { ModelState.AddModelError("", "数据处理出错,请重新提交!"); return(View(entity)); } }