Esempio n. 1
0
 /// <summary>
 /// 作者:Beta
 /// 时间:2014.03.25
 /// 描述:更新学员信息
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static bool UpdateStudent(Student model)
 {
     Db.Entry(model).State = EntityState.Modified;
     return Db.SaveChanges() > 0;
 }
Esempio n. 2
0
        /// <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;
                    }
                }
            }
        }
Esempio n. 3
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;
        }
Esempio n. 4
0
        /// <summary>
        /// 作者:Beta
        /// 时间:2014.03.25
        /// 描述:更新学员信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool UpdateStudent(Student model)
        {
            using (var edb = new EmeEntities())
            {
                var stu = edb.Student.FirstOrDefault(p => p.Id == model.Id);
                if (null == stu)
                    return false;

                stu.UserId = model.UserId;
                stu.StudentTypeId = model.StudentTypeId;
                stu.SA = model.SA;
                stu.CC = model.CC;
                stu.IsRR = model.IsRR;
                stu.StudentTypeId = model.StudentTypeId;
                stu.Status = model.Status;
                stu.UpdateBy = model.UpdateBy;
                stu.UpdateTime = DateTime.Now;
                stu.Remark = model.Remark;
                edb.Entry(stu).State = EntityState.Modified;
                return edb.SaveChanges() > 0;
            }
        }