///// <summary> ///// 作者:Kylin ///// 时间:2015.07.29 ///// 描述:根据Phone 获取学员信息 ///// </summary> ///// <param name="mobile"></param> ///// <param name="userId"></param> ///// <returns></returns> //public static UserInfoByMobileModel GetUserInfoByMobile(string mobile) //{ // var userModel = new UserInfoByMobileModel() { MobilePhone = mobile }; // if (string.IsNullOrEmpty(mobile)) // return null; // var sa = string.Empty; // var cc = string.Empty; // using (var edb = new EmeEntities()) // { // var user = (from u in edb.UserInfo // join us in edb.User on u.UserId equals us.Id // join ub in edb.UserBranch on u.UserId equals ub.UserId // where u.Mobile == mobile && ub.IsMain // && u.Status == ConvertEnum.StatusTypeForActive // && ub.Status == ConvertEnum.StatusTypeForActive // && us.Status == ConvertEnum.StatusTypeForActive // select new // { // Mobile = u.Mobile, // BranchId = ub.BranchId, // UserType = us.UserType, // UserId = u.UserId, // CName = u.CName, // EName = u.EName, // }).FirstOrDefault(); // // 信息 // if (user != null) // { // var branch = edb.Branch.FirstOrDefault( // b => b.Id == user.BranchId && b.Status == ConvertEnum.StatusTypeForActive); // if (branch != null) // { // userModel.UserId = user.UserId; // userModel.CName = user.CName; // userModel.EName = user.EName; // if (user.UserType == ConvertEnum.UserTypeForStudent && edb.Student.Any(p => p.UserId == user.UserId && p.Status == ConvertEnum.StatusTypeForActive))//学员 // { // userModel.UserType = BaseEnum.EmeEnum<UserType>.GetEnameByValue(user.UserType); // } // else if (edb.Teacher.Any(p => p.UserId == user.UserId && p.Status == ConvertEnum.StatusTypeForActive)) //老师 // { // var teacherUser = edb.Teacher.FirstOrDefault(p => p.UserId == user.UserId && p.Status == ConvertEnum.StatusTypeForActive); // if (null != teacherUser) // { // var teachType = BaseEnum.EmeEnum<TeacherType>.GetScodeByValue(teacherUser.TeacherType); // userModel.UserType = teachType; // } // } // else //员工 // { // userModel.UserType = BaseEnum.EmeEnum<UserType>.GetScodeByValue(user.UserType); // } // //用户岗位user job // var userORGType = edb.UserJob.Where(p => p.UserId == user.UserId && p.Status == ConvertEnum.StatusTypeForActive).Select(p => p.Job.SCode); // foreach (var jobScode in userORGType) // { // userModel.ORGType += jobScode; // userModel.ORGType += ","; // } // userModel.ORGType = userModel.ORGType.TrimEnd(','); // } // } // return userModel; // } //} /// <summary> /// 作者:Kylin /// 时间:2015.08.05 /// 描述:获取用户身份, 根据userId 二次认证 /// </summary> /// <param name="phone"></param> /// <param name="userId"></param> /// <returns></returns> public static UserInfoByPhoneModel GetUserInfoByPhone(string phone, int? userId) { var userModel = new UserInfoByPhoneModel() { UserId = userId ?? 0, MobilePhone = phone }; if (string.IsNullOrEmpty(phone) && !userId.HasValue) return userModel; using (var edb = new EmeEntities()) { userModel = edb.GetUserTypeInfoByMobile(phone, userId).Select(u => new UserInfoByPhoneModel() { MobilePhone = u.Mobile, BranchId = u.BranchId.Value, UserType = u.UserType, UserTypeId = u.UserTypeId.Value, UserId = u.UserId.Value, CName = u.UserCName, EName = u.UserEName }).FirstOrDefault(); if (null == userModel) { return new UserInfoByPhoneModel() { UserId = userId ?? 0, MobilePhone = phone }; } return userModel; } #region 注释 代码实现 //var userModel = new UserInfoByPhoneModel() { MobilePhone = phone }; //if (string.IsNullOrEmpty(phone) && !userId.HasValue) // return userModel; //using (var edb = new EmeEntities()) //{ // var userList = (from u in edb.UserInfo // join us in edb.User on u.UserId equals us.Id // join ub in edb.UserBranch on u.UserId equals ub.UserId // where ub.IsMain // && u.Status == ConvertEnum.StatusTypeForActive // && ub.Status == ConvertEnum.StatusTypeForActive // && us.Status == ConvertEnum.StatusTypeForActive // select new UserInfoByPhoneModel() // { // MobilePhone = u.Mobile, // BranchId = ub.BranchId, // UserTypeId = us.UserType, // UserId = u.UserId, // CName = u.CName, // EName = u.EName, // }); // if (!userList.Any()) // { // return new UserInfoByPhoneModel(); // } // var user = new UserInfoByPhoneModel(); // if (userId.HasValue && userId.Value > 0) // { // user = userList.FirstOrDefault(p => p.UserId == userId); // } // else // { // user = userList.FirstOrDefault(p => p.MobilePhone == phone); // } // // 信息 // if (user != null) // { // var branch = edb.Branch.FirstOrDefault( // b => b.Id == user.BranchId && b.Status == ConvertEnum.StatusTypeForActive); // if (branch != null) // { // userModel.UserId = user.UserId; // userModel.CName = user.CName; // userModel.EName = user.EName; // userModel.BranchId = user.BranchId; // userModel.UserTypeId = user.UserTypeId; // if (user.UserTypeId == ConvertEnum.UserTypeForStudent && edb.Student.Any(p => p.UserId == user.UserId && p.Status == ConvertEnum.StatusTypeForActive)) // { // userModel.UserType = BaseEnum.EmeEnum<UserType>.GetEnameByValue(user.UserTypeId); // return userModel; // } // if (edb.Teacher.Any(p => p.UserId == user.UserId && p.Status == ConvertEnum.StatusTypeForActive)) // { // var teacherUser = edb.Teacher.FirstOrDefault(p => p.UserId == user.UserId && p.Status == ConvertEnum.StatusTypeForActive); // if (null != teacherUser) // { // userModel.UserType = BaseEnum.EmeEnum<TeacherType>.GetScodeByValue(teacherUser.TeacherType); // } // return userModel; // } // userModel.UserType = BaseEnum.EmeEnum<TeacherType>.GetScodeByValue(ConvertEnum.UserTypeForEmployee); // return userModel; // } // } // return userModel; //} #endregion }
/// <summary> /// 作者:Kylin /// 时间:2015.03.11 /// 描述:根据Phone 获取学员信息 /// </summary> /// <param name="phone"></param> /// <returns></returns> public static UserInfoByPhoneModel GetUserInfoByPhone(string phone) { var userModel = new UserInfoByPhoneModel() { MobilePhone = phone, UserId = 0 }; if (string.IsNullOrEmpty(phone)) return userModel; using (var edb = new EmeEntities()) { userModel = edb.GetUserTypeInfoByMobile(phone, null).Select(u => new UserInfoByPhoneModel() { BranchId = u.BranchId.Value, UserType = u.UserType, UserTypeId = u.UserTypeId.Value, UserId = u.UserId.Value, CName = u.UserCName, EName = u.UserEName, MobilePhone = u.Mobile, }).FirstOrDefault(); if (null == userModel) { return new UserInfoByPhoneModel() { MobilePhone = phone, UserId = 0 }; } return userModel; } }