using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.Entity; using Bowin.Common.Utility; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.DataLogic.Repositories; using System.Linq.Expressions; using EMIS.Entities; using EMIS.DataLogic.SystemDAL; using EMIS.ViewModel.SystemView; using EMIS.Utility; using EMIS.DataLogic.Common.AdministrativeOrgan; using EMIS.DataLogic.Common.TeacherManagement; using EMIS.ViewModel; using EMIS.Utility.SSO; using EMIS.CommonLogic.Students; using EMIS.ViewModel.Students; using EMIS.DataLogic.Common.Students; using EMIS.DataLogic.Common.Specialtyclass; using System.Text.RegularExpressions; namespace EMIS.CommonLogic.SystemServices { public class UserServices : BaseServices, IUserServices { public UserDAL UserDAL { get; set; } public ClassmajorDAL ClassmajorDAL { get; set; } public StaffDAL StaffDAL { get; set; } public RoleDAL RoleDAL { get; set; } public CampusDAL CampusDAL { get; set; } public CollegeDAL CollegeDAL { get; set; } public StudentsDAL StudentsDAL { get; set; } public EMIS.DataLogic.Repositories.HRService.UsersRepository CommUserRepository { get; set; } public Lazy ControlItemServices { get; set; } public bool Login(string loginID, string password) { var encryptPassword = password.ToUpper(); //Bowin.Common.Utility.StringEx.MD5(password); //岭南不用姓名登陆 //var userName = UserDAL.UserRepository.GetList(u => u.RecordStatus == (int)SYS_STATUS.USABLE && u.Name == loginID).ToList(); //if(userName.Count>1) //{ // throw new Exception("由于您的名字在系统中存在重名情况,请使用工号进行登录。"); //} var user = UserDAL.UserRepository.GetList(u => u.RecordStatus == (int)SYS_STATUS.USABLE && (u.LoginID == loginID) && u.Password == encryptPassword) .Include(x => x.CF_Student).FirstOrDefault(); if (user == null) return false; if (user.CF_Student != null) { ControlItemServices.Value.CheckLoginControlItems(user.UserID); } return true; } public Entities.Sys_User GetUserByLoginID(string loginID, bool isNeedEnable = true) { Expression> user = (p => p.LoginID == loginID.Trim()||p.Name==loginID); if (isNeedEnable) { //user = user.And(p => p.RecordStatus == 1); 加了个方法代替,因为日后很可能会重用 return UserDAL.GetSingleEnableUser(user); } else { return UserDAL.UserRepository.GetSingle(user, (x => x.CF_Staff.CF_College.CF_Campus.CF_University), (x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CF_College.CF_Campus.CF_University)); } } public List GetUserListByLoginID(IList loginIDList, bool isNeedEnable = true) { Expression> userExp = (x => loginIDList.Contains(x.LoginID)); if (isNeedEnable) { userExp = userExp.And(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); } return UserDAL.UserRepository.GetList(userExp).ToList(); } public Sys_User GetUserByUserID(Guid? userID, bool isNeedEnable = true) { Expression> user = (p => p.UserID == userID); if (isNeedEnable) { //user = user.And(p => p.RecordStatus == 1); 加了个方法代替,因为日后很可能会重用 return UserDAL.GetSingleEnableUser(user); } else { return UserDAL.UserRepository.GetSingle(user, (x => x.CF_Staff.CF_College.CF_Campus.CF_University), (x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CF_College.CF_Campus.CF_University)); } } public UserView GetUserViewByID(Guid userID) { Expression> userExp = p => p.UserID == userID; return UserDAL.GetUserView(userExp, (x => true)).FirstOrDefault(); } /// /// 教师用户列表(用于列表控键,分页) /// /// /// /// /// /// /// /// /// /// /// public Bowin.Common.Linq.Entity.IGridResultSet GetUserViewList(ViewModel.ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? departmentID, Guid? roleID, int? dataRangeID, int? stauts, int pageIndex, int pageSize) { Expression> exp = (x => true); Expression> roleExp = (x => true); if (campusID.HasValue) { exp = exp.And(x => x.CF_Staff.CF_College.CampusID == campusID.Value); } if (collegeID.HasValue) { exp = exp.And(x => x.CF_Staff.CollegeID == collegeID.Value); } if (departmentID.HasValue) { exp = exp.And(x => x.CF_Staff.DepartmentID == departmentID.Value); } //if (roleID.HasValue) //{ // exp = exp.And(x => x.Sys_Role.Any(w => w.RoleID == roleID)); // //roleExp = roleExp.And(x => x.RoleID == roleID.Value); //} //if (dataRangeID.HasValue) //{ // exp = exp.And(x => x.Sys_Role.Any(w => w.DefaultDataRange == dataRangeID.Value)); // //roleExp = roleExp.And(x => x.DefaultDataRange == dataRangeID.Value); //} if (stauts.HasValue) { exp = exp.And(x => x.RecordStatus == stauts); } IQueryable q = UserDAL.GetUserView(exp, roleExp); // if (roleID.HasValue) { q = q.Where(x => x.RoleID == roleID); } if (dataRangeID.HasValue) { q = q.Where(x => x.DataRange == dataRangeID); } if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute)) q = q.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); q = this.GetQueryByDataRangeByDepartment(q); return q.OrderBy(x => x.CollegeCode).ThenBy(x => x.LoginID).ToGridResultSet(pageIndex, pageSize); } /// /// 教师用户列表(用于列表控键,不分页) /// /// /// /// /// /// /// /// public IList GetUserViewList(ViewModel.ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? departmentID, Guid? roleID, int? dataRangeID) { Expression> exp = (x => true); Expression> roleExp = (x => true); if (campusID.HasValue) { exp = exp.And(x => x.CF_Staff.CF_Department.CF_College.CampusID == campusID.Value); } if (collegeID.HasValue) { exp = exp.And(x => x.CF_Staff.CF_Department.CollegeID == collegeID.Value); } if (departmentID.HasValue) { exp = exp.And(x => x.CF_Staff.DepartmentID == departmentID.Value); } if (roleID.HasValue) { roleExp = roleExp.And(x => x.RoleID == roleID.Value); } if (dataRangeID.HasValue) { roleExp = roleExp.And(x => x.DefaultDataRange == dataRangeID.Value); } IQueryable q = UserDAL.GetUserView(exp, roleExp); if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute)) q = q.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); return q.OrderBy(x => x.CollegeCode).ThenBy(x => x.LoginID).ToList(); } /// /// 学生用户列表(用于列表控键,分页) /// /// /// /// /// /// /// /// /// /// /// /// public Bowin.Common.Linq.Entity.IGridResultSet GetStudentUserViewList(ViewModel.ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? educationID, int? schoolYearID, int? standardID, int? learnFormID, Guid? classMajorID,string LearnSystem, int pageIndex, int pageSize) { Expression> exp = (x => true); Expression> roleExp = (x => true); if (campusID.HasValue) { exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CF_College.CampusID == campusID.Value); } if (collegeID.HasValue) { exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID.Value); } if (educationID.HasValue) { exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.EducationID == educationID.Value); } if (schoolYearID.HasValue) { exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.SchoolyearID == schoolYearID.Value); } if (standardID.HasValue) { exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID.Value); } if (learnFormID.HasValue) { exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearningformID == learnFormID.Value); } if (classMajorID.HasValue) { exp = exp.And(x => x.CF_Student.ClassmajorID == classMajorID); } if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1") { var LearnSystems = Convert.ToDecimal(LearnSystem); exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems); } IQueryable q = UserDAL.GetStudentUserView(exp, roleExp); if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute)) q = q.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); return this.GetQueryByDataRangeByCollege(q).OrderBy(x => x.Grade).ThenBy(x => x.ClassNo).ThenBy(x => x.LoginID).ToGridResultSet(pageIndex, pageSize); } /// /// 学生用户列表(用于列表控键,不分页) /// /// /// /// /// /// /// /// /// /// public IList GetStudentUserViewList(ViewModel.ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? educationID, int? schoolYearID, int? standardID, int? learnFormID, Guid? classMajorID, string LearnSystem) { Expression> exp = (x => true); Expression> roleExp = (x => true); if (campusID.HasValue) { exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CF_College.CampusID == campusID.Value); } if (collegeID.HasValue) { exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID.Value); } if (educationID.HasValue) { exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.EducationID == educationID.Value); } if (schoolYearID.HasValue) { exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.SchoolyearID == schoolYearID.Value); } if (standardID.HasValue) { exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID.Value); } if (learnFormID.HasValue) { exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearningformID == learnFormID.Value); } if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1") { var LearnSystems = Convert.ToDecimal(LearnSystem); exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems); } IQueryable q = UserDAL.GetStudentUserView(exp, roleExp); if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute)) q = q.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); return q.OrderBy(x => x.Grade).ThenBy(x => x.ClassNo).ThenBy(x => x.LoginID).ToList(); } /// /// 批量初始化密码 /// /// 主键ID /// public void BatchInitPassword(IList userID, bool isChange,string pwd) { if (userID.Count > 0) { if (isChange == false) { List list = UserDAL.UserRepository.Entities.Where(x => userID.Contains(x.UserID)).ToList(); List studentList = StudentsDAL.StudentRepository.Entities.Where(x => userID.Contains(x.UserID)).ToList(); List staffList = StaffDAL.staffRepository.Entities.Where(x => userID.Contains(x.UserID)).ToList(); List userList = new List(); if (studentList.Count > 0) { foreach (var user in list) { var student = studentList.Where(x => x.UserID == user.UserID).FirstOrDefault(); var passwordstr = "A" + student.IDNumber.Substring(student.IDNumber.Length - 6); user.Password = passwordstr.MD5(); SetModifyStatus(user); userList.Add(user); } } if (staffList.Count > 0) { foreach (var user in list) { var staff = staffList.Where(x => x.UserID == user.UserID).FirstOrDefault(); var passwordstr = "A" + staff.CertificatesNum.Substring(staff.CertificatesNum.Length - 6, staff.CertificatesNum.Length); user.Password = ("888888").MD5(); SetModifyStatus(user); userList.Add(user); } } UnitOfWork.BatchUpdate(userList); UnitOfWork.Commit(); } else { List list = UserDAL.UserRepository.Entities.Where(x => userID.Contains(x.UserID)).ToList(); List userList = new List(); foreach (var user in list) { user.Password = pwd.MD5(); SetModifyStatus(user); userList.Add(user); } UnitOfWork.BatchUpdate(userList); UnitOfWork.Commit(); } } } /// /// 启用 /// /// 主键ID /// public void Usable(IList userID) { if (userID.Count > 0) { UnitOfWork.Update( x => new Sys_User { RecordStatus = (int)SYS_STATUS.USABLE }, x => userID.Contains(x.UserID) ); List list = UserDAL.UserRepository.Entities.Where(x => userID.Contains(x.UserID)).ToList(); foreach (var user in list) { SetModifyStatus(user); UnitOfWork.Update(user); UnitOfWork.Commit(); } } } /// /// 禁用 /// /// 主键ID /// public void UnUsable(IList userID) { if (userID.Count > 0) { UnitOfWork.Update( x => new Sys_User { RecordStatus = (int)SYS_STATUS.UNUSABLE }, x => userID.Contains(x.UserID) ); List list = UserDAL.UserRepository.Entities.Where(x => userID.Contains(x.UserID)).ToList(); foreach (var user in list) { SetModifyStatus(user); UnitOfWork.Update(user); UnitOfWork.Commit(); } } } /// /// 保存用户角色 /// /// /// public void SaveUserRoles(Guid userID, IList roleID) { var user = this.UserDAL.UserRepository.GetSingle(x => x.UserID == userID, (x => x.Sys_Role)); var roleList = this.RoleDAL.RoleRepository.GetList(x => roleID.Contains(x.RoleID)).ToList(); user.Sys_Role = new HashSet(); roleList.ForEach(x => user.Sys_Role.Add(x)); this.UnitOfWork.Commit(); } public IList GetUserInchargeCampus(Guid userID) { var campusList = this.StaffDAL.GetUserInChargeCampus(x => x.UserID == userID).ToList(); return campusList; } public IList GetUserInchargeCollege(Guid userID) { var collegeList = this.StaffDAL.GetUserInChargeCollege(x => x.UserID == userID).ToList(); return collegeList; } public IList GetUserInchargeDepartment(Guid userID) { var departmentList = this.StaffDAL.GetUserInChargeDepartment(x => x.UserID == userID).ToList(); return departmentList; } public IList GetUserRoles(Guid userID) { var user = this.UserDAL.UserRepository.GetSingle(x => x.UserID == userID, (x => x.Sys_Role)); var roleList = user.Sys_Role.ToList(); return roleList; } public Sys_Role GetMaxPrivilegeRoleByUserID(Guid userID) { var role = RoleDAL.RoleRepository.GetList(x => x.Sys_User.Any(w => w.UserID == userID)) .OrderByDescending(x => x.Sys_FunctionCode.Count()) .FirstOrDefault(); return role; } /// /// 保存用户所属校区 /// /// /// public void SaveUserCampus(Guid userID, IList campusID) { var user = this.UserDAL.UserRepository.GetSingle(x => x.UserID == userID, (x => x.CF_Staff.CF_StaffManageCampus)); if (user.CF_Staff == null) throw new Exception("该用户并非教职工用户,请补全该用户的教职工信息再进行操作,或选择其他用户进行操作。"); //var campusList = this.CampusDAL.campusRepository.GetList(x => campusID.Contains(x.CampusID)).ToList(); user.CF_Staff.CF_StaffManageCampus.ToList().ForEach(x => this.UnitOfWork.Remove(x)); campusID.ForEach(x => { CF_StaffManageCampus staffManageCampus = new CF_StaffManageCampus(); staffManageCampus.StaffManageCampusID = Guid.NewGuid(); staffManageCampus.UserID = userID; staffManageCampus.CampusID = x; this.SetNewStatus(staffManageCampus); this.UnitOfWork.Add(staffManageCampus); }); this.UnitOfWork.Commit(); } /// /// 保存用户所属学院 /// /// /// public void SaveUserCollege(Guid userID, IList collegeID) { var user = this.UserDAL.UserRepository.GetSingle(x => x.UserID == userID, (x => x.CF_Staff.CF_StaffManageCollege)); if (user.CF_Staff == null) throw new Exception("该用户并非教职工用户,请补全该用户的教职工信息再进行操作,或选择其他用户进行操作。"); user.CF_Staff.CF_StaffManageCollege.ToList().ForEach(x => this.UnitOfWork.Remove(x)); collegeID.ForEach(x => { CF_StaffManageCollege staffManageCollege = new CF_StaffManageCollege(); staffManageCollege.StaffManageCollegeID = Guid.NewGuid(); staffManageCollege.UserID = userID; staffManageCollege.CollegeID = x; this.SetNewStatus(staffManageCollege); this.UnitOfWork.Add(staffManageCollege); }); this.UnitOfWork.Commit(); } /// /// 保存用户所属教研室 /// /// /// public void SaveUserDepartment(Guid userID, IList departmentID) { var user = this.UserDAL.UserRepository.GetSingle(x => x.UserID == userID, (x => x.CF_Staff.CF_StaffManageDepartment)); if (user.CF_Staff == null) throw new Exception("该用户并非教职工用户,请补全该用户的教职工信息再进行操作,或选择其他用户进行操作。"); user.CF_Staff.CF_StaffManageDepartment.ToList().ForEach(x => this.UnitOfWork.Remove(x)); departmentID.ForEach(x => { CF_StaffManageDepartment staffManageDepartment = new CF_StaffManageDepartment(); staffManageDepartment.StaffManageDepartmentID = Guid.NewGuid(); staffManageDepartment.UserID = userID; staffManageDepartment.DepartmentID = x; this.SetNewStatus(staffManageDepartment); this.UnitOfWork.Add(staffManageDepartment); }); this.UnitOfWork.Commit(); } public IList GetUserRolesView(Guid userID) { return RoleDAL.GetRoleView(x => x.Sys_User.Any(w => w.UserID == userID)).OrderBy(x => x.TypeID).ThenBy(x => x.OrderNo).ToList(); } public string GetUserEmail(Guid userID) { var user = UserDAL.UserRepository.GetSingle(x => x.UserID == userID, (x => x.CF_Staff.CF_StaffProfile), (x => x.CF_Student.CF_StudentContact)); if (user == null) throw new Exception("指定的用户信息不存在。"); if (user.CF_Student != null && user.CF_Student.CF_StudentContact != null) { return user.CF_Student.CF_StudentContact.Email; } else if (user.CF_Staff != null && user.CF_Staff.CF_StaffProfile != null) { return user.CF_Staff.CF_StaffProfile.Email; } else { throw new Exception("用户并没有注册电子邮箱信息。"); } } public void ChangePassword(ChangePasswordView password, Guid userID) { var user = this.UserDAL.UserRepository.GetSingle(x => x.UserID == userID, (x => x.Sys_MailVerifyCode)); user.Password = password.Password.MD5(); user.Sys_MailVerifyCode = null; UnitOfWork.Commit(); } public Sys_User GetUserByID(Guid userID) { return this.UserDAL.UserRepository.Entities.Where(x => x.UserID == userID).FirstOrDefault(); } public void SynHRServices() { var exceptUser = new string[] { "admin" }; var hrUsers = CommUserRepository.GetList(x => !exceptUser.Contains(x.userid)).ToList(); var staffs = StaffDAL.staffRepository.GetList(x => !exceptUser.Contains(x.Sys_User.LoginID)) .Include(x => x.Sys_User).Include(x => x.CF_StaffProfile).ToList(); hrUsers.ForEach(x => x.status = "D"); foreach (var staff in staffs) { var hrUser = hrUsers.FirstOrDefault(x => x.userid == staff.Sys_User.LoginID); if (hrUser == null) { hrUser = new Entities.HRServices.Comm_Users(); hrUser.userid = staff.Sys_User.LoginID; hrUser.loginid = staff.Sys_User.LoginID; hrUser.createdt = DateTime.Now; this.HRUnitOfWork.Add(hrUser); } hrUser.username = staff.Sys_User.Name; if (staff.DepartmentID.HasValue) { hrUser.dpid = staff.DepartmentID.ToString(); } else { hrUser.dpid = staff.CollegeID.ToString(); } hrUser.telephone = staff.CF_StaffProfile.Telephone; hrUser.mobile = staff.CF_StaffProfile.Mobile; hrUser.email = staff.CF_StaffProfile.Email; hrUser.cardid = staff.Sys_User.LoginID; hrUser.employeeclassid = ""; hrUser.jobtypeid = "教师"; hrUser.birthday = staff.BirthDate; switch (staff.Sex) { case (int)CF_Sex.Male: hrUser.sex = "1"; break; case (int)CF_Sex.Female: hrUser.sex = "2"; break; default: hrUser.sex = "0"; break; } hrUser.orderNo = "1"; hrUser.userrole = ""; hrUser.userligion = ""; hrUser.password = staff.Sys_User.Password; hrUser.status = "A"; hrUser.updatedt = DateTime.Now; hrUser.istmpuser = false; } this.HRUnitOfWork.Commit(); } public virtual string SSOLogin() { return SSO.SSOLogin(); } public Guid? StudentRegist(RegistView registView) { string reg = @"(^\d{15}$)|(^\d{18}$)|(^\d{17}\d|X|x)$"; if (registView.CertificatesType == (int)CF_CertificatesType.IdCrad && !Regex.IsMatch(registView.LoginID, reg, RegexOptions.IgnoreCase)) { throw new Exception("证件号码格式不正确,请检查并修改正确后重试。"); } var dupUser = UserDAL.UserRepository.GetSingle(x => x.LoginID == registView.LoginID && x.UserID != registView.UserID); if (dupUser != null) { throw new Exception("该证件号码已经注册,请不要重复注册。"); } var userID = this.SaveStudentByRegistView(registView); return userID; } private Guid? SaveStudentByRegistView(RegistView registView) { var classmajor = this.ClassmajorDAL.GetSocialClassmajor(x => x.SchoolAreaID == registView.SchoolAreaID).FirstOrDefault(); CF_Student student = StudentsDAL.StudentRepository.GetSingle(x => x.UserID == registView.UserID, (x => x.CF_StudentAccount), (x => x.CF_StudentProfile), (x => x.CF_StudentContact), (x => x.CF_Recruitstudents), (x => x.Sys_User.Sys_Role), (x => x.Sys_User.Sys_Announcement), (x => x.Sys_User.Sys_MailVerifyCode), (x => x.Sys_User.EX_ExaminationRegistrationConfirm)); CF_StudentAccount account; CF_StudentProfile profile; CF_StudentContact contact; CF_Recruitstudents recruits; Sys_User user; if (student != null) { account = student.CF_StudentAccount; profile = student.CF_StudentProfile; contact = student.CF_StudentContact; recruits = student.CF_Recruitstudents; user = student.Sys_User; } else { student = new CF_Student(); account = new CF_StudentAccount(); profile = new CF_StudentProfile(); contact = new CF_StudentContact(); recruits = new CF_Recruitstudents(); user = new Sys_User(); Sys_Role role = RoleDAL.RoleRepository.GetSingle(x => x.CF_StudentRole != null && x.CF_StudentRole.StudentType != null, (x => x.CF_StudentRole)); student.UserID = Guid.NewGuid(); student.ClassmajorID = classmajor.ClassmajorID; student.StudentCardNo = registView.LoginID; student.StudentType = role.CF_StudentRole.StudentType; student.RecordStatus = (int)SYS_STATUS.USABLE; student.CreateTime = DateTime.Now; student.CreateUserID = student.UserID; //提供返回值 registView.UserID = student.UserID; account.UserID = student.UserID; account.RecordStatus = (int)SYS_STATUS.USABLE; account.CreateTime = DateTime.Now; account.CreateUserID = student.UserID; profile.UserID = student.UserID; profile.RecordStatus = (int)SYS_STATUS.USABLE; profile.CreateTime = DateTime.Now; profile.CreateUserID = student.UserID; contact.UserID = student.UserID; contact.WorkUnit = registView.WorkUnit; contact.RecordStatus = (int)SYS_STATUS.USABLE; contact.CreateTime = DateTime.Now; contact.CreateUserID = student.UserID; recruits.UserID = student.UserID; recruits.RecordStatus = (int)SYS_STATUS.USABLE; recruits.CreateTime = DateTime.Now; recruits.CreateUserID = student.UserID; user.UserID = student.UserID; user.LoginID = registView.LoginID; user.Password = registView.PCode.MD5(); user.RecordStatus = (int)SYS_STATUS.USABLE; user.CreateTime = DateTime.Now; user.CreateUserID = student.UserID; user.Sys_Role.Add(role); UnitOfWork.Add(user); UnitOfWork.Add(student); UnitOfWork.Add(account); UnitOfWork.Add(profile); UnitOfWork.Add(contact); UnitOfWork.Add(recruits); } student.CertificatesType = registView.CertificatesType; student.IDNumber = registView.LoginID; if (!string.IsNullOrEmpty(registView.PhotoUrl)) { student.PhotoUrl = registView.PhotoUrl; } student.Sex = registView.Sex; student.ModifyTime = DateTime.Now; student.ModifyUserID = student.UserID; account.ModifyTime = DateTime.Now; account.ModifyUserID = student.UserID; profile.BirthDate = registView.BirthDate; profile.ModifyTime = DateTime.Now; profile.ModifyUserID = student.UserID; contact.Mobile = registView.Mobile; contact.Email = registView.Email; contact.ModifyTime = DateTime.Now; contact.ModifyUserID = student.UserID; recruits.ModifyTime = DateTime.Now; recruits.ModifyUserID = student.UserID; user.Name = registView.UserName; user.ModifyTime = DateTime.Now; user.ModifyUserID = student.UserID; UnitOfWork.Commit(); return student.UserID; } public bool LoginHistory(string LoginID, bool isSuccess) { var today = DateTime.Now.Day; int? failCount = 0; bool status = true; Sys_LoginHistory todayLoginHistorie = new Sys_LoginHistory(); Sys_LoginHistory addloginHistories = new Sys_LoginHistory(); //无论什么情况登陆,先删除当前登陆账号非当天的登陆历史记录 List oldLoginHistories = UserDAL.LoginHistoryRepository.Entities.Where(x => x.LoginID == LoginID && x.LoginFailTime.Value.Day != today).ToList(); UnitOfWork.Delete(oldLoginHistories); todayLoginHistorie = UserDAL.LoginHistoryRepository.Entities.Where(x => x.LoginID == LoginID && x.LoginFailTime.Value.Day == today).FirstOrDefault(); if (todayLoginHistorie == null) { if (!isSuccess)//当天第一次登陆失败 { addloginHistories.LoginHistoryID = Guid.NewGuid(); addloginHistories.LoginID = LoginID; addloginHistories.LoginFailTime = DateTime.Now; addloginHistories.Count = failCount + 1; UnitOfWork.Add(addloginHistories); } status = true; } else if (todayLoginHistorie.Count < 5) { failCount = todayLoginHistorie.Count; UnitOfWork.Delete(x => x.LoginHistoryID == todayLoginHistorie.LoginHistoryID); if (!isSuccess)//当天登陆失败次数大于1,小于5,且本次登陆失败 { addloginHistories.LoginHistoryID = Guid.NewGuid(); addloginHistories.LoginID = LoginID; addloginHistories.LoginFailTime = DateTime.Now; addloginHistories.Count = failCount + 1; UnitOfWork.Add(addloginHistories); } status = true; } else if (todayLoginHistorie.Count >= 5) { status = false; } UnitOfWork.Commit(); return status; } } }