public async Task <ActionResult> SignUp([FromBody] CourseSignUpModel model) { _logger.LogTrace("Post to SignUp"); _logger.LogInfo($"SignUp called: {model}"); //Check if student exists var student = await _studentService.FindById(model.StudentId); if (student == null) { _logger.LogWarn($"Sign Up | Student not found {model.StudentId}"); return(NotFound(new { StatusCode = StatusCodes.Status404NotFound, Message = "Student not found " + model.StudentId })); } ; //Check Availability if (!_coursesService.CheckAvailabilityAsync(model.CourseId).Result) { _logger.LogWarn($"Sign Up | Max capacity reached {model.CourseId}"); return(Unauthorized(new { StatusCode = StatusCodes.Status401Unauthorized, Message = "Course at max capacity" })); } //Check if student already signed if (await _studentSessionService.CheckIfAlreadySignedIn(model.StudentId, model.CourseId)) { _logger.LogWarn($"Sign Up | Student already signed in {model.StudentId}"); return(BadRequest(new { StatusCode = StatusCodes.Status400BadRequest, Message = "Student already signed In" })); } ; //Add student to session await _coursesService.AddStudentSessionAsync(model.CourseId, model.StudentId); _logger.LogInfo("Student sign up to course created successfully"); return(CreatedAtAction(nameof(SignUp), "Student Signed up")); }
public async Task <ActionResult> SignUpMessageBus([FromBody] CourseSignUpModel model) { _logger.LogTrace("Post to SignUp/MessageBus"); var student = await _studentService.FindById(model.StudentId); if (student == null) { _logger.LogWarn($"Sign Up MessageBus | Student not found {model.StudentId}"); return(NotFound(new { StatusCodes.Status404NotFound, Message = "Student not found " + model.StudentId })); } ; await _serviceBusService.SendMessage(new { model.StudentId, model.CourseId, student.Email }); _logger.LogInfo("Student sign up send to message bus successfully"); return(CreatedAtAction(nameof(SignUpMessageBus), "Message Sent")); }