コード例 #1
0
ファイル: UserInfoController.cs プロジェクト: kylin589/EmePro
        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);
        }
コード例 #2
0
ファイル: EMEUserAPI.cs プロジェクト: kylin589/EmePro
        /// <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;
        }
コード例 #3
0
ファイル: UserBLL.cs プロジェクト: kylin589/EmePro
        /// <summary>
        /// 作者:Raymond
        /// 日期:2014-4-12
        /// 描述:更新userBranch对象
        /// </summary>
        /// <param name="userBranch"></param>
        /// <returns></returns>
        public static bool UpdateUserBranch(UserBranch userBranch)
        {
            using (var edb = new EmeEntities())
            {
                var model = edb.UserBranch.FirstOrDefault(p => p.Id == userBranch.Id);
                if (null == model)
                    return false;

                model.UserId = userBranch.UserId;
                model.BranchId = userBranch.BranchId;
                model.IsMain = userBranch.IsMain;
                model.OrderNum = userBranch.OrderNum;
                model.Status = userBranch.Status;
                model.UpdateBy = userBranch.UpdateBy;
                model.UpdateTime = DateTime.Now;
                model.Remark = userBranch.Remark;

                edb.Entry(model).State = EntityState.Modified;
                return edb.SaveChanges() > 0;
            }
        }
コード例 #4
0
ファイル: UserBLL.cs プロジェクト: kylin589/EmePro
        /// <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;
                    }
                }
            }
        }
コード例 #5
0
ファイル: UserBLL.cs プロジェクト: kylin589/EmePro
        /// <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;
                    }
                }
            }
        }
コード例 #6
0
ファイル: UserBLL.cs プロジェクト: kylin589/EmePro
        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;
        }