public async Task <ActionResult <PlayerHandicap> > PostPlayerHandicap(PlayerHandicap handicap)
        {
            _context.PlayerHandicaps.Add(handicap);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetPlayerHandicap), new { id = handicap.Id }, handicap));
        }
Exemplo n.º 2
0
        public void SetPlayerHandicap(Player.Player player, Season season, TimeSpan handicap)
        {
            var playerHandicap = new PlayerHandicap(player.Id, season.Id, handicap);

            bool isHandicapAlreadyPresent = false;

            foreach (var playerHandicap1 in Handicaps)
            {
                if (playerHandicap1.PlayerId == player.Id && playerHandicap1.SeasonId == season.Id)
                {
                    isHandicapAlreadyPresent = true;
                    playerHandicap1.Handicap = handicap;

                    if (handicap.TotalMilliseconds <= 0)
                    {
                        Handicaps.Remove(playerHandicap1);
                    }

                    break;
                }
            }

            if (!isHandicapAlreadyPresent)
            {
                Handicaps.Add(playerHandicap);
            }

            HandicapChanged?.Invoke();
        }
        public async Task <ActionResult <PlayerHandicap> > PutPlayerHandicap(PlayerHandicap handicap)
        {
            try
            {
                _context.Entry(handicap).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                return(NoContent());
            } catch (DbUpdateConcurrencyException e)
            {
                Console.WriteLine(e);
                return(BadRequest());
            }
        }