public IActionResult Create([FromBody] LectureCreateRequest request)
 {
     try
     {
         var userId       = _authenticationService.GetAuthenticatedUserId(User);
         var universityId = int.Parse(User.Claims.FirstOrDefault(x => x.Type == "UniversityId")?.Value);
         var lectureId    = _lectureService.Create(request.Code, request.Name, universityId, userId);
         return(new ObjectResult(new
         {
             StatusCode = ResponseConstants.Success,
             LectureId = lectureId
         }));
     }
     catch (LectureAlreadyExistsException)
     {
         return(new ObjectResult(new Result {
             StatusCode = ResponseConstants.LectureAlreadyExist
         }));
     }
     catch (UserNotFoundException)
     {
         return(BadRequest());
     }
     catch (Exception)
     {
         return(new ObjectResult(new Result {
             StatusCode = ResponseConstants.Unknown
         }));
     }
 }
Ejemplo n.º 2
0
 public ActionResult Post([FromBody] CreateLecture command)
 {
     _lectureService.Create
         (command.Name, command.Number, command.Description);
     return(Created("api/[controller]/" + command.Name, null));
 }