예제 #1
0
        /// <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;
        }
예제 #2
0
        /// <summary>
        /// 作者:Raymond
        /// 日期:2014-5-12
        /// 描述:修改用户
        /// ------------------------
        /// 作者:Ark
        /// 日期:2014-8-18
        /// 描述:Crm同步到Eme,不同步SA
        /// </summary>
        /// <param name="crmUser"></param>
        /// <param name="noCrossCenterList"></param>
        /// <param name="specialAreaList"></param>
        /// <returns></returns>
        public ResultModel EditUser(UserModel crmUser, List<int> noCrossCenterList, List<int> specialAreaList)
        {
            var list = new List<string>();
            list.Add(crmUser.UserName);

            var result = new ResultModel()
            {
                msg = APIModel.M_PARAMS_ERR,
                code = APIModel.C_PARAMS_ERR,
                count = 0,
                results = list,
            };

            var sex = Common.DataConvert.ConvertSex(crmUser.Sex);

            var resultTip = UserBLL.UpdateUserForCrm(crmUser, sex, APIModel.M_PARAMS_ERR, noCrossCenterList, specialAreaList);

            if (resultTip.Status != 100)
            {
                result.msg = resultTip.Msg;
            }
            else
            {
                result.msg = APIModel.M_SUCCESS;
                result.code = APIModel.C_SUCCESS;
                result.count = 1;
            }

            return result;
        }
예제 #3
0
파일: UserBLL.cs 프로젝트: kylin589/EmePro
        /// <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;
        }