public ActionResult CreateDoubleFreehandMatch([FromBody] FreehandDoubleMatchCreateDto freehandDoubleMatchCreateDto) { string userId = User.Identity.Name; if (freehandDoubleMatchCreateDto.PlayerOneTeamA != int.Parse(userId) && freehandDoubleMatchCreateDto.PlayerOneTeamB != int.Parse(userId) && freehandDoubleMatchCreateDto.PlayerTwoTeamA != int.Parse(userId) && freehandDoubleMatchCreateDto.PlayerTwoTeamB != int.Parse(userId)) { return(Forbid()); } var newMatch = _doubleMatchService.CreateFreehandDoubleMatch(int.Parse(userId), freehandDoubleMatchCreateDto); var freehandDoubleMatchReadDto = _mapper.Map <FreehandDoubleMatchResponseDto>(newMatch); return(CreatedAtRoute("GetFreehandDoubleMatchByMatchId", new { matchId = newMatch.Id }, freehandDoubleMatchReadDto)); }
public FreehandDoubleMatchModel CreateFreehandDoubleMatch(int userId, FreehandDoubleMatchCreateDto freehandDoubleMatchCreateDto) { FreehandDoubleMatchModel fdm = new FreehandDoubleMatchModel(); DateTime now = DateTime.Now; fdm.OrganisationId = freehandDoubleMatchCreateDto.OrganisationId; fdm.PlayerOneTeamA = freehandDoubleMatchCreateDto.PlayerOneTeamA; fdm.PlayerOneTeamB = freehandDoubleMatchCreateDto.PlayerOneTeamB; fdm.PlayerTwoTeamA = freehandDoubleMatchCreateDto.PlayerTwoTeamA; fdm.PlayerTwoTeamB = freehandDoubleMatchCreateDto.PlayerTwoTeamB; fdm.StartTime = now; fdm.EndTime = null; fdm.TeamAScore = freehandDoubleMatchCreateDto.TeamAScore; fdm.TeamBScore = freehandDoubleMatchCreateDto.TeamBScore; if (!string.IsNullOrEmpty(freehandDoubleMatchCreateDto.NicknameTeamA)) { fdm.NicknameTeamA = freehandDoubleMatchCreateDto.NicknameTeamA; } if (!string.IsNullOrEmpty(freehandDoubleMatchCreateDto.NicknameTeamB)) { fdm.NicknameTeamB = freehandDoubleMatchCreateDto.NicknameTeamB; } if (freehandDoubleMatchCreateDto.UpTo != null) { fdm.UpTo = freehandDoubleMatchCreateDto.UpTo; } fdm.GameFinished = false; fdm.GamePaused = false; _context.FreehandDoubleMatches.Add(fdm); _context.SaveChanges(); return(fdm); }