/// <summary> /// 作者:Vincen /// 时间:2013.12.11 /// 描述:设置(用户信息)缓存 /// </summary> /// <param name="userInfo"></param> public static void SetUserInfoCache(UserInfo userInfo) { if (null == userInfo) return; if (!Icache.IsSet(string.Format("{0}{1}", KuserInfoId, userInfo.Id))) { Icache.Set(string.Format("{0}{1}", KuserInfoId, userInfo.Id), userInfo, 180 * 24 * 60); Icache.Set(string.Format("{0}{1}", KuserId, userInfo.UserId), userInfo, 180 * 24 * 60); } }
public JsonResult CreateTeacher(FormCollection fc) { var branchId = fc["CreateUserBranchId"]; var userType = fc["CreateUserType"]; var userName = fc["CreateUserName"]; var cName = fc["CreateUserInfoCName"]; var eName = fc["CreateUserInfoEName"]; var mobile = fc["CreateUserInfoMobile"]; var email = fc["CreateUserInfoEmail"]; var sex = fc["CreateUserInfoSex"]; var teacherType = fc["CreateTeacherType"]; var remark = fc["CreateUserInfoRemark"]; var activeStatus = Utility.CommonHelper.To<int>(Eme.Enum.StatusType.Active); var user = new Eme.Model.Eme.User() { UserName = userName, Password = WebCommon.Global.InitPasswordNew, UserType = Utility.CommonHelper.To<int>(userType), Status = activeStatus, CreateBy = LoginUserManager.CurrLoginUser.UserId, CreateTime = DateTime.Now }; var userInfo = new UserInfo() { CName = cName, EName = eName, IconUrl = null, Sex = Utility.CommonHelper.To<int>(sex), Email = email, Birthday = null, Mobile = mobile, EducationType = null, JobStatusType = Utility.CommonHelper.To<int>(Eme.Enum.JobStatusType.AtWork), Status = activeStatus, CreateBy = LoginUserManager.CurrLoginUser.UserId, CreateTime = DateTime.Now, Remark = remark }; var userBranch = new UserBranch() { BranchId = Utility.CommonHelper.To<int>(branchId), IsMain = true, OrderNum = 0, Status = activeStatus, CreateBy = LoginUserManager.CurrLoginUser.UserId, CreateTime = DateTime.Now }; var teacher = new Model.Eme.Teacher(); if (user.UserType == Utility.CommonHelper.To<int>(Eme.Enum.UserType.Teacher)) { teacher = new Eme.Model.Eme.Teacher() { IsFullTime = false, TeacherType = Utility.CommonHelper.To<int>(teacherType), Status = activeStatus, CreateBy = LoginUserManager.CurrLoginUser.UserId, CreateTime = DateTime.Now }; } var result = UserBLL.CreateUser(user, userInfo, userBranch, teacher, LoginUserManager.CurrLoginUser.UserId); return Json(new { status = result }, JsonRequestBehavior.AllowGet); }
/// <summary> /// 作者:Raymond /// 日期:2014-5-10 /// 描述:新增用户 /// </summary> /// <param name="crmUser"></param> /// <param name="noCrossCenterList"></param> /// <param name="specialAreaList"></param> /// <returns></returns> public ResultModel AddUser(UserModel crmUser, List<int> noCrossCenterList, List<int> specialAreaList) { // Crm用户名 var userName = crmUser.UserName; // 用户类型学员 var userType = CommonHelper.To<int>(UserType.Student); var passWord = crmUser.PassWord; var activeStatus = CommonHelper.To<int>(StatusType.Active); var list = new List<string>(); list.Add(userName); var result = new ResultModel() { msg = APIModel.M_PARAMS_ERR, code = APIModel.C_PARAMS_ERR, count = 0, results = list, }; int passwordLength = 6; if (string.IsNullOrEmpty(crmUser.Mobile) || crmUser.Mobile.Length < passwordLength) { result.msg += string.Concat(": Mobile字段不能为null或者空字符串,并且长度必须大于", passwordLength); return result; } passWord = string.IsNullOrEmpty(crmUser.PassWord) ? Utility.SecurityHelper.GetMd5(crmUser.Mobile.Substring(crmUser.Mobile.Length - passwordLength, passwordLength)) : crmUser.PassWord; var branchId = Common.DataConvert.ConvertBranch(crmUser.BranchId); if (branchId == -1) { result.msg = APIModel.M_PARAMS_ERR + ":没有找到对应的中心,中心错误"; return result; } var emeUser = new User() { UserName = userName, UserType = userType, Password = passWord, IsOverwriteRights = false, Status = activeStatus, }; var emeUserInfo = new UserInfo() { CName = crmUser.Cname, EName = crmUser.Ename, Email = crmUser.Email, Mobile = crmUser.Mobile, Birthday = crmUser.Birthday, Sex = Common.DataConvert.ConvertSex(crmUser.Sex), Status = activeStatus, Address = crmUser.Address, ConditionType = Common.DataConvert.ConvertConditionType(crmUser.Condition), CreateTime = DateTime.Now, }; var emeUserBranch = new UserBranch() { BranchId = branchId, IsMain = true, OrderNum = 0, Status = activeStatus, }; var emeStudent = new Student() { StudentTypeId = 1, SA = Common.DataConvert.ConvertUserNameToUserId(crmUser.SA), CC = Common.DataConvert.ConvertUserNameToUserId(crmUser.CC), ContractStatus = ConvertEnum.ContractStatusTypeForExcute, Status = activeStatus, CreateTime = DateTime.Now, }; var loginUserId = -1; try { var flagUser = UserBLL.CreateUser(emeUser, emeUserInfo, emeUserBranch, emeStudent, loginUserId, noCrossCenterList, specialAreaList); if (flagUser) { result.msg = APIModel.M_SUCCESS; result.code = APIModel.C_SUCCESS; result.count = 1; //写入薏米同学 //CreateUserToEdusoho(emeUserInfo.Email, emeUser.Id, emeUserInfo.CName + "|" + emeUserInfo.EName, emeUser.UserName, emeUser.Password, emeUser.UserType, emeUserInfo.Mobile, emeUserInfo.Sex, emeUserInfo.Birthday, result); } } catch (Exception e) { result.msg = "内部错误:" + e.Message.ToString(); } return result; }
/// <summary> /// 作者:Vincen /// 时间:2013.12.11 /// 描述:更新(用户信息)缓存 /// </summary> /// <param name="userInfo"></param> public static void UpdateUserInfoCache(UserInfo userInfo) { Icache.Set(string.Format("{0}{1}", KuserInfoId, userInfo.Id), userInfo, 180 * 24 * 60); Icache.Set(string.Format("{0}{1}", KuserId, userInfo.UserId), userInfo, 180 * 24 * 60); }
/// <summary> /// 作者:Vincen /// 时间:2013.12.12 /// 描述:更新用户信息 /// </summary> /// <param name="userInfo"></param> /// <returns></returns> public static bool UpdateUserInfo(UserInfo userInfo) { using (var edb = new EmeEntities()) { var model = edb.UserInfo.FirstOrDefault(p => p.Id == userInfo.Id); if (null == model) return false; model.EName = userInfo.EName; model.CName = userInfo.CName; model.Sex = userInfo.Sex; model.Email = userInfo.Email; model.Birthday = userInfo.Birthday; model.Mobile = userInfo.Mobile; model.Remark = userInfo.Remark; //model.JobStatusType = userInfo.JobStatusType; model.EducationType = userInfo.EducationType; model.ConditionType = userInfo.ConditionType; if (userInfo.Status == 0) { model.Status = ConvertEnum.StatusTypeForActive; } else { model.Status = userInfo.Status; } if (userInfo.IconUrl != null) { model.IconUrl = userInfo.IconUrl; } model.UpdateBy = userInfo.UpdateBy; model.UpdateTime = userInfo.UpdateTime; model.Address = userInfo.Address; model.Lat = userInfo.Lat; model.Lng = userInfo.Lng; edb.Entry(model).State = EntityState.Modified; return edb.SaveChanges() > 0; } }
/// <summary> /// 作者:Beta /// 时间:2014.02.17 /// 描述:添加教师详细信息(中、英文名、性别....) /// </summary> /// <param name="model"></param> /// <returns></returns> public static UserInfo CreateUserInfo(UserInfo model) { using (var edb = new EmeEntities()) { edb.Entry(model).State = EntityState.Added; edb.SaveChanges(); return model; } }
/// <summary> /// 作者:Ark /// 时间:2014.08.30 /// 描述:更新Crm学员信息 /// </summary> /// <param name="crmUser"></param> /// <param name="sex"></param> /// <param name="paramError"></param> /// <param name="noCrossCenterList"></param> /// <param name="specialAreaList"></param> /// <returns></returns> public static ResultTiper UpdateUserForCrm(UserModel crmUser, int sex, string paramError, List<int> noCrossCenterList, List<int> specialAreaList) { var result = new ResultTiper { Status = 100 }; // 用户名 var userName = crmUser.UserName; // 用户类型学员 var userType = ConvertEnum.UserTypeForStudent; // 状态正常 var activeStatus = ConvertEnum.StatusTypeForActive; var updateBy = -122; using (var edb = new EmeEntities()) { try { var emeUser = edb.User.FirstOrDefault(u => u.UserName.Equals(userName, StringComparison.CurrentCultureIgnoreCase)); // 用户不存在 if (null == emeUser) { result.Status = 101; result.Msg = paramError + ":未找到改用户,更新失败"; return result; } var branchId = edb.Branch.Where(b => b.DataCenterId == crmUser.BranchId && b.Status == activeStatus).Select(b => b.Id).FirstOrDefault(); // 中心不存在 if (branchId < 1) { result.Status = 101; result.Msg = paramError + ":没有找到对应的中心,中心错误"; return result; } var userId = emeUser.Id; emeUser.Email = crmUser.Email; emeUser.Mobile = crmUser.Mobile; emeUser.UpdateBy = updateBy; emeUser.UpdateTime = DateTime.Now; emeUser.Status = activeStatus; emeUser.IsSync = false; edb.Entry(emeUser).State = EntityState.Modified; var emeUserInfo = edb.UserInfo.FirstOrDefault(u => u.UserId == userId); if (null != emeUserInfo) { emeUserInfo.CName = crmUser.Cname; //emeUserInfo.EName = crmUser.Ename; //Ark 2014-08-19 不同步英文名 //emeUserInfo.Mobile = crmUser.Mobile; //beta 2015.04.07 同步不修改学员手机号码 emeUserInfo.Email = crmUser.Email; emeUserInfo.Birthday = crmUser.Birthday; emeUserInfo.Sex = sex; emeUserInfo.Status = activeStatus; emeUserInfo.UpdateBy = updateBy; emeUserInfo.UpdateTime = DateTime.Now; emeUserInfo.Address = crmUser.Address; edb.Entry(emeUserInfo).State = EntityState.Modified; } else { emeUserInfo = new UserInfo() { UserId = emeUser.Id, CName = crmUser.Cname, EName = crmUser.Ename, Mobile = crmUser.Mobile, Sex = sex, Email = crmUser.Email, Birthday = crmUser.Birthday, Status = activeStatus, CreateBy = updateBy, CreateTime = DateTime.Now, Address = crmUser.Address }; edb.Entry(emeUserInfo).State = EntityState.Added; } var emeUserBranch = edb.UserBranch.FirstOrDefault(p => p.UserId == userId && p.Status == activeStatus && p.IsMain); if (null != emeUserBranch) { // 所属中心修改,修改对应的跨中心 if (emeUserBranch.BranchId != branchId) { #region 跨中心订课 2014-11-1 raymond 取消 //// 原所属中心在不允许跨中心订课中心中不存在 //if (!noCrossCenterList.Contains(emeUserBranch.BranchId)) //{ // // 取非所属中心 // var otherBranchList = edb.UserBranch.Where(b => b.UserId == userId && b.BranchId != emeUserBranch.BranchId).ToList(); // foreach (var other in otherBranchList) // { // other.Status = ConvertEnum.StatusTypeForDelete; // emeUserBranch.UpdateBy = updateBy; // emeUserBranch.UpdateTime = DateTime.Now; // edb.Entry(emeUserBranch).State = EntityState.Modified; // } //} //// 新所属中心在不允许跨中心订课中心中不存在 //if (!noCrossCenterList.Contains(branchId)) //{ // // 获取区域BranchId // var areaBranchId = edb.Branch.Where(b => b.Id == emeUserBranch.BranchId).Select(b => b.ParentId).FirstOrDefault(); // // 区域存在 // if (areaBranchId > 0) // { // List<int> branchIdList = null; // // 获取区域下的所有中心(特殊区域) // if (specialAreaList.Contains(areaBranchId.Value)) // branchIdList = edb.Branch.Where(b => b.Status == ConvertEnum.StatusTypeForActive && specialAreaList.Contains(b.ParentId.Value)).Select(b => b.Id).ToList(); // else // branchIdList = edb.Branch.Where(b => b.Status == ConvertEnum.StatusTypeForActive && b.ParentId.Value == areaBranchId).Select(b => b.Id).ToList(); // foreach (var bId in branchIdList) // { // // 循环添加非当前中心 // if (bId != branchId) // { // var ub = new UserBranch // { // UserId = userId, // BranchId = bId, // CreateBy = updateBy, // CreateTime = DateTime.Now // }; // edb.Entry(ub).State = EntityState.Added; // } // } // } //} #endregion } emeUserBranch.BranchId = branchId; emeUserBranch.UpdateBy = updateBy; emeUserBranch.UpdateTime = DateTime.Now; edb.Entry(emeUserBranch).State = EntityState.Modified; } var emeStudent = edb.Student.FirstOrDefault(p => p.UserId == userId); if (null != emeStudent) { if (!string.IsNullOrWhiteSpace(crmUser.CC)) { var ccUserId = edb.User.Where(c => c.UserName.Equals(crmUser.CC, StringComparison.CurrentCultureIgnoreCase)) .Select(u => u.Id) .FirstOrDefault(); if (ccUserId != 0) { emeStudent.CC = ccUserId; emeStudent.UpdateBy = updateBy; emeStudent.UpdateTime = DateTime.Now; edb.Entry(emeStudent).State = EntityState.Modified; } } } edb.SaveChanges(); AsyncUpdateAddressInfo(emeUserInfo); } catch (Exception e) { QueueManager.AddExceptionLog(new ExceptionLogs() { ExceptionType = CommonHelper.To<int>(ExceptionType.Message), Message = string.Format("UserBLL-UpdateUserForCrm:{0};{1};{2}", e.Message, e.InnerException, e.HelpLink), IsTreat = false, CreateBy = updateBy, CreateTime = DateTime.Now }); result.Status = 102; result.Msg = "内部错误:" + e.Message; } } return result; }
/// <summary> /// 作者:Raymond /// 日期:2014-5-12 /// 描述:创建User及Student /// </summary> /// <param name="user"></param> /// <param name="userInfo"></param> /// <param name="userBranch"></param> /// <param name="student"></param> /// <param name="loginUserId"></param> /// <param name="noCrossCenterList"></param> /// <param name="specialAreaList"></param> /// <returns></returns> public static bool CreateUser(User user, UserInfo userInfo, UserBranch userBranch, Student student, int loginUserId, List<int> noCrossCenterList, List<int> specialAreaList) { using (var tran = new TransactionScope()) { using (var edb = new EmeEntities()) { try { var isExists = edb.User.Any(p => p.UserName == user.UserName); if (isExists) return false; edb.Entry(user).State = EntityState.Added; edb.SaveChanges(); userInfo.UserId = user.Id; edb.Entry(userInfo).State = EntityState.Added; userBranch.UserId = user.Id; edb.Entry(userBranch).State = EntityState.Added; #region 跨中心订课 取消往userBranch写记录的方式 //// 所属中心在不允许跨中心订课中心中不存在 //if (!noCrossCenterList.Contains(userBranch.BranchId)) //{ // // 获取区域BranchId // var areaBranchId = edb.Branch.Where(b => b.Id == userBranch.BranchId).Select(b => b.ParentId).FirstOrDefault(); // // 区域存在 // if (areaBranchId > 0) // { // List<int> branchIdList = null; // // 获取区域下的所有中心(特殊区域) // if (specialAreaList.Contains(areaBranchId.Value)) // branchIdList = edb.Branch.Where(b => b.Status == ConvertEnum.StatusTypeForActive && specialAreaList.Contains(b.ParentId.Value)).Select(b => b.Id).ToList(); // else // branchIdList = edb.Branch.Where(b => b.Status == ConvertEnum.StatusTypeForActive && b.ParentId.Value == areaBranchId).Select(b => b.Id).ToList(); // foreach (var branchId in branchIdList) // { // // 循环添加非当前中心 // if (branchId != userBranch.BranchId) // { // var ub = new UserBranch { // UserId = user.Id, // BranchId = branchId, // CreateBy = user.CreateBy, // CreateTime = DateTime.Now // }; // edb.Entry(ub).State = EntityState.Added; // } // } // } //} #endregion if (user.UserType == CommonHelper.To<int>(UserType.Student)) { student.UserId = user.Id; edb.Entry(student).State = EntityState.Added; } var result = edb.SaveChanges() > 0; AsyncUpdateAddressInfo(userInfo); tran.Complete(); return result; } catch (Exception ex) { tran.Dispose(); Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs() { ExceptionType = CommonHelper.To<int>(ExceptionType.Message), Message = string.Format("UserBLL-CreateUser:{0};{1};{2}", ex.Message, ex.InnerException, ex.HelpLink), IsTreat = false, CreateBy = loginUserId, CreateTime = DateTime.Now }); return false; } } } }
/// <summary> /// 作者:Vincen /// 时间:2014.04.30 /// 描述:创建User /// --------------------- /// 描述:更新使用新的Context实列 /// </summary> /// <param name="user"></param> /// <param name="userInfo"></param> /// <param name="userBranch"></param> /// <param name="teacher"></param> /// <param name="loginUserId"></param> /// <returns></returns> public static bool CreateUser(User user, UserInfo userInfo, UserBranch userBranch, Teacher teacher, int loginUserId) { using (var tran = new TransactionScope()) { using (var edb = new EmeEntities()) { try { var isExists = edb.User.Any(p => p.UserName == user.UserName); if (isExists) return false; edb.Entry(user).State = EntityState.Added; edb.SaveChanges(); userInfo.UserId = user.Id; edb.Entry(userInfo).State = EntityState.Added; userBranch.UserId = user.Id; edb.Entry(userBranch).State = EntityState.Added; if (user.UserType == CommonHelper.To<int>(UserType.Teacher)) { teacher.UserId = user.Id; edb.Entry(teacher).State = EntityState.Added; } var result = edb.SaveChanges() > 0; tran.Complete(); return result; } catch (Exception ex) { tran.Dispose(); //Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs() //{ // ExceptionType = CommonHelper.To<int>(ExceptionType.Message), // Message = string.Format("UserBLL-CreateUser:{0};{1};{2}", ex.Message, ex.InnerException, ex.HelpLink), // IsTreat = false, // CreateBy = loginUserId, // CreateTime = DateTime.Now //}); return false; } } } }
public static ESBResult EditEmployee(EmployeeModel employee, string ltSCode, string ftSCode, string saSCode, int headBranchId, string jobScode) { var result = new ESBResult { Code = "000000", Message = "成功" }; var editUserId = -111; if (string.IsNullOrWhiteSpace(employee.UserName)) { result.Code = "EME0101"; result.Message = "同步失败,员工的[UserName]为NULL!"; return result; } using (var edb = new EmeEntities()) { using (var tran = new TransactionScope()) { try { // 查询员工的部门 var remark = employee.DeptId.ToString(); var branchId = headBranchId; // 默认总部 var centerOrHead = edb.Branch.FirstOrDefault(b => b.Remark == remark); if (null == centerOrHead) { result.Code = "EME0101"; result.Message = "请先同步此员工所在的部门!"; return result; //先新增部门 } #region 职务(岗位)同步 // 查询员工的岗位 var job = edb.Job.FirstOrDefault(j => j.BranchId == centerOrHead.Id && j.HrId == employee.JobId); if (null == job) { //先新增岗位 var jobModel = new JobModel { JobId = employee.JobId, DeptId = employee.DeptId, CName = employee.JobName, Status = ConvertEnum.StatusTypeForActive, EName = employee.JobName, NodeCode = jobScode }; job = EditJob(jobModel, jobScode, edb); if (job == null) { result.Code = "EME0101"; result.Message = "职务同步失败!"; return result; } } #endregion while (centerOrHead.BranchType != ConvertEnum.BranchTypeForSchool && centerOrHead.BranchType != ConvertEnum.BranchTypeForArea && centerOrHead.BranchType != ConvertEnum.BranchTypeForCompany) { if (null == centerOrHead) break; centerOrHead = edb.Branch.FirstOrDefault(b => b.Id == centerOrHead.ParentId); } if (null != centerOrHead) { if (centerOrHead.BranchType == ConvertEnum.BranchTypeForSchool) branchId = centerOrHead.Id; else if (centerOrHead.BranchType == ConvertEnum.BranchTypeForArea) branchId = centerOrHead.Id; } // 员工类型默认员工 var userType = ConvertEnum.UserTypeForEmployee; var status = ConvertEnum.StatusTypeForActive; var jobStatusType = ESBConvert.ToJobStatusType(employee.JobStatus); if (job.SCode == ltSCode || job.SCode == ftSCode) userType = ConvertEnum.UserTypeForTeacher; if (jobStatusType == ConvertEnum.JobStatusTypeForLeave) status = ConvertEnum.StatusTypeForInactive; #region 同步员工基本信息(User、UserInfo、UserBranch、UserJob) #region User // 是否新增 var isAddUser = false; //根据老用户名称是否存在 2014-11-4 raymond 修改 var userName = string.IsNullOrEmpty(employee.OldName) ? employee.UserName : employee.OldName; var user = edb.User.FirstOrDefault(u => u.UserName == userName); //var user = edb.User.FirstOrDefault(u => u.UserName == employee.OldName); if (null == user) { isAddUser = true; user = new User(); } user.UserType = userType; user.Status = status; user.Email = employee.Email; user.Mobile = employee.Mobile; user.Remark = "修改前" + employee.OldName; // 不存在新增,存在修改 if (isAddUser) { user.UserName = employee.UserName; user.Password = "******"; user.Remark = "EHR同步"; user.CreateBy = editUserId; user.CreateTime = employee.CreateTime; edb.User.Add(user); edb.SaveChanges(); } else { user.IsSync = false; user.UpdateBy = editUserId; user.UpdateTime = DateTime.Now; } #endregion #region UserInfo // 是否新增 var isAddUserInfo = false; var userInfo = edb.UserInfo.FirstOrDefault(u => u.UserId == user.Id); if (null == userInfo) { isAddUserInfo = true; userInfo = new UserInfo(); } userInfo.UserId = user.Id; userInfo.EName = employee.EName; userInfo.CName = employee.CName; userInfo.Sex = ESBConvert.ToSex(employee.Sex); userInfo.Email = employee.Email; userInfo.Mobile = employee.Mobile; userInfo.Birthday = employee.Birthday; userInfo.JobStatusType = jobStatusType; userInfo.Status = status; if (isAddUserInfo) { userInfo.Remark = "EHR同步"; userInfo.CreateBy = editUserId; userInfo.CreateTime = employee.CreateTime; edb.UserInfo.Add(userInfo); } else { userInfo.UpdateBy = editUserId; userInfo.UpdateTime = DateTime.Now; } #endregion #region UserBranch // 是否新增 var isAddUserBranch = false; var userBranch = edb.UserBranch.FirstOrDefault(b => b.UserId == user.Id/* && b.BranchId == branchId*/ && b.IsMain); if (null == userBranch) { isAddUserBranch = true; userBranch = new UserBranch(); } userBranch.UserId = user.Id; userBranch.BranchId = branchId; userBranch.Status = status; userBranch.IsMain = true; if (isAddUserBranch) { userBranch.Remark = "EHR同步"; userBranch.CreateBy = editUserId; userBranch.CreateTime = employee.CreateTime; edb.UserBranch.Add(userBranch); } else { userBranch.UpdateBy = editUserId; userBranch.UpdateTime = DateTime.Now; } #endregion #region UserJob // 是否新增 var isAddUserJob = false; var userJobList = edb.UserJob.Where(u => u.UserId == user.Id).ToList(); var activeCount = userJobList.Count(u => u.Status == ConvertEnum.StatusTypeForActive); var userJob = userJobList.FirstOrDefault(u => u.JobId == job.Id); // 如果userJob数量=1,直接修改此userJob if (activeCount == 1) { userJob = userJobList.FirstOrDefault(u => u.Status == ConvertEnum.StatusTypeForActive); } if (null == userJob) { isAddUserJob = true; userJob = new UserJob(); } userJob.JobId = job.Id; userJob.Status = status; if (isAddUserJob) { userJob.UserId = user.Id; userJob.Remark = "EHR同步"; userJob.CreateBy = editUserId; userJob.CreateTime = employee.CreateTime; edb.UserJob.Add(userJob); } else { userJob.UpdateBy = editUserId; userJob.UpdateTime = DateTime.Now; } #endregion edb.SaveChanges(); #endregion #region 同步老师(Teacher、TeachRange) // 教师和学习指导同步到Teacher、TeachRange if (job.SCode == ltSCode || job.SCode == ftSCode || job.SCode == saSCode) { var teacherType = ConvertEnum.TeacherTypeForSA; if (job.SCode == ltSCode) teacherType = ConvertEnum.TeacherTypeForLT; if (job.SCode == ftSCode) teacherType = ConvertEnum.TeacherTypeForFT; // 是否新增 var isAddTeacher = false; var teacher = edb.Teacher.FirstOrDefault(t => t.UserId == user.Id); if (null == teacher) { isAddTeacher = true; teacher = new Teacher(); } teacher.UserId = user.Id; teacher.TeacherType = teacherType; teacher.Status = status; teacher.IsFullTime = true; var flag = true; //默认添加 TeachRange if (isAddTeacher) { teacher.Remark = "EHR同步"; teacher.CreateBy = editUserId; teacher.CreateTime = DateTime.Now; edb.Teacher.Add(teacher); edb.SaveChanges(); } else { teacher.UpdateBy = editUserId; teacher.UpdateTime = DateTime.Now; flag = !edb.TeachRange.Any(t => t.TeacherId == teacher.Id); } if (flag) { // 最近的同级的范围 var newSameLvelTeacherId = (from t in edb.Teacher join r in edb.TeachRange on t.Id equals r.TeacherId where t.TeacherType == teacherType && t.Status == ConvertEnum.StatusTypeForActive orderby t.Id descending select t.Id).Take(1).FirstOrDefault(); if (newSameLvelTeacherId > 0) { var rangeList = edb.TeachRange.Where(t => t.TeacherId == newSameLvelTeacherId && t.Status == ConvertEnum.StatusTypeForActive).ToList(); foreach (var range in rangeList) { var teachRange = new TeachRange { TeacherId = teacher.Id, ProductLevelId = range.ProductLevelId, Status = status, CreateBy = editUserId, CreateTime = DateTime.Now }; edb.TeachRange.Add(teachRange); } } } edb.SaveChanges(); } #endregion tran.Complete(); } catch (Exception ex) { tran.Dispose(); // 异常日志消息队列 QueueManager.AddExceptionLog(new ExceptionLogs() { ExceptionType = CommonHelper.To<int>(ExceptionType.Function), Message = string.Format("UserBLL-EditEmployee:{0};{1};{2}", ex.Message, ex.InnerException.Message, ex.HelpLink), IsTreat = false, CreateBy = -1, CreateTime = DateTime.Now }); result.Code = "EME0102"; result.Message = "数据库操作异常,请联系管理员!Cause:" + ex.Message; } } } return result; }
public ActionResult UserInfo(UserInfo model) { var uinfo = UserBLL.GetUserInfoById(model.Id); uinfo.Sex = model.Sex; uinfo.Email = model.Email; uinfo.Birthday = model.Birthday; uinfo.Mobile = model.Mobile; uinfo.EducationType = model.EducationType; uinfo.UpdateBy = LoginUserManager.CurrLoginUser.UserId; uinfo.UpdateTime = DateTime.Now; var restult = UserBLL.UpdateUserInfo(uinfo); return Json(new { Status = restult }, JsonRequestBehavior.AllowGet); }