Пример #1
0
        public ActionResult Edit(PermissionEdit permissionEdit)
        {
            if (ModelState.IsValid)
            {
                if (permissionEdit.Id.HasValue)
                {
                    Permission permission = PermissionServices
                                            .LoadFirst(u => u.Id == permissionEdit.Id.Value);
                    if (permission == null)
                    {
                        return(Json(new Result
                        {
                            State = 0,
                            Message = "修改的权限不存在"
                        }));
                    }

                    permission.Name = permissionEdit.Name?.ToString();
                    permission.Sort = permissionEdit.Sort;
                    PermissionServices.EditEntity(permission);
                    return(Json(new Result
                    {
                        State = 1,
                        Message = "修改成功"
                    }));
                }
                else
                {
                    Permission permission = Mapper.Map <Permission>(permissionEdit);
                    permission.AddTime = DateTime.Now;
                    PermissionServices.AddEntity(permission);

                    return(Json(new Result <int>
                    {
                        State = 1,
                        Message = "添加成功",
                        Data = permission.Id
                    }));
                }
            }
            return(PartialView(permissionEdit));
        }