public ActionResult CreateStudents(Student student)
        {
            string  errorStatus = _student.CreateStudent(student);
            Message message     = new Message(errorStatus);

            return(Ok(message.ErrorMessage(student.StudentId)));
        }
예제 #2
0
        public IActionResult CreateStudent([FromBody] StudentDTO studentDTO)
        {
            if (studentDTO == null)
            {
                return(BadRequest(ModelState));
            }
            if (_student.StudentExist(studentDTO.Name))
            {
                ModelState.AddModelError("", "Student already exist");
                return(StatusCode(404, ModelState));
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var studentObj = _mapper.Map <Student>(studentDTO);

            if (!_student.CreateStudent(studentObj))
            {
                ModelState.AddModelError("", $"Something went wrong when saving the record{studentDTO.Name}");
                return(StatusCode(500, ModelState));
            }
            return(CreatedAtRoute("GetStudent", new { id = studentObj.SID }, studentObj));
        }
예제 #3
0
        public async Task <ActionResult <Model> > CreateStudent(Model model)
        {
            if (model is null)
            {
                return(BadRequest());
            }
            var students = student.CreateStudent(model);

            if (students is null)
            {
                return(BadRequest());
            }
            return(Ok(students));
        }
예제 #4
0
        public IActionResult CreateStudent([FromBody] Student studentObj)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            if (studentObj == null)
            {
                return(BadRequest());
            }

            _studentRepo.CreateStudent(studentObj);

            return(Ok());
        }