public Task <CourseProgress> StartCourseAsync(Ticket ticket, string courseId, string userId = null) { var startOptions = new CourseStartOptions { CourseId = courseId }; var query = userId != null ? new Dictionary <string, string> { ["userId"] = userId } : null; return(InvokeApiMethod <CourseProgress>( HttpMethod.Post, path: "progress", ticket: ticket, content: startOptions, queryParameters: query)); }
public async Task <IActionResult> StartCourse([FromBody] CourseStartOptions startOptions, [FromQuery] string userId) { if (startOptions == null) { return(BadRequest("CourseStartOptions is null")); } if (!User.IsInRole("Client") || string.IsNullOrEmpty(userId)) { userId = User.GetId(); } if (!IdIsValid(userId)) { return(Forbid($"The user has no rights or the id = {userId} is invalid")); } var course = await courseRepository.GetAsync(startOptions.CourseId); if (course == null) { return(BadRequest($"Invalid course id = {startOptions.CourseId}")); } if (await progressRepository.ContainsAsync(userId, course.Id)) { return(BadRequest($"User id = {userId} hasn't course with id = {startOptions.CourseId}")); } var courseProgress = course.CreateProgress(userId); courseProgress.Id = await progressRepository.InsertAsync(courseProgress); courseProgress.SetUpLinks(); var uri = Request.GetUri(); return(Created($"{uri}/{courseProgress.CourceId}", courseProgress)); }