예제 #1
0
        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"));
            }
        }
예제 #2
0
        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));
        }