public ActionResult CreateFreehandDoubleGoal([FromBody] FreehandDoubleGoalCreateDto freehandGoalCreateDto) { try { int matchId = freehandGoalCreateDto.DoubleMatchId; string userId = User.Identity.Name; bool matchAccess = _doubleFreehandMatchService.CheckMatchPermission(int.Parse(userId), matchId); if (!matchAccess) { return(Forbid()); } var newGoal = _doubleFreehandGoalservice.CreateDoubleFreehandGoal(int.Parse(userId), freehandGoalCreateDto); var freehandGoalReadDto = _mapper.Map <FreehandDoubleGoalReadDto>(newGoal); return(CreatedAtRoute("GetFreehandDoubleGoalById", new { goalId = newGoal.Id }, freehandGoalReadDto)); } catch (Exception e) { return(StatusCode(500, e.Message)); } }
public FreehandDoubleGoalModel CreateDoubleFreehandGoal(int userId, FreehandDoubleGoalCreateDto freehandDoubleGoalCreateDto) { FreehandDoubleGoalModel fhg = new FreehandDoubleGoalModel(); DateTime now = DateTime.Now; fhg.DoubleMatchId = freehandDoubleGoalCreateDto.DoubleMatchId; fhg.OpponentTeamScore = freehandDoubleGoalCreateDto.OpponentTeamScore; fhg.ScoredByUserId = freehandDoubleGoalCreateDto.ScoredByUserId; fhg.ScorerTeamScore = freehandDoubleGoalCreateDto.ScorerTeamScore; fhg.TimeOfGoal = now; fhg.WinnerGoal = freehandDoubleGoalCreateDto.WinnerGoal; _context.FreehandDoubleGoals.Add(fhg); _context.SaveChanges(); UpdateFreehandDoubleMatchScore(userId, freehandDoubleGoalCreateDto); return(fhg); }
private void UpdateFreehandDoubleMatchScore(int userId, FreehandDoubleGoalCreateDto freehandGoalCreateDto) { FreehandDoubleMatchModel fmm = _context.FreehandDoubleMatches.FirstOrDefault(f => f.Id == freehandGoalCreateDto.DoubleMatchId); if (fmm.PlayerOneTeamA == freehandGoalCreateDto.ScoredByUserId || fmm.PlayerTwoTeamA == freehandGoalCreateDto.ScoredByUserId) { fmm.TeamAScore = freehandGoalCreateDto.ScorerTeamScore; } else { fmm.TeamBScore = freehandGoalCreateDto.ScorerTeamScore; } // Check if match is finished if (freehandGoalCreateDto.WinnerGoal == true) { fmm.EndTime = DateTime.Now; fmm.GameFinished = true; } _context.SaveChanges(); }