public async Task<IActionResult> Post([FromBody] Student student) { try { var res = await _studentRepository.AddAsync(student); return Ok(res); } catch (Exception ex) { return BadRequest(ex); } }
public async Task <IActionResult> Create([FromBody] StudentViewModel student) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Student newStudent = new Student { LastName = student.LastName, FirstMidName = student.FirstMidName, EnrollmentDate = student.EnrollmentDate }; await _studentsRepository.AddAsync(newStudent); await _studentsRepository.CommitAsync(); student = Mapper.Map <Student, StudentViewModel>(newStudent); return(CreatedAtRoute("GetStudent", new { controller = "Students", id = student.ID }, student)); }