public async Task <IActionResult> GetAsync([FromRoute] string id, CancellationToken cancellationToken) { if (id == null) { var error = ServiceErrorResponses.InvalidRouteParameter("activityId"); return(this.BadRequest(error)); } var modelActivity = await activityRepository.GetByIdAsync(id); if (modelActivity == null) { var message = "Activity with id " + id + " not found."; var error = ServiceErrorResponses.NoSuchObject("Activity", message); return(this.NotFound(error)); } var clientActivity = ActivityConverter.Convert(modelActivity); return(Ok(clientActivity)); }
public async Task <IActionResult> CreateAsync([FromBody] Client.ActivityBuildInfo buildInfo, CancellationToken cancellationToken) { if (buildInfo == null) { var error = ServiceErrorResponses.BodyIsMissing("ActivityCreationInfo"); return(this.BadRequest(error)); } var userId = User.FindFirstValue("userId"); if (userId == null) { var error = ServiceErrorResponses.InvalidClaims("userId"); return(this.BadRequest(error)); } var maraphoneId = buildInfo.MaraphoneId; var maraphone = await maraphoneRepository.GetAsync(maraphoneId, cancellationToken); if (maraphone == null) { var error = ServiceErrorResponses.NoSuchObject("Maraphone", "Maraphone not found"); return(this.NotFound(error)); } var duration = maraphone.Duration; var endAt = buildInfo.StartAt + duration; var activityCreationInfo = new ActivityCreationInfo(buildInfo.MaraphoneId, buildInfo.Tags, userId, buildInfo.Experts, buildInfo.StartAt, endAt); var modelActivity = await activityRepository.CreateAsync(activityCreationInfo, endAt, cancellationToken); var clientActivity = ActivityConverter.Convert(modelActivity); return(CreatedAtRoute( "GetActivity", new { id = clientActivity.Id }, clientActivity)); }