Exemple #1
0
        public void GenerateRound()
        {
            var roundNumbers = new List <int>();
            var rnd          = new Random();

            var i = 0;

            while (i < 7)
            {
                var check = rnd.Next(1, 37);
                if (!roundNumbers.Contains(check))
                {
                    roundNumbers.Add(check);
                    i++;
                }
            }

            var numbers = string.Join(";", roundNumbers.OrderBy(x => x));

            var model = _roundRepository.GetAll().FirstOrDefault(r => string.IsNullOrEmpty(r.WinningComination));

            model.WinningComination = numbers;
            model.DateResults       = DateTime.Now;
            model.PayIn             = CalculateProfit(model.Id);
            model.PayOut            = CalculateLoss(model.Id);

            _roundRepository.Update(model);

            _roundRepository.Create(new Round
            {
                CreatedRound = DateTime.Now
            });
        }
Exemple #2
0
        public ActionResult Update(Round round)
        {
            ApiResult <Round> apiResult;

            if (ModelState.IsValid)
            {
                if (round.Id > 0)
                {
                    apiResult = TryExecute(() =>
                    {
                        _roundRepository.Update(round);
                        _unitOfWork.Commit();
                        return(round);
                    }, "Interview Round updated sucessfully");
                }
                else
                {
                    apiResult = TryExecute(() =>
                    {
                        _roundRepository.Create(round);
                        _unitOfWork.Commit();
                        return(round);
                    }, "Interview Round created sucessfully");
                }
            }
            else
            {
                apiResult = ApiResultFromModelErrors <Round>();
            }

            return(Json(apiResult, JsonRequestBehavior.AllowGet));
        }
        public IHttpActionResult Put([FromBody] Round round)
        {
            if (ModelState.IsValid)
            {
                round = roundRepository.Update(round);
            }

            return(Json(round));
        }
Exemple #4
0
 public ActionResult Edit(Round round)
 {
     if (ModelState.IsValid)
     {
         _roundRepository.Update(round);
         _unitOfWork.Commit();
         return(RedirectToAction("Index"));
     }
     return(View(round));
 }
Exemple #5
0
        public async Task <ResponseFindWinnerGameView> FindWinner(RequestFindWinnerGameView item)
        {
            int    score  = 21;
            Player player = await _playerRepository.Get(item.PlayerHand.PlayerId);

            Player dealer = await _playerRepository.Get(item.DealerHand.PlayerId);

            PlayerRoundHand playerHand = await _playerRoundHandRepository.Get(item.PlayerHand.Id);

            PlayerRoundHand dealerHand = await _playerRoundHandRepository.Get(item.DealerHand.Id);

            Round round = await _roundRepository.Get(playerHand.RoundId);

            if (playerHand.Score > score && dealerHand.Score <= score)
            {
                round.Winner      = dealer.Name;
                round.WinnerScore = dealerHand.Score;
            }
            if (dealerHand.Score <= score && dealerHand.Score > playerHand.Score)
            {
                round.Winner      = dealer.Name;
                round.WinnerScore = dealerHand.Score;
            }
            if (dealerHand.Score > score && playerHand.Score > score)
            {
                round.Winner      = "Draw";
                round.WinnerScore = 0;
            }
            if (dealerHand.Score == playerHand.Score)
            {
                round.Winner      = "Draw";
                round.WinnerScore = 0;
            }
            if (dealerHand.Score > score && playerHand.Score <= score)
            {
                round.Winner      = player.Name;
                round.WinnerScore = playerHand.Score;
            }
            if (playerHand.Score <= score && playerHand.Score > dealerHand.Score)
            {
                round.Winner      = player.Name;
                round.WinnerScore = playerHand.Score;
            }
            await _roundRepository.Update(round);

            var result = new ResponseFindWinnerGameView();

            result.Round = _maping.MapRoundToRoundFindWinnerGameViewItem(round);
            return(result);
        }
Exemple #6
0
        public void SaveRound(int gameId, List <bool> flags)
        {
            var roundPlayers = GetRoundPlayers(gameId).ToList();

            for (int i = 0; i < roundPlayers.Count - 1; i++)
            {
                roundPlayers[i].IsWin = flags[i];
                _roundPlayerRepository.Update(roundPlayers[i]);
            }
            int   roundId = GetCurrentRoundId(gameId);
            Round round   = _roundRepository.Get(roundId);

            round.IsCompleted = true;
            _roundRepository.Update(round);
        }
        public bool AnswerRound(int answerImageId, int userId)
        {
            GameEntity currentGameForPlayer = _gameRepository.GetLatestGameForUser(userId);

            // id should be replaced with start date
            RoundEntity currentRound = _roundRepository.GetCurrentOpenRound(currentGameForPlayer.Id);

            ImageEntity answerImage = _imageRepository.Get(answerImageId);

            currentRound.GuessedImageId   = answerImage.Id;
            currentGameForPlayer.Duration = DateTime.Now - currentGameForPlayer.StartDate;

            _gameRepository.Update(currentGameForPlayer);
            _roundRepository.Update(currentRound);

            return(currentRound.GuessedImageId == currentRound.CorrectImageId);
        }
Exemple #8
0
        public void CreateTicket(CreateTicketViewModel ticketViewModel, int userId)
        {
            ValidateNumbers(ticketViewModel.Combination);

            var combination = string.Join(";", ticketViewModel.Combination.Split(';').Select(c => int.Parse(c)).OrderBy(x => x));

            var round = _roundRepository.GetAll().FirstOrDefault(r => string.IsNullOrEmpty(r.WinningComination));

            if (round == null)
            {
                throw new Exception("No Active round!");
            }

            round.PayIn = round.PayIn == null ? round.PayIn = 0 + 50 : round.PayIn += 50;

            _roundRepository.Update(round);

            var user = _userRepository.GetById(userId);

            if (user == null)
            {
                throw new Exception("There is no User with that Id");
            }

            user.Balance -= 50;
            if (user.Balance < 0)
            {
                throw new Exception("You don't have money for the Ticket");
            }

            _userRepository.Update(user);

            var model = new Ticket
            {
                Combination = combination,
                UserId      = userId,
                Status      = Status.Pending,
                DateCreated = DateTime.Now,
                Round       = round.Id
            };

            _ticketRepository.Create(model);
        }
Exemple #9
0
        public async Task UpdateAsync(Guid id, Round round)
        {
            var existingRound = await _roundRepository.GetByIdAsync(id);

            if (existingRound == null)
            {
                AddNotification("Rodada não encontrada.");
            }

            existingRound.Update(round.Description, round.Date, round.RankingId);
            if (await ValidateRoundAsync(existingRound))
            {
                _roundRepository.Update(existingRound);

                if (!await CommitAsync())
                {
                    AddNotification("Não foi possível atualizar a rodada.");
                }
            }
        }
        public Round Update(Round roundUpdated)
        {
            var validatedRound = _roundVali.ValidateRound(roundUpdated);

            return(_roundRepo.Update(validatedRound));
        }