Beispiel #1
0
        public IActionResult Index([FromForm] RoleAddEditPostModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new AjaxResult()
                {
                    Status = "error", ErrorMsg = MvcHelper.GetValidMsg(ModelState)
                }));
            }

            try
            {
                using (var tran = new TransactionScope())
                {
                    var roleId = _roleService.AddOrEdit(model.Id, model.Name, model.Remark);
                    if (roleId <= 0)
                    {
                        return(Json(new AjaxResult()
                        {
                            Status = "error", ErrorMsg = "已存在相同的角色名称"
                        }));
                    }

                    _menuService.AddMenuIds(roleId, model.MenuIds);
                    tran.Complete();
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
                return(Json(new AjaxResult()
                {
                    Status = "error", ErrorMsg = "出错了,详见错误日志"
                }));
            }


            return(Json(new AjaxResult()
            {
                Status = "ok"
            }));
        }