public IHttpActionResult PostStudentGrade(StudentGradeDTO studentGradeDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (studentGradeDTO == null) { return(BadRequest("Missing values")); } StudentGrade studentGrade = Mapper.Map <StudentGrade>(studentGradeDTO); StudentGradeRepo.Add(studentGrade); try { StudentGradeRepo.Save(); return(Ok(studentGrade)); } catch { return(BadRequest("Failed to add student grade")); } }
public IHttpActionResult PostStudentGrade(StudentGradeDTO StudentGradeDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Mapper.Initialize(c => c.CreateMap <StudentGradeDTO, StudentGrade>()); StudentGrade StudentGrade = Mapper.Map <StudentGrade>(StudentGradeDTO); studentGradeRepo.Add(StudentGrade); studentGradeRepo.Save(); return(CreatedAtRoute("DefaultApi", new { id = StudentGrade.ID }, StudentGrade)); }