/// <summary> /// 添加一条用户密码历史记录 /// </summary> /// <param name="entity">记录实体</param> /// <returns></returns> public int Insert(T_USER_PASSWORD_HISTORY entity) { using (var dbContext = new DuPont_TestContext()) { dbContext.T_USER_PASSWORD_HISTORY.Add(entity); return(dbContext.SaveChanges()); } }
/// <summary> /// 修改密码逻辑事物 /// </summary> /// <param name="userInfo">用户信息</param> /// <param name="deleteHis">所要删除的用户密码历史记录</param> /// <returns></returns> public bool TranUpdatePwd(T_USER userInfo, T_USER_PASSWORD_HISTORY deleteHis) { bool result = true; using (var dbContext = new DuPont_TestContext()) { using (var tran = dbContext.Database.BeginTransaction()) { //更新用户表 int uURes = Update(userInfo); if (uURes <= 0) { result = false; } //删除密码历史表中最老的记录 if (result && deleteHis != null) { var entity = dbContext.T_USER_PASSWORD_HISTORY.Where(a => a.UserID == deleteHis.UserID && a.Password == deleteHis.Password).FirstOrDefault(); dbContext.T_USER_PASSWORD_HISTORY.Remove(entity); int delRes = dbContext.SaveChanges(); if (delRes <= 0) { result = false; } } if (result) { dbContext.T_USER_PASSWORD_HISTORY.Add(new T_USER_PASSWORD_HISTORY { UserID = userInfo.Id, Password = userInfo.Password, CreateTime = DateTime.Now }); int addRes = dbContext.SaveChanges(); if (addRes <= 0) { result = false; } } if (result) { tran.Commit(); } } } return(result); }
/// <summary> /// 删除一条密码历史记录 /// </summary> /// <param name="entity">记录实体</param> /// <returns></returns> public int Delete(T_USER_PASSWORD_HISTORY entity) { if (entity != null) { using (var dbContext = new DuPont_TestContext()) { var entityt = dbContext.T_USER_PASSWORD_HISTORY.Where(a => a.UserID == entity.UserID && a.Password == entity.Password).FirstOrDefault(); dbContext.T_USER_PASSWORD_HISTORY.Remove(entityt); return(dbContext.SaveChanges()); } } return(0); }
public int Update(T_USER_PASSWORD_HISTORY entity) { throw new NotImplementedException(); }