protected void txtSubmit_Click(object sender, EventArgs e) { using (ISession session = new Session()) { Magic.Sys.User user = Magic.Sys.User.Retrieve(session, this.UserId); if (user == null) { WebUtil.ShowError(this, "请重新登陆"); return; } if (this.txtOldPwd.Value != user.Password) { WebUtil.ShowError(this, "原密码不正确"); return; } if (this.txtNewPwd.Value != this.txtNewPwd2.Value) { WebUtil.ShowError(this, "2次输入的密码不正确"); return; } user.Password = this.txtNewPwd.Value; user.Update(session, "Password"); WebUtil.ShowMsg(this, "密码修改成功"); } }
protected void MagicItemCommand(object sender, MagicItemEventArgs e) { if (e.CommandName == "Delete") { //MagicToolBar的事件 bool deleted = false; using (ISession session = new Session()) { session.BeginTransaction(); try { foreach (RepeaterItem item in this.rptUser.Items) { HtmlInputCheckBox chk = item.FindControl("checkbox") as HtmlInputCheckBox; if (chk != null && chk.Checked && Cast.Int(chk.Value) > 0) { Magic.Sys.User user = Magic.Sys.User.Retrieve(session, Cast.Int(chk.Value)); if (user != null) { //逻辑删除,仅将状态update成UserStatus.Deleted user.Status = UserStatus.Deleted; user.ModifyBy = Magic.Security.SecuritySession.CurrentUser.UserId; user.ModifyTime = DateTime.Now; //Update方法有2个版本, //1. 只传ISession参数,将更新实体的所有属性 //2. 传一个属性名称的字符串数组,只更新指定的字段 user.Update(session, "Status", "ModifyBy", "ModifyTime"); deleted = true; } } } session.Commit(); if (deleted) { this.QueryAndBindData(session, this.magicPagerMain.CurrentPageIndex, this.magicPagerMain.PageSize, true); } WebUtil.ShowMsg(this, "选择的用户已经被删除", "操作成功"); } catch (Exception err) { session.Rollback(); WebUtil.ShowError(this, err); } } } }
public bool AuthenticateUser(string username, string password) { // UserBase user = null; if (ValidateUser(username, password, out user)) { SetCurrentUser(user); using (ISession session = new Session()) { User entity = (User)user; entity.LastLogonTime = DateTime.Now; entity.Update(session, "LastLogonTime"); } return(true); } return(false); }