private void btnConfirm_Click(object sender, RoutedEventArgs e) { UserInfo_VM ui_vm = gridMyInfoTab.DataContext as UserInfo_VM; if (ui_vm != null) { if (ui_vm.IsModelValid()) { try { UserInfo_API_Put userput = Mapper.Map <UserInfo_VM, UserInfo_API_Put>(ui_vm); WebApiClientHelper.DoJsonRequest <UserInfo_API_Put>(GlobalData.GetResUri(string.Format("usersinfo/{0}", ui_vm.UserName)), EnuHttpMethod.Put, objToSend: userput, tick: ui_vm.UpdateTicks); } catch (ClientException ex) { ui_vm.SetExtraError(ex.Message); //这是Popup以外的另一种异常显示方式 return; } LoadMyInfo(); Commands.ShowPopupAlert.Execute(new ShowPopupAlertParam { AlertMessage = "修改信息成功.", AlertType = EnuPopupAlertType.Info }, this); Commands.GoToViewMode.Execute(null, this); } } }
// PUT api/usersinfo/{username} // 更新用户信息,非管理员只能更新自己的 public void Put(string id, UserInfo_API_Put userinfo, long updateticks) { this.CheckUserName(id); this.CheckAdministrator(id); //非管理员忽略掉Role的修改 if (this.GetUserRole() != RoleType.ADMINISTARTOR) { userinfo.Role = null; } UserInfo_BLL ui_bll = Mapper.Map <UserInfo_BLL>(userinfo); ui_bll.UserName = id; ui_bll.UpdateTicks = updateticks; Managers.s_userManager.SetUser(ui_bll); }