public void DeleteFreehandGoal(FreehandDoubleGoalModel freehandDoubleGoalModel)
 {
     if (freehandDoubleGoalModel == null)
     {
         throw new ArgumentNullException(nameof(freehandDoubleGoalModel));
     }
     SubtractDoubleFreehandMatchScore(freehandDoubleGoalModel);
     _context.FreehandDoubleGoals.Remove(freehandDoubleGoalModel);
     _context.SaveChanges();
 }
        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 SubtractDoubleFreehandMatchScore(FreehandDoubleGoalModel freehandDoubleGoalModel)
        {
            var match = _context.FreehandDoubleMatches.FirstOrDefault(x => x.Id == freehandDoubleGoalModel.DoubleMatchId);

            if (freehandDoubleGoalModel.ScoredByUserId == match.PlayerOneTeamA || freehandDoubleGoalModel.ScoredByUserId == match.PlayerTwoTeamA)
            {
                if (match.TeamAScore > 0)
                {
                    match.TeamAScore -= 1;
                }
            }
            else
            {
                if (match.TeamBScore > 0)
                {
                    match.TeamBScore -= 1;
                }
            }
            _context.SaveChanges();
        }
 public void UpdateFreehanDoubledGoal(FreehandDoubleGoalModel goalItem)
 {
     // Do nothing
 }