コード例 #1
0
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="userId">用户编号</param>
        /// <param name="pwd">新密码</param>
        /// <param name="oldpwd">旧密码</param>
        /// <returns>修改结果</returns>
        public CustomResult  UpdatePassword(Guid userId, string pwd, string oldpwd)
        {
            using (DataSubmittedEntities db = new DataSubmittedEntities())
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    MD5Encryptor md5      = new MD5Encryptor();
                    string       password = md5.Encrypt(oldpwd);

                    var list = db.OT_User.Where(a => a.Id == userId & a.Password == password & a.IsDelete == (byte)EUserStatus.Normal).ToList();

                    if (list != null && list.Count > 0)
                    {
                        password = md5.Encrypt(pwd);
                        foreach (var info in list)
                        {
                            info.Password = password;
                        }
                        SessionManage.SetSession("UserInfo", null);
                        return(Result.SaveUpdateResult(db, transaction));
                    }
                    else
                    {
                        CustomResult pReturnValue = new CustomResult();
                        pReturnValue.ResultKey   = (byte)EResult.Fail;//程序已经使用多处,所有不变动
                        pReturnValue.ResultValue = Wttech.DataSubmitted.Common.Resources.TipInfo.OldPasswordError;
                        return(pReturnValue);
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// 保存用户信息到缓存中
        /// </summary>
        /// <param name="userId">用户编号</param>
        /// <param name="Session">存储用户信息缓存</param>
        private void SaveUserInfo(Guid userId)
        {
            using (DataSubmittedEntities db = new DataSubmittedEntities())
            {
                List <UserInfoViewModel> list = db.OT_User.Where(a => a.Id == userId & a.IsDelete == (byte)EUserStatus.Normal).Select(a => new UserInfoViewModel
                {
                    UserId   = a.Id,
                    UserName = a.Name,
                }).ToList();

                //给用户的角色赋值
                foreach (UserInfoViewModel model in list)
                {
                    model.RoleList = db.OT_UserRole.Where(a => a.UserId == userId && a.IsDelete == (byte)EDataStatus.Normal).Select(a => new RoleInfoViewModel
                    {
                        RoleId   = a.RoleId,
                        RoleName = a.OT_Role.Name
                    }).ToList();
                }

                SessionManage.SetSession("UserInfo", list[0]);
            }
        }