Beispiel #1
0
        /// <summary>
        /// 学生注册
        /// </summary>
        /// <param name="studentDto"></param>
        /// <returns></returns>
        public async Task <StudentDto> RegisterStudent(StudentDto studentDto)
        {
            // 判断学号是否已经注册
            var stu = await _studentRepository.Where(x => x.StuNo == studentDto.StuNo).FirstOrDefaultAsync();

            if (stu != null)
            {
                throw Oops.Oh(StudentErrorCodes.s1205);
            }
            // 判断班级是否存在
            var classes = await _studentRepository.Change <TbClass>().FirstOrDefaultAsync(x => x.Id == studentDto.ClassesId);

            if (classes == null)
            {
                throw Oops.Oh(StudentErrorCodes.s1202);
            }
            // 判断班级是否属于该系别
            if (classes.DeptId != studentDto.DeptId)
            {
                throw Oops.Oh(StudentErrorCodes.s1203);
            }
            // studentDto.CreateTime = TimeUtil.GetTimeStampNow();
            var stduent = await _studentRepository
                          .InsertNowAsync(studentDto.Adapt <TbStudent>());

            return(stduent.Entity.Adapt <StudentDto>());
        }
Beispiel #2
0
        /// <summary>
        /// 修改学生信息
        /// </summary>
        /// <param name="studentDto"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public async Task <StudentDto> UpdateStudent(StudentDto studentDto)
        {
            var stu = await _studentRepository
                      .Entities
                      .Include(x => x.Classes)
                      .Include(x => x.Dept)
                      .FirstOrDefaultAsync(x => x.Id == studentDto.Id);

            if (stu == null)
            {
                throw Oops.Oh(StudentErrorCodes.s1204);
            }
            var newStu     = studentDto.Adapt(stu);
            var changeInfo = await newStu.UpdateExcludeAsync(u => u.CreateTime);

            return(newStu.Adapt <StudentDto>());
        }