Exemple #1
0
        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));
        }
Exemple #2
0
        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));
        }
Exemple #6
0
 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));
 }
Exemple #7
0
 public StatusCodeResult PostStudent([FromBody] Student student)
 {
     if (!_studentsService.CheckIfStudentExists(student))
     {
         _studentsService.Add(student);
         return(new StatusCodeResult(200));
     }
     else
     {
         return(new BadRequestResult());
     }
 }
Exemple #8
0
 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 });
 }
Exemple #9
0
        public ActionResult <Student> PostStudent(Student student)
        {
            _context.Add(student);

            return(CreatedAtRoute("GetStudent", new { id = student.StudentId }, student));
        }
Exemple #10
0
 public void Post([FromBody] StudentItem student)
 {
     _studentsService.Add(student);
 }