Exemple #1
0
        public IActionResult WaitingListAdd(int id, [FromBody] LinkerViewModel model)
        {
            if (!ModelState.IsValid)
            {
                var errors = ModelState.Select(x => x.Value.Errors)
                             .Where(y => y.Count > 0)
                             .ToList();
                return(StatusCode(412, errors));
            }

            try {
                var course = _courseService.GetCourseById(id);

                var student = _studentService.AddStudentToCourseWaitingList(id, model);

                return(Ok($"{student.Name} is now registered on the waiting list\n"));
                // return Created(Url.Link("GetCourseWaitingList", new { id }), student);
            } catch (CustomObjectNotFoundException e) {
                return(NotFound(e.Message));
            } catch (CustomConflictException e) {
                //return StatusCode(409, e.Message);
                return(StatusCode(412, e.Message));
            } catch (CustomForbiddenException e) {
                return(StatusCode(412, e.Message));
                //return StatusCode(403, e.Message);
            } catch (Exception e) {
                return(StatusCode(500, e.Message));
            }
        }