/// <summary>
        /// 学生申请
        /// </summary>
        /// <param name="studentId"></param>
        /// <param name="teacherPhone"></param>
        /// <returns></returns>
        public bool StudentApply(int studentId, string teacherPhone, int oper = 0)
        {
            var result        = false;
            var schoolTeacher = SchoolTeacherBll.GetSchoolTeacherByPhone(teacherPhone);

            if (schoolTeacher != null)
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    try
                    {
                        var apply = GetApplyByStudentId(studentId);
                        if (apply == null || apply.Yay_Status != (int)ApplyStatusEnum.意)
                        {
                            CloseApplyStatus(studentId, oper);
                            Yw_StudentApplySchool model = new Yw_StudentApplySchool();
                            model.Yay_OperateTime = DateTime.Now;
                            model.Yay_Operator    = studentId;
                            model.Yay_SchoolId    = schoolTeacher.Yoh_SchoolId;
                            model.Yay_Status      = (int)ApplyStatusEnum.申请;
                            model.Yay_StudentId   = studentId;
                            model.Yay_TeacherId   = schoolTeacher.Yoh_Id;
                            model.Yay_ApplyTime   = DateTime.Now;
                            result = InsertApply(model) > 0;
                            if (result)
                            {
                                scope.Complete();
                            }
                            else
                            {
                                RollbackTran();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        RollbackTran();
                        throw ex;
                    }
                }
            }
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// 保存学校
        /// </summary>
        /// <param name="school"></param>
        /// <param name="schoolTeacher"></param>
        /// <returns></returns>
        public bool SaveSchool(Bas_School school, Yw_SchoolTeacher schoolTeacher)
        {
            bool result = false;

            #region 参数逻辑校验
            bool checkParam = true;
            if (school.Bsl_Id == 0 && schoolTeacher.Yoh_Id != 0)//学校不存在 校长已经存在
            {
                checkParam = false;
            }
            if (school.Bsl_Id != 0 && schoolTeacher.Yoh_Id == 0)//学校存在 校长不存在
            {
                checkParam = false;
            }
            int count = SchoolTeacherBll.GetSchoolTeacherCountByPhone(schoolTeacher.Yoh_Phone);
            if (schoolTeacher.Yoh_Id == 0 && count > 0)//校长不存在,登录手机已经存在
            {
                checkParam = false;
            }
            if (!checkParam)
            {
                //throw new AbhsException(ErrorCodeEnum.ParameterInvalid, AbhsErrorMsg.ConstParameterInvalid);
                return(false);
            }
            #endregion
            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    if (school.Bsl_Id == 0)
                    {
                        int schoolId        = SchoolRepository.Insert(school);
                        int schoolTeacherId = 0;
                        if (schoolId > 0)
                        {
                            schoolTeacher.Yoh_SchoolId = schoolId;
                            schoolTeacherId            = SchoolTeacherBll.InsertEntity(schoolTeacher);
                            if (schoolTeacherId > 0)
                            {
                                result = SchoolRepository.UpdateMasterId(schoolId, schoolTeacherId);
                            }
                        }
                    }
                    else
                    {
                        #region teacher
                        bool updateTeacher   = true;
                        bool updateSchool    = true;
                        var  oldTeacher      = SchoolTeacherBll.GetEntity(schoolTeacher.Yoh_Id);
                        int  schoolTeacherId = schoolTeacher.Yoh_Id;
                        #region 更新校长
                        if (oldTeacher.Yoh_Phone != schoolTeacher.Yoh_Phone)
                        {
                            if (SchoolTeacherBll.GetSchoolTeacherCountByPhone(schoolTeacher.Yoh_Phone) == 0 && schoolTeacher.Yoh_Password.HasValue())
                            {
                                SchoolTeacherBll.UpdateStatus(schoolTeacher.Yoh_Id, (int)StatusEnum.除, school.Bsl_Editor);
                                schoolTeacher.Yoh_Id         = 0;
                                schoolTeacher.Yoh_SchoolId   = school.Bsl_Id;
                                schoolTeacher.Yoh_CreateTime = DateTime.Now;
                                schoolTeacher.Yoh_UpdateTime = DateTime.Now;
                                schoolTeacherId = SchoolTeacherBll.InsertEntity(schoolTeacher);
                                updateTeacher   = schoolTeacherId > 0;
                            }
                            else
                            {
                                updateTeacher = false;
                            }
                        }
                        #endregion
                        #region 更新密码
                        else
                        {
                            if (schoolTeacher.Yoh_Password.HasValue())
                            {
                                updateTeacher = SchoolTeacherBll.UpdatePwd(schoolTeacher.Yoh_Id, schoolTeacher.Yoh_Password, school.Bsl_Editor);
                            }
                        }
                        #endregion
                        #endregion
                        #region 更新学校
                        school.Bsl_SchoolMasterId = schoolTeacherId;
                        updateSchool = SchoolRepository.Update(school);
                        #endregion
                        result = updateTeacher && updateSchool;
                    }
                    if (result)
                    {
                        scope.Complete();
                    }
                    else
                    {
                        RollbackTran();
                    }
                }
                catch (Exception ex)
                {
                    RollbackTran();
                    throw ex;
                }
            }
            return(result);
        }