public async Task <IActionResult> CreateMatchWithInvites([FromBody] CreateInviteMatchDTO match) { _Logger.LogInformation($"Matches: {HelperMethods.GetCallerMemberName()}"); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var result = await Mediator.Send(new CreateMatchWithInvitesCommand() { Match = match }); if (result != null) { return(CreatedAtRoute("GetMatchById", new { id = result }, match)); } return(BadRequest("Save failed")); } catch (Exception ex) { _Logger.LogError($"Something went wrong at CreateMatchWithInvites action: {ex.Message}"); return(StatusCode(500, "Internal server error")); } }
/// <summary> /// Support the creation of a Match Record and trigger the invitation for all club members /// </summary> /// <param name="matchView"></param> /// <returns>the unique id of the match : or null</returns> public async Task <Guid?> CreateMatchWithInvites(CreateInviteMatchDTO matchView) { _Logger.LogInformation($"MatchManager: {HelperMethods.GetCallerMemberName()}"); var generator = _MatchCreateFactory.GetInvitationMatchCreator(); return(await generator.Create(matchView)); }
/// <summary> /// Supports creation with invites also being handled /// </summary> /// <param name="match"></param> /// <returns></returns> public override async Task <Guid?> Create(object match) { Guid?matchId = null; CreateInviteMatchDTO castMatch = (CreateInviteMatchDTO)match; var mappedMapped = this._Mapper.Map <Match>(match); //Step1. Check if invites are needed to be added/created if (castMatch.SendInvites == true) { if (!castMatch.SelectedMembers.Any()) { await GetAllMembersAndAddToInvites(mappedMapped); } } //StepX. Save the match! (N.B. here we might want to return the object!) matchId = await this.SaveNewMatch(mappedMapped); if (matchId != null) { //Now we need to send the invites then! await CreateInvitationRequestAndPublish(mappedMapped.Invites.ToList(), castMatch.Date); mappedMapped.InvitesSent = true; } return(matchId); }