예제 #1
0
        public ActionResult Edit(RoleEdit roleEdit)
        {
            Role role = RoleServices
                        .LoadFirst(r => r.ID == roleEdit.ID.Value);

            if (role == null)
            {
                return(NotFound(new Result
                {
                    State = 0,
                    Message = "修改的角色不存在"
                }));
            }
            role = Mapper.Map(roleEdit, role);
            if (RoleServices.EditEntity(role))
            {
                return(Ok(new Result
                {
                    State = 1,
                    Message = "修改成功"
                }));
            }
            else
            {
                return(BadRequest(new Result
                {
                    State = 1,
                    Message = "修改失败"
                }));
            }
        }
 public ActionResult Edit(RoleEdit roleEdit)
 {
     if (ModelState.IsValid)
     {
         Role role = RoleServices
                     .LoadFirst(r => r.ID == roleEdit.ID.Value);
         if (role == null)
         {
             return(Json(new Result
             {
                 State = 0,
                 Message = "修改的角色不存在"
             }));
         }
         role = Mapper.Map(roleEdit, role);
         if (RoleServices.EditEntity(role))
         {
             return(Json(new Result
             {
                 State = 1,
                 Message = "修改成功"
             }));
         }
         else
         {
             return(Json(new Result
             {
                 State = 1,
                 Message = "修改失败"
             }));
         }
     }
     else
     {
         IEnumerable <object> errors = ModelStateToJson();
         return(Json(new Result <object>
         {
             State = 0,
             Message = "错误",
             Data = errors
         }));
     }
 }