Ejemplo n.º 1
0
        public async Task <IActionResult> PutMatch(Guid id, Match match)
        {
            if (id != match.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,Name,Alias,Image")] Guild guild)
        {
            if (ModelState.IsValid)
            {
                guild.Id = Guid.NewGuid();
                _context.Add(guild);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(guild));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("Id,CharacterId,Date,Ranking")] Rank rank)
        {
            if (ModelState.IsValid)
            {
                rank.Id = Guid.NewGuid();
                _context.Add(rank);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CharacterId"] = new SelectList(_context.Characters, "Id", "Id", rank.CharacterId);
            return(View(rank));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("Id,Name,GuildId,GuildPosition,IsActivated")] Character character)
        {
            if (ModelState.IsValid)
            {
                character.Id = Guid.NewGuid();
                _context.Add(character);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GuildId"] = new SelectList(_context.Guilds, "Id", "Name", character.GuildId);
            var guildPositions = EnumHelper <GuildPositions> .GetValues().Select(GP => new { Key = GP, Value = EnumHelper <GuildPositions> .GetDisplayValue(GP) });

            ViewData["GuildPosition"] = new SelectList(guildPositions, "Key", "Value", character.GuildPosition);
            return(View(character));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Resolve(Guid id, Guid winner, Guid loser, int draw)
        {
            Match m = await _context.Match.FindAsync(id);

            if (m._played)
            {
                return(RedirectToAction("Rank"));
                //return View("Rank", await ResolveRankView());
            }
            Team alpha = await _context.Team.FindAsync(winner);

            Team beta = await _context.Team.FindAsync(loser);

            double aELO = alpha.Elo;
            double bELO = beta.Elo;
            double eA   = 1.0 / (1.0 + Math.Pow(10.0, ((bELO - aELO) / 400)));
            double eB   = 1.0 / (1.0 + Math.Pow(10.0, ((aELO - bELO) / 400)));

            if (draw == 1)
            {
                alpha.Draws++;
                beta.Draws++;
                alpha.Elo += Convert.ToInt16((32.0 * (0.5 - eA)));
                beta.Elo  += Convert.ToInt16((32.0 * (0.5 - eB)));
                m.draw     = true;
            }
            else
            {
                alpha.Wins++;
                beta.Losses++;
                alpha.Elo += Convert.ToInt16((32.0 * (1.0 - eA)));
                beta.Elo  += Convert.ToInt16((32.0 * (0.0 - eB)));
            }
            m._played   = true;
            m._playedOn = DateTime.UtcNow;
            m.winner    = alpha;
            m.loser     = beta;
            _context.Entry(alpha).State = EntityState.Modified;
            _context.Entry(beta).State  = EntityState.Modified;
            _context.Entry(m).State     = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(RedirectToAction("Rank"));
            //return View("Rank", await ResolveRankView());
        }