Esempio n. 1
0
        public async Task <IActionResult> PutSkill(long id, Skill skill)
        {
            if (id != skill.Id)
            {
                return(BadRequest());
            }

            _context.Entry(skill).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SkillExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 2
0
        public async Task <IActionResult> PutRating([FromRoute] int id, [FromBody] Rating rating)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != rating.Id)
            {
                return(BadRequest());
            }

            _context.Entry(rating).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RatingExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 3
0
        public async Task <IActionResult> PutPlayerPlayfab([FromBody] Player player)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            bool playerExists = PlayerExistsPlayfab(player.PlayfabId);

            if (!playerExists)
            {
                return(await PutPlayer(player));
            }
            var playerStored = await _context.Player.Include(e => e.Rating).FirstOrDefaultAsync(e => e.PlayfabId == player.PlayfabId);

            if (player.Id == playerStored.Id)
            {
                _context.Entry(player).State = EntityState.Modified;
                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    playerExists = PlayerExistsPlayfab(player.PlayfabId);
                    if (playerExists)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            else
            {
                return(Ok(playerStored));
            }

            return(NoContent());
        }
 public void Update(Skills item)
 {
     try {
         _context.Entry(item).State =
             Microsoft.EntityFrameworkCore.EntityState.Modified;
         _context.SaveChanges();
     }
     catch (Exception)
     {
         throw;
     }
 }
Esempio n. 5
0
        public async Task <IActionResult> PutPlayerInt([FromBody] TeamListModel TeamList)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var         gameInfo  = GameInfo.DefaultGameInfo;
            List <Team> teamList  = new List <Team>();
            List <int>  positions = new List <int>();

            foreach (ResultTeam team in TeamList.TeamList)
            {
                var team1 = new Team();

                foreach (string ID in team.PlayerIds)
                {
                    var player = await _context.Player.Include(e => e.Rating)
                                 .FirstOrDefaultAsync(e => e.PlayfabId == ID);

                    team1.AddPlayer(player, player.Rating);
                }
                teamList.Add(team1);
                positions.Add(team.Place);
            }
            var teams      = Teams.Concat(teamList.ToArray());
            var newRatings = TrueSkillCalculator.CalculateNewRatings(gameInfo, teams, positions);

            foreach (KeyValuePair <Player, Rating> item in newRatings)
            {
                item.Key.Rating = item.Value;
                _context.Entry(item.Key).State = EntityState.Modified;
            }
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(NotFound());
            }
            return(Ok(newRatings));
        }
Esempio n. 6
0
 public void Update(Skills item)
 {
     _context.Entry(item).State =
         Microsoft.EntityFrameworkCore.EntityState.Modified;
     _context.SaveChanges();
 }
Esempio n. 7
0
        public virtual void Add(T entity)
        {
            DbEntityEntry dbEntityEntry = _context.Entry <T>(entity);

            _context.Set <T>().Add(entity);
        }