public IActionResult Post([FromBody] Student newStudent) { // add the new student _studentsService.Add(newStudent); // return a 201 Created status. This will also add a "location" header // with the URI of the new student. E.g., /api/students/99, if the new is 99 return(CreatedAtAction("Get", new { Id = newStudent.Id }, newStudent)); }
public async Task <IActionResult> Create([Bind("Id,Name,Surname,Age")] Students student) { if (ModelState.IsValid) { await _studentsService.Add(student); return(RedirectToAction(nameof(Index))); } return(View(student)); }
public IActionResult Post([FromBody] Student newStudent) { // add the new student _studentsService.Add(newStudent); try { _studentsService.Add(newStudent); } catch (System.Exception ex) { ModelState.AddModelError("AddStudent", ex.Message); return(BadRequest(ModelState)); } // return a 201 Created status. This will also add a "location" header // with the URI of the new student. E.g., /api/students/99, if the new is 99 return(CreatedAtAction("Get", new { Id = newStudent.Id }, newStudent)); }
public async Task <StudentDTO> AddStudent(StudentWithoutCoursesDTO studentWithoutCoursesDTO) { var student = _mapper.Map <Student>(studentWithoutCoursesDTO); student = await _studentsService.Add(student); var studentDTO = _mapper.Map <StudentDTO>(student); return(studentDTO); }
public ActionResult Post([FromBody] Models.Student student) { if (studentsService.Get().Any(s => s.Id == student.Id)) { studentsService.Update(student); return(Ok(student)); } studentsService.Add(student); return(CreatedAtAction(nameof(Get), new { id = student.Id }, student)); }
public IActionResult Post([FromBody] Student newStudent) { try { StudentService.Add(newStudent); }catch (System.Exception ex) { ModelState.AddModelError("AddStudent", ex.Message); return(BadRequest(ModelState)); } return(CreatedAtAction("Get", new { Id = newStudent.Id }, newStudent)); }
public StatusCodeResult PostStudent([FromBody] Student student) { if (!_studentsService.CheckIfStudentExists(student)) { _studentsService.Add(student); return(new StatusCodeResult(200)); } else { return(new BadRequestResult()); } }
public IActionResult Add(Persons model) { if (!ModelState.IsValid) { return(View(model)); } model.Uid = Guid.NewGuid(); _personsService.Add(model); _studentsService.Add(new Students() { PersonUid = model.Uid }); return(RedirectToAction("List")); //return RedirectToAction("List", new { departmentId = model.DepartmentId }); }
public ActionResult <Student> PostStudent(Student student) { _context.Add(student); return(CreatedAtRoute("GetStudent", new { id = student.StudentId }, student)); }
public void Post([FromBody] StudentItem student) { _studentsService.Add(student); }