Example #1
0
        public async Task <ActionResult <StudentDto> > PostCourseDto(StudentDtoForCreation studentDto)
        {
            try
            {
                var result = await _unitOfWork.StudentRepository.GetStudentByPersonalNumber(studentDto.PersonalNumber);

                if (result != null)
                {
                    return(StatusCode(404, $"A student with the personal number {result.PersonalNumber} already exists in the system."));
                }

                _unitOfWork.StudentRepository.AddStudentToRepo(studentDto);
                if (await _unitOfWork.Complete())
                {
                    return(StatusCode(201, "Succesfull, a new student resource was created"));
                }
                return(StatusCode(500, "Could not save student resource"));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }
Example #2
0
        public void AddStudentToRepo(StudentDtoForCreation student)
        {
            var creationStudentMappedToEntityModel = _mapper.Map <Student>(student);

            _context.Entry(creationStudentMappedToEntityModel).State = EntityState.Added;
        }