public JsonResult CreateButton(ButtonViewModel buttonViewModel)
 {
     if (!IsButtonSum())
     {
         return Json(new { ErrorMessage = "主菜单按钮个数必须小于等于三个" });
     }
     Button button = new Button
     {
         AddTime = DateTime.Now,
         UserId = WebSecurity.GetUserId(User.Identity.Name),
         type = "click",
         IsOrder = 0,
         name = buttonViewModel.name
     };
     if (ModelState.IsValid)
     {
         _buttonRepository.Add(button);
         _buttonRepository.Context.Commit();
         button.key = "Button_click_" + button.ButtonID;
         _buttonRepository.Update(button);
         _buttonRepository.Context.Commit();
         buttonViewModel = Mapper.Map<ButtonViewModel>(button);
         return Json(buttonViewModel);
     }
     return Json(new { ErrorMessage = ModelState.Values.ToList()[0].Errors.ToList()[0].ErrorMessage });
 }
        public JsonResult EditButton(ButtonViewModel buttonViewModel)
        {
            try
            {
                Button Button = _buttonRepository.GetByKey(buttonViewModel.ID);
                if (!String.IsNullOrEmpty(buttonViewModel.name))
                {
                    Button.name = buttonViewModel.name;
                }

                Button.AddTime = DateTime.Now;
                Button.UserId = WebSecurity.GetUserId(User.Identity.Name);
                Button.IsOrder = 0;
                Button.key = "Button_click_" + Button.ButtonID.ToString();
                Button.type = "click";
                if (ModelState.IsValid)
                {
                    _buttonRepository.Update(Button);
                    _buttonRepository.Context.Commit();
                    buttonViewModel = Mapper.Map<Button, ButtonViewModel>(Button);
                    return Json(buttonViewModel);
                }
                else
                {
                    return Json(new { ErrorMessage = ModelState.Values.ToList()[0].Errors.ToList()[0].ErrorMessage });
                }
            }
            catch (ErrorJsonResultException ex)
            {
                return Json(new { ErrorMessage = ex.JsonResult.errcode + "," + ex.JsonResult.errmsg });
            }
        }