public Task <Activity> CreateAsync(ActivityCreationInfo activityCreationInfo, DateTime endAt, CancellationToken cancellationToken) { if (activityCreationInfo == null) { throw new ArgumentNullException(nameof(activityCreationInfo)); } cancellationToken.ThrowIfCancellationRequested(); var activity = new Activity { Status = Status.New, CreatedAt = DateTime.Now, Tags = activityCreationInfo.Tags, Experts = activityCreationInfo.Experts, StartAt = activityCreationInfo.StartAt, MaraphoneId = activityCreationInfo.MaraphoneId, CreatedBy = activityCreationInfo.CreatedBy, EndAt = endAt }; activities.InsertOne(activity, cancellationToken: cancellationToken); return(Task.FromResult(activity)); }
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)); }