コード例 #1
0
 public void Setup()
 {
     this._student            = StudentTestUtils.GetStudent();
     this._studentDetailsDto  = StudentTestUtils.GetStudentDetailsDto(this._student.Id);
     this._studentCreationDto = StudentTestUtils.GetStudentCreationDto();
     this._studentMapper      = new StudentMapper();
 }
コード例 #2
0
 public void Cleanup()
 {
     this._student            = null;
     this._studentDetailsDto  = null;
     this._studentCreationDto = null;
     this._studentMapper      = null;
 }
コード例 #3
0
        public IActionResult CreateStudent([FromBody] StudentCreationDto student)
        {
            Students st = Mapper.Map <Students>(student);

            studentsRepo.AddStudent(st, User);

            studentsRepo.Save();

            return(CreatedAtRoute("GetStudent", new { st.StudentId }, st));
        }
コード例 #4
0
        public async Task<IActionResult> CreateStudent([FromBody] StudentCreationDto studentCreationDto)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var student = await studentService.Create(studentCreationDto);

            return CreatedAtRoute("FindStudentById", new { id = student.Id }, student);
        }
コード例 #5
0
 public void TestInitialize()
 {
     this._student1            = StudentTestUtils.GetStudent();
     this._student2            = StudentTestUtils.GetStudent();
     this._studentDto1         = StudentTestUtils.GetStudentDetailsDto(_student1.Id);
     this._studentDto2         = StudentTestUtils.GetStudentDetailsDto(_student2.Id);
     this._studentCreationDto  = StudentTestUtils.GetStudentCreationDto();
     this._mockReadRepository  = new Mock <IReadRepository>();
     this._mockWriteRepository = new Mock <IWriteRepository>();
     this._mockStudentMapper   = new Mock <IStudentMapper>();
     _studentService           = new StudentService(_mockReadRepository.Object, _mockWriteRepository.Object,
                                                    _mockStudentMapper.Object);
 }
コード例 #6
0
 public void Setup()
 {
     client                   = new CustomWebApplicationFactory <Startup>().CreateClient();
     student1                 = StudentTestUtils.GetStudent();
     student2                 = StudentTestUtils.GetStudent2();
     studentDetailsDto1       = StudentTestUtils.GetStudentDetailsDto(student1.Id);
     studentDetailsDto2       = StudentTestUtils.GetStudentDetailsDto(student2.Id);
     studentCreationDto       = StudentTestUtils.GetStudentCreationDto();
     course1                  = CourseTestUtils.GetCourse();
     course2                  = CourseTestUtils.GetCourse2();
     courseDetailsDto         = CourseTestUtils.GetCourseDetailsDto(course1.Id);
     studentCourseCreationDto = StudentCourseTestUtils.GetStudentCourseCreationDto(course2.Id);
 }
コード例 #7
0
        public async Task<IActionResult> Update(Guid id, [FromBody] StudentCreationDto studentCreationDto)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            try
            {
                var student = await studentService.Update(id, studentCreationDto);
                return NoContent();
            }
            catch (StudentNotFoundException studentNotFoundException)
            {
                return NotFound(studentNotFoundException.Message);
            }
        }
コード例 #8
0
        public async Task <IActionResult> CreateTeacher(StudentCreationDto studentCreationDto)
        {
            if (ModelState.IsValid)
            {
                var newStudent = new Student()
                {
                    Address         = studentCreationDto.Address,
                    HomePhoneNumber = studentCreationDto.HomePhoneNumber,
                    PlaceOfBirth    = studentCreationDto.PlaceOfBirth,
                    FatherName      = studentCreationDto.FatherName,

                    BirthDate    = studentCreationDto.BirthDate,
                    Email        = studentCreationDto.Email,
                    FirstName    = studentCreationDto.FirstName,
                    Gender       = studentCreationDto.Gender,
                    LastName     = studentCreationDto.LastName,
                    PhoneNumber  = studentCreationDto.PhoneNumber,
                    UserName     = studentCreationDto.UserName,
                    NationalCode = studentCreationDto.NationalCode,
                };

                IdentityResult createResult =
                    await _userManager.CreateAsync(newStudent, studentCreationDto.Password);

                if (createResult.Succeeded)
                {
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    foreach (var error in createResult.Errors)
                    {
                        ModelState.AddModelError(error.Code, error.Description);
                    }
                    return(View(studentCreationDto));
                }

                return(RedirectToAction(nameof(Index)));
            }

            return(View(studentCreationDto));
        }