Ejemplo n.º 1
0
        public async Task <ActionResult <Player> > PostPlayer(Player onlyName)
        {
            string inputName = onlyName.Name;
            var    player    = await _context.Players.SingleOrDefaultAsync(e => e.Name == inputName);

            if (player != null)
            {
                _context.Entry(player).State = EntityState.Modified;
            }
            else
            {
                player = new Player(inputName);
                _context.Players.Add(player);
            }
            player.Ip = _accessor.ActionContext.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString();
            await _context.SaveChangesAsync();

            BroadcastHelper.Online(_hubContext, player);
            _gamecenter.AddOnlinePlayer(player);
            return(CreatedAtAction(nameof(GetPlayer), new { id = player.Id }, player));
        }