コード例 #1
0
        public async Task Edit(StudentCourseTimeInput input)
        {
            //检查Id参数
            if (!input.Id.HasValue)
            {
                throw new UserFriendlyException("传入Id参数不正确!");
            }

            //获取需要修改的对象
            var studentCourseTime = await _studentCourseTimeRepository.FirstOrDefaultAsync(x => x.Id == input.Id.Value);

            if (studentCourseTime == null)
            {
                throw new UserFriendlyException("当前的预约信息不存在!");
            }

            //修改属性值
            if (input.CourseTimeId.HasValue)
            {
                //验证学生预约的上课时间是否存在
                var courseTime = await _courseTimeRepository.FirstOrDefaultAsync(x => x.Id == input.CourseTimeId);

                if (courseTime == null)
                {
                    throw new UserFriendlyException("该课程不存在!");
                }

                studentCourseTime.CourseTimeId = input.CourseTimeId.Value;
            }
            if (input.StudentId.HasValue)
            {
                //验证当前预约的学生是否存在
                var student = await _studentRepository.FirstOrDefaultAsync(x => x.Id == input.StudentId);

                if (student == null)
                {
                    throw new UserFriendlyException("该学生不存在!");
                }

                studentCourseTime.StudentId = input.StudentId.Value;
            }
            if (input.ClassCredit.HasValue)
            {
                studentCourseTime.ClassCredit = input.ClassCredit.Value;
            }

            //执行修改数据方法
            await _studentCourseTimeRepository.UpdateAsync(studentCourseTime);
        }
コード例 #2
0
        public async Task Add(StudentCourseTimeInput input)
        {
            //验证传入参数
            if (!input.CourseTimeId.HasValue)
            {
                throw new UserFriendlyException("传入Start参数不正确!");
            }
            if (!input.StudentId.HasValue)
            {
                throw new UserFriendlyException("传入End参数不正确!");
            }

            //验证学生预约的上课时间是否存在
            var courseTime = await _courseTimeRepository.FirstOrDefaultAsync(x => x.Id == input.CourseTimeId);

            if (courseTime == null)
            {
                throw new UserFriendlyException("该课程不存在!");
            }

            //验证当前预约的学生是否存在
            var student = await _studentRepository.FirstOrDefaultAsync(x => x.Id == input.StudentId);

            if (student == null)
            {
                throw new UserFriendlyException("该学生不存在!");
            }

            //创建学生预约课程信息
            var studentCourseTime = new Education.StudentCourseTime
            {
                CourseTimeId = input.CourseTimeId.Value,
                StudentId    = input.StudentId.Value
            };

            //随堂分数属性赋值
            if (input.ClassCredit.HasValue)
            {
                studentCourseTime.ClassCredit = input.ClassCredit.Value;
            }

            //执行插入数据方法
            await _studentCourseTimeRepository.InsertAsync(studentCourseTime);
        }