public async Task <ActionResult <StatDTO> > PostStat(StatDTO stat) { await _stat.Create(stat); await _log.CreateLog(HttpContext, User.FindFirst("UserName").Value); return(CreatedAtAction("GetStat", new { id = stat.Id }, stat)); }
/// <summary> /// Get a list of all stats in the database /// </summary> /// <returns>Successful result with list of stats</returns> public async Task <StatDTO> GetStat(int id) { var result = await _context.Stat.Where(x => x.Id == id).FirstOrDefaultAsync(); StatDTO resultDTO = new StatDTO() { Name = result.Name, Id = result.Id }; return(resultDTO); }
public async Task <IActionResult> PutStat(int id, StatDTO stat) { if (id != stat.Id) { return(BadRequest()); } var result = await _stat.Update(stat); await _log.CreateLog(HttpContext, User.FindFirst("UserName").Value); return(Ok(result)); }
/// <summary> /// Update a given stat in the database /// </summary> /// <param name="id">Id of stat to be updated</param> /// <param name="stat">Stat information for update</param> /// <returns>Successful result of specified updated stat</returns> public async Task <StatDTO> Update(StatDTO statDTO) { Stat stat = new Stat() { Id = statDTO.Id, Name = statDTO.Name }; _context.Entry(stat).State = EntityState.Modified; await _context.SaveChangesAsync(); return(statDTO); }
/// <summary> /// Creates a new stat in the database /// </summary> /// <param name="stat">Stat information for creation</param> /// <returns>Successful result of stat creation</returns> public async Task <StatDTO> Create(StatDTO stat) { Stat newStat = new Stat() { Name = stat.Name, }; _context.Entry(newStat).State = EntityState.Added; await _context.SaveChangesAsync(); stat.Id = newStat.Id; return(stat); }
public StatDTO GetStats() { CheckPlayerLog(); var result = new StatDTO() { }; var todayStat = _episodeRepository.GetTodayStats(); result.TodayStats = new SessionStatDTO { CrownCount = todayStat?.CrownCount ?? 0, EpisodeCount = todayStat?.EpisodeCount ?? 0, // TODO add cheater count CheaterCount = 0 }; var seasonStat = _episodeRepository.GetSeasonStats(1); result.SeasonStats = new SessionStatDTO { CrownCount = seasonStat?.CrownCount ?? 0, EpisodeCount = seasonStat?.EpisodeCount ?? 0, // TODO add cheater count CheaterCount = 0 }; //_logger.LogInformation($"Current Round: {LogParserV2.currentRound}"); result.RoundStats = _episodeRepository.GetRoundStats(LogParserV2.currentRound); if (result.RoundStats == null) { result.RoundStats = new RoundStatsDto { GoldCount = 0, SilverCount = 0, BronzeCount = 0, QualifiedCount = 0, NotQualifiedCount = 0, RoundType = LogParserV2.currentRound } } ; string readableRoundType; if (RoundEntity.RoundTypeMap.TryGetValue(LogParserV2.currentRound, out readableRoundType)) { result.CurrentRound = readableRoundType; } result.Streak = _episodeRepository.GetStreak(); return(result); }
public async Task CanGetStat() { StatDTO newStat = new StatDTO() { Id = 4, Name = "Agility" }; var repo = BuildRepo(); var saved = await repo.Create(newStat); var result = await repo.GetStat(newStat.Id); Assert.Equal(newStat.Id, result.Id); }
public async Task CanUpdateStat() { StatDTO newStat = new StatDTO() { Id = 1, Name = "StatUpdate" }; var repo = BuildRepo(); await repo.Update(newStat); var result = await repo.GetStat(1); Assert.Equal(1, result.Id); Assert.Equal(newStat.Name, result.Name); }
public async Task CanSaveStat() { StatDTO newStat = new StatDTO() { Id = 4, Name = "Agility", }; var repo = BuildRepo(); var saved = await repo.Create(newStat); Assert.NotNull(saved); Assert.NotEqual(0, saved.Id); Assert.Equal(saved.Id, newStat.Id); Assert.Equal(saved.Name, newStat.Name); }
public StatDTO ToDTO(StatEntity entity) { StatDTO dto = new StatDTO(); dto.ItemName = entity.ItemId.GetEnumName <ItemEnum>().Replace("0", "、").Replace("1", "(").Replace("2", ")"); dto.Id = entity.Id; dto.TypeId = entity.TypeId; dto.ItemId = entity.ItemId; dto.TypeName = entity.TypeId.GetEnumName <TypeEnum>().Replace("0", "、").Replace("1", "(").Replace("2", ")"); dto.QuarterNumber = entity.QuarterNumber; dto.QuarterAmount = entity.QuarterAmount; dto.YearNumber = entity.YearNumber; dto.YearAmount = entity.YearAmount; dto.TotalNumber = entity.TotalNumber; dto.TotalAmount = entity.TotalAmount; return(dto); }
public async Task <StatDTO> GetStats() { var results = _context.DnaRecords.AsQueryable(); var mutants = await results.CountAsync(x => x.IsMutant); var humans = await results.CountAsync() - mutants; var statDTO = new StatDTO() { CountMutantDNA = mutants, CountHumanDNA = humans, Ratio = humans > 0 ? (mutants / (double)humans).ToString("0.#", CultureInfo.InvariantCulture) : "0.0" }; return(statDTO); }