Пример #1
0
        public async Task UpdateAlreadyExistingStudent()
        {
            var student = new Student()
            {
                Id          = 1,
                FirstName   = "AdeTola",
                LastName    = "AdeTola",
                Sport       = "Tennis",
                Gender      = "Male",
                DateOfBirth = DateTimeOffset.Parse("2010-03-04"),
                Level       = "Basic4"
            };

            _studentRepositoryMock.Setup(repo => repo.UpdateStudent(It.IsAny <Student>(), 1)).Verifiable();

            var stud = new StudentCreationViewModel()
            {
                FirstName   = "AdeTola",
                LastName    = "AdeTola",
                Sport       = "Football",
                Gender      = "Male",
                DateOfBirth = DateTimeOffset.Parse("2013-03-04"),
                Level       = "Basic4"
            };

            var updateStd = await _sysUnderTest.UpdateStudent(stud, 1);

            _studentRepositoryMock.Verify(repo => repo.UpdateStudent(It.IsAny <Student>(), 1), Times.Once);
        }
Пример #2
0
        public async Task <bool> AddStudent(StudentCreationViewModel student)
        {
            bool ans = false;
            var  std = StudentCreationViewModel.ToStudent(student);

            ans = await _studentRepository.AddStudent(std);

            return(ans);
        }
Пример #3
0
        public async Task <bool> UpdateStudent(StudentCreationViewModel student, int id)
        {
            var std = StudentCreationViewModel.ToStudent(student);

            std.Id = 1;
            //var std = _mapper.Map<StudentCreationViewModel, Student>(student);
            bool result = await _studentRepository.UpdateStudent(std, id);

            return(result);
        }
Пример #4
0
        public async Task <ActionResult> PutAsync(int id, [FromBody] StudentCreationViewModel student)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (student == null)
            {
                return(BadRequest(" Student doest not exist"));
            }

            //student.Id = id;

            var pupil = await context.UpdateStudent(student, id);

            return(Ok(pupil));
        }
Пример #5
0
        public async Task <ActionResult> PostAsync([FromBody] StudentCreationViewModel student)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var age = DateTime.Now.Year - student.DateOfBirth.Year;

            if (!(age >= 5 && age <= 20))
            {
                return(BadRequest("Date of birth is not within the range limit. Age range is between 5 and 20."));
            }

            bool pupil = await context.AddStudent(student);

            if (pupil)
            {
                return(Ok("Student data saved successfully"));
            }
            else
            {
                return(BadRequest("Something went wrong, data not saved"));
            }
        }