public async Task <IActionResult> Put([FromBody] RoundDto dto) { var round = _mapper.Map <Round>(dto); await _roundService.UpdateAsync(round); return(Ok("Updated")); }
public ICollection <RoundTileDto> Resolve(Round source, RoundDto destination, ICollection <RoundTileDto> destMember, ResolutionContext context) { var roundId = source.Id; var boardTiles = _context.RoundTiles.Where(rt => rt.RoundId == roundId && rt.Owner == DefaultValue.board); return(_mapper.Map <ICollection <RoundTile>, ICollection <RoundTileDto> >(boardTiles.ToList())); }
public async Task <IActionResult> Post([FromBody] RoundDto dto) { var round = _mapper.Map <Round>(dto); await _roundService.AddAsync(round); return(Created("localhost", "")); }
private int GetPreviousRoundScoresSum(RoundDto round) { var playerRounds = _roundRepository.GetRoundsByPlayerId(round.PlayerId); var playerRoundScoresSum = playerRounds?.LastOrDefault()?.Score ?? 0; return(playerRoundScoresSum); }
public RoundDto CreateRound(RoundDto round) { var roundWithCalculatedScore = CalculateRoundScore(round); var createdRound = _roundRepository.CreateRound(roundWithCalculatedScore); return(createdRound); }
public async Task <bool> CreateNewRound(RoundDto value) { Round round = new Round(); round.RoundNumber = value.RoundNumber; round.StartDate = value.StartDate; round.EndDate = value.EndDate; await _content.Rounds.AddAsync(round); return(await _content.SaveChangesAsync() > 0); }
private int GetCurrentRoundScore(RoundDto round) { var roundScore = round.Rolls.Select(r => r.Score).Sum(); if (roundScore > PinsCount) { throw new ArgumentOutOfRangeException(); } return(roundScore); }
public async Task CreateAsync(RoundDto roundDto) { var round = new Round { Id = roundDto.Id, GameId = roundDto.GameId, Title = roundDto.Title, }; await _repositoryRound.CreateAsync(round); await _repositoryRound.SaveChangesAsync(); }
public async Task <List <RoundDto> > GetQuizRoundsByQuizIdAsync(long quizId) { var allRoundDtos = new List <RoundDto>(); var rounds = await _quizRepository.GetQuizRoundsByQuizIdAsync(quizId); foreach (var round in rounds) { var roundQuestions = await _quizRepository.GetAllRoundQuestionsAsync(round.Id); var roundDto = new RoundDto(round, roundQuestions); allRoundDtos.Add(roundDto); } return(allRoundDtos); }
public async Task <bool> CreateTeamScoresForRound(RoundDto round) { var users = await _content.Users.ToListAsync(); foreach (var user in users) { // Need to create the TeamScore for the Round TeamScore ts = new TeamScore(); ts.RoundId = round.RoundNumber; ts.Total = 0; ts.UserId = user.Id; await _content.TeamScores.AddAsync(ts); } return(await _content.SaveChangesAsync() > 0); }
public ActionResult <RoundDto> UpdateRound([FromRoute] int id, [FromBody] RoundDto roundDto) { try { var round = new RoundMapper().ToModel(roundDto); round.RoundId ??= id; var result = _unitOfWork.Rounds.Update(id, round); _unitOfWork.Save(); return(Ok(new RoundMapper().ToDto(result))); } catch (Exception e) { throw new HttpRequestException(e.Message, e, HttpStatusCode.InternalServerError); } }
private static RoundDto GetRoundDtoByScores(int firstRollScore, int secondRollScore) { var roundDto = new RoundDto { Rolls = new List <RollDto> { new RollDto { Number = 1, Score = firstRollScore }, new RollDto { Number = 2, Score = secondRollScore } } }; return(roundDto); }
public async Task <ActionResult <int> > Put(Guid id, [FromBody] RoundDto dto) { try { if (id != dto.Id) { return(BadRequest()); } int result = await service.UpdateAsync(dto); return(Ok(result)); } catch (ItemNotFoundException) { return(NotFound()); } }
public RoundDto CalculateRoundScore(RoundDto round) { var previousRoundsScoresSum = GetPreviousRoundScoresSum(round); var currentRoundRollsSum = GetCurrentRoundScore(round); var firstRollScore = round.Rolls.FirstOrDefault().Score; RoundTypeDto roundTypeDto = null; var isStrike = firstRollScore == PinsCount; if (isStrike) { round.Score = previousRoundsScoresSum + currentRoundRollsSum + 10; roundTypeDto = _roundRepository.GetRoundTypeByName("Strike"); } var isOpen = currentRoundRollsSum < PinsCount; if (isOpen) { round.Score = previousRoundsScoresSum + currentRoundRollsSum; roundTypeDto = _roundRepository.GetRoundTypeByName("Open"); } var isSpare = (currentRoundRollsSum == PinsCount && firstRollScore != PinsCount); if (isSpare) { round.Score = previousRoundsScoresSum + firstRollScore + 10; roundTypeDto = _roundRepository.GetRoundTypeByName("Spare"); } if (!isSpare && !isOpen & !isStrike) { throw new ArgumentOutOfRangeException(); } round.RoundTypeId = roundTypeDto?.Id; return(round); }
public ActionResult <RoundDto> CreateRound([FromBody] RoundDto roundDto) { try { if (roundDto is null) { return(BadRequest("Round can't be null")); } var round = new RoundMapper().ToModel(roundDto); var send = _unitOfWork.Rounds.Add(round); _unitOfWork.Save(); var dto = new RoundMapper().ToDto(send); return(CreatedAtAction(nameof(GetRoundById), new { id = dto.RoundId }, dto)); } catch (Exception e) { throw new HttpRequestException(e.Message, e, HttpStatusCode.InternalServerError); } }
public ICollection <RoundOtherPlayerDto> Resolve(Round source, RoundDto destination, ICollection <RoundOtherPlayerDto> destMember, ResolutionContext context) { var roundId = source.Id; var mainPlayerUserName = string.Empty; if (context.Options.Items.Count() > 0 && context.Options.Items.ContainsKey("MainRoundPlayer")) { var rp = context.Items["MainRoundPlayer"] as RoundPlayer; mainPlayerUserName = rp.GamePlayer.Player.UserName; var otherPlayers = source.RoundPlayers.Where(rp => rp.GamePlayer.Player.UserName != mainPlayerUserName); return(_mapper.Map <ICollection <RoundPlayer>, ICollection <RoundOtherPlayerDto> >(otherPlayers.ToList(), opt => opt.Items["MainRoundPlayer"] = rp)); } else { mainPlayerUserName = _userAccessor.GetCurrentUserName(); var otherPlayers = source.RoundPlayers.Where(rp => rp.GamePlayer.Player.UserName != mainPlayerUserName); return(_mapper.Map <ICollection <RoundPlayer>, ICollection <RoundOtherPlayerDto> >(otherPlayers.ToList())); } }
public async Task <IActionResult> Create(int id, GameContentViewModel model) { if (ModelState.IsValid) { var userId = await _accountManager.GetUserIdByNameAsync(User.Identity.Name); var gameId = await _gameManager.GetGameAsync(id, userId); var roundDto = new RoundDto { GameId = gameId.Id, Title = model.RoundTitle, }; await _roundManager.CreateAsync(roundDto); return(Redirect($"/game/gameContent/{id}")); } return(View(model)); }
public RoundDto CreateRound(RoundDto round) { RoundDto roundDto; using (var context = new BowlingScoreboardDbContextFactory().CreateDbContext()) { var roundEntity = _mapper.Map <Round>(round); context.Rounds.Add(roundEntity); context.SaveChanges(); roundDto = _mapper.Map <RoundDto>(roundEntity); roundDto.GameId = round.GameId; roundDto.PlayerId = round.PlayerId; } return(roundDto); }
public List <RoundDto> GerarRound(int quantiaDePerguntas = 0) { quantiaDePerguntas = quantiaDePerguntas == 0 ? 15 : quantiaDePerguntas; var rep = Repository.GetAll(); var idsPerguntas = CurrentSession.Session.CreateSQLQuery($"SELECT Id FROM PERGUNTA ORDER BY RAND() LIMIT {quantiaDePerguntas}").List <long>(); var listaPorExtenso = new List <string>(); foreach (var idsPergunta in idsPerguntas) { listaPorExtenso.Add(idsPergunta.ToString()); } var perguntas = CurrentSession.Session.CreateSQLQuery($"SELECT * FROM PERGUNTA WHERE Id in ({String.Join(",", listaPorExtenso)})").AddEntity(typeof(Pergunta)).List <Pergunta>(); var respostas = rep.Where(x => idsPerguntas.Contains(x.Pergunta.Id)); var respostasDto = new List <RespostaDto>(); var listaFinal = new List <RoundDto>(); foreach (var resposta in respostas) { respostasDto.Add(ObjectMapper.Map(resposta, new RespostaDto())); } foreach (var pergunta in perguntas) { var round = new RoundDto { Pergunta = ObjectMapper.Map(pergunta, new PerguntaDto()), Resposta = respostasDto.Where(x => x.Pergunta.Id == pergunta.Id).ToList() }; listaFinal.Add(round); } return(listaFinal.OrderBy(x => x.Pergunta.Dificuldade).ToList()); }
public RoundDto CreateRound(Guid gameId, Guid playerId, [FromBody] RoundDto round) { return(_roundService.CreateRound(round)); }
public async Task <IActionResult> CreateTeamScoresForRound(RoundDto round) { var result = await _repo.CreateTeamScoresForRound(round); return(Ok(result)); }
public async Task <RoundDto> CreateRoundAsync(RoundDto round) { return(await new HttpRequestService <RoundDto>().CreateAsync(round, BaseUrl, Api)); }
public async Task <RoundDto> UpdateRoundAsync(int id, RoundDto round) { return(await new HttpRequestService <RoundDto>().UpdateAsync(id, round, BaseUrl, Api)); }
private static Round FromDto(RoundDto r) { return(new Round(r.Subject, r.Estimations.Select(FromDto), r.StartedAt, r.FinishedAt, r.Consensus)); }