Ejemplo n.º 1
0
        public async Task Edit(StudentExamTimeInput input)
        {
            //检查Id参数
            if (!input.Id.HasValue)
            {
                throw new UserFriendlyException("传入Id参数不正确!");
            }

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

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

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

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

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

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

                studentExamTime.StudentId = input.StudentId.Value;
            }
            if (input.Credit.HasValue)
            {
                studentExamTime.Credit = input.Credit.Value;
            }

            //执行插入数据方法
            await _studentExamTimeRepository.UpdateAsync(studentExamTime);
        }
Ejemplo n.º 2
0
        public async Task Add(StudentExamTimeInput input)
        {
            //验证传入参数
            if (!input.ExamTimeId.HasValue)
            {
                throw new UserFriendlyException("传入Start参数不正确!");
            }
            if (!input.StudentId.HasValue)
            {
                throw new UserFriendlyException("传入End参数不正确!");
            }

            //验证学生预约的考试时间是否存在
            var examTime = await _examTimeRepository.FirstOrDefaultAsync(x => x.Id == input.ExamTimeId);

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

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

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

            //创建学生预约考试信息
            var studentExamTime = new Education.StudentExamTime
            {
                ExamTimeId = input.ExamTimeId.Value,
                StudentId  = input.StudentId.Value
            };

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

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