コード例 #1
0
        //删除用户一门课程
        public bool DeleteUserCourse(string openId, string LessonCode)
        {
            try
            {
                _dbContext.Database.BeginTransaction();
                //删除用户课程表
                UserSrv userSrv = new UserSrv(_dbContext);
                userSrv.DeleteUserCourse(openId, LessonCode);

                //更新课程报名数
                var cs = _dbContext.DbCourseSchedule.Where(a => a.LessonCode == LessonCode).FirstOrDefault();
                cs.ApplyNum--;
                if (cs.ApplyNum == 0)
                {
                    TecSrv tecSrv = new TecSrv(_dbContext);
                    //删除老师课程
                    tecSrv.DeleteTecCourse(LessonCode);
                }
                _dbContext.SaveChanges();
                _dbContext.Database.CommitTransaction();
            }
            catch (Exception ex)
            {
                _dbContext.Database.RollbackTransaction();
                throw ex;
            }
            return(true);
        }
コード例 #2
0
        /// <summary>
        /// 新建课时交易
        /// </summary>
        /// <param name="line"></param>
        //private void AddCourseTimeTransByLine(EOrderLine line)
        //{
        //    EUserCourseTimeTrans trans = new EUserCourseTimeTrans
        //    {
        //        CourseScheduleType = (CourseScheduleType)line.Ext1,
        //        TransQty = line.Qty,
        //        UserOpenId = line.OrderId,
        //        CoursePriceCode = line.ItemCode,
        //        TransDateTime = DateTime.Now,

        //    };
        //    _dbContext.DBUserCourseTimeTrans.Add(trans);
        //}

        #endregion

        #region 用户课程

        /// <summary>
        /// 用户选择课程
        /// </summary>
        /// <param name="courseList"></param>
        public void UserSelectNewCourses(string openId, List <EUserCourse> courseList, CourseScheduleType courseScheduleType, bool useRightNow = false, bool isAdmin = false)
        {
            try
            {
                BeginTrans();
                if (courseList.Count > 0)
                {
                    UserSrv userSrv = new UserSrv(_dbContext);
                    TecSrv  tecSrv  = new TecSrv(_dbContext);
                    //不是后台选择,且选择已满
                    if (!isAdmin && !userSrv.CheckUserCanSelectCourse(openId, courseScheduleType))
                    {
                        throw new EduException("无法选择,您已经选择过此类课程!,如果疑问,请联系客服");
                    }
                    else
                    {
                        foreach (var c in courseList)
                        {
                            if (userSrv.CheckUserHasThisCourse(openId, c.LessonCode))
                            {
                                c.CourseScheduleType = courseScheduleType;
                                continue;
                            }


                            c.UserOpenId  = openId;
                            c.UseRightNow = useRightNow;

                            //更新课程总人数
                            var cs = _dbContext.DbCourseSchedule.Where(a => a.LessonCode == c.LessonCode).FirstOrDefault();
                            cs.ApplyNum++;

                            //获取课程对应的老师
                            var cls     = _dbContext.DBCourseInfoClass.Where(s => s.CourseCode == cs.CourseCode).FirstOrDefault();
                            var tecCode = cls.TecCode;

                            //更新老师课程
                            tecSrv.UpdateTecCourse(tecCode, cs, DateTime.Now, useRightNow);

                            //添加用户课程
                            userSrv.AddUserCourse(c);
                        }

                        userSrv.UpdateCanSelectCourse(openId, courseScheduleType, false);
                    }
                    _dbContext.SaveChanges();

                    userSrv.AddNextCourseLog(openId, false);

                    CommitTrans();
                }
            }
            catch (Exception ex)
            {
                RollBackTrans();

                throw ex;
            }
        }
コード例 #3
0
ファイル: TecSrv.cs プロジェクト: flysnoopy1984/EduCenter
        public void NewTecFromUser(EUserInfo user)
        {
            int count = _dbContext.DBTecInfo.Count(t => t.UserOpenId == user.OpenId);

            if (count == 0)
            {
                int No      = 0;
                var lastTec = _dbContext.DBTecInfo.OrderByDescending(a => a.Id).FirstOrDefault();
                if (lastTec != null)
                {
                    No = (int)lastTec.Id;
                }
                No++;
                //教师信息
                ETecInfo tec = new ETecInfo
                {
                    Sex             = user.Sex,
                    Code            = EduCodeGenerator.GetTecCode(No),
                    Name            = user.Name,
                    UserOpenId      = user.OpenId,
                    WxName          = user.wx_Name,
                    Phone           = user.Phone,
                    CreatedDateTime = DateTime.Now,
                    UpdatedDateTime = DateTime.Now,
                };

                //教师技能
                _dbContext.Database.ExecuteSqlRaw(TecSrv.sql_DeleteALLTecSkill(tec.Code));

                CourseSrv courseSrv  = new CourseSrv(this._dbContext);
                var       courseList = courseSrv.GetCourseType();
                foreach (var course in courseList)
                {
                    ETecSkill ts = new ETecSkill
                    {
                        CourseType = (CourseType)course.Key,
                        SkillLevel = SkillLevel.None,
                        TecCode    = tec.Code,
                    };

                    _dbContext.DBTecSkill.Add(ts);
                }

                _dbContext.DBTecInfo.Add(tec);
                _dbContext.Database.ExecuteSqlRaw(UserSrv.sql_UpdateUserRole(UserRole.Teacher, user.OpenId));
                _dbContext.SaveChanges();
            }
        }