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));
     }
 }
 /// <summary>
 /// 删除按钮
 /// 注意:当按钮已经被分配,则不提供删除
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public ActionResult Delete(int id)
 {
     try
     {
         var entity = webAuthorityCommandsRepository.Find(id);
         var list   = webManageRoles_WebManageMenus_Authority_RRepository.GetModel().Where(i => (i.Authority & entity.Flag) == entity.Flag);
         if (list == null || list.Count() == 0)
         {
             //删除主表
             webAuthorityCommandsRepository.Delete(entity);
             MvcExtensions.ReloadWebAuthorityCommands();
             return(RedirectToAction("Index"));
         }
         else
         {
             return(Content("<script>alert('本功能按钮【已被使用】,不能进行删除!');location.href='/WebAuthorityCommand/Index';</script>"));
         }
     }
     catch (Exception)
     {
         return(RedirectToAction("Index"));
     }
 }
        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));
            }
        }