public async Task <IActionResult> Put(int id, [FromBody] StudentViewModel student)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            Student updateStudent = _studentsRepository.GetSingle(s => s.ID == id);

            if (updateStudent == null)
            {
                return(NotFound("The Student to be updated was not found"));
            }
            else
            {
                updateStudent.LastName       = student.LastName;
                updateStudent.FirstMidName   = student.FirstMidName;
                updateStudent.EnrollmentDate = student.EnrollmentDate;

                await _studentsRepository.CommitAsync();
            }


            //student = Mapper.Map<Student, StudentViewModel>(updateStudent);

            return(new ObjectResult("Student updated successfully"));
        }
Exemple #2
0
        public async Task <IActionResult> Put(int?id, [FromBody] StudentViewModel student)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id == null)
            {
                return(NotFound());
            }

            Student updateStudent = _studentsRepository.GetSingle(s => s.ID == id);

            if (updateStudent == null)
            {
                return(NotFound());
            }
            else
            {
                updateStudent.LastName       = student.LastName;
                updateStudent.FirstMidName   = student.FirstMidName;
                updateStudent.EnrollmentDate = student.EnrollmentDate;

                await _studentsRepository.CommitAsync();
            }

            //student = Mapper.Map<Student, StudentViewModel>(updateStudent);

            return(new NoContentResult());
        }