コード例 #1
0
        public TheBetEntity SaveBet(UserBetEntity userBet)
        {
            var betService = new TheBet.Services.BetService();
            var theBet     = betService.SaveBet(userBet);

            return(theBet);
        }
コード例 #2
0
 private void CheckUserBet(UserBetEntity bet, Guid userId)
 {
     if (bet.UserId != userId)
     {
         throw new CoreException(ErrorCode.Unknown, "Không được chỉnh sửa bet của người khác nha mài");
     }
 }
コード例 #3
0
        public Task UpdateTotalAmoutAll(Guid userId)
        {
            CheckIsAdmin(userId);
            var listUser  = _userRepository.Include(x => x.Amout, x => x.UserBets).Where(x => x.DeletedTime == null).ToList();
            var listMatch = _matchRepository.Include(x => x.PriceConfig).Where(x => x.DeletedTime == null && x.IsUpdated == 1).ToList();

            foreach (var match in listMatch)
            {
                foreach (var user in listUser)
                {
                    var a = 0;
                    if (DateTime.Compare(user.CreatedTime.DateTime, match.TimeMatch) > 0)
                    {
                        a = 1;
                    }
                    if (a != 1)
                    {
                        foreach (var userBet in user.UserBets)
                        {
                            if (userBet.MatchId == match.Id)
                            {
                                a = 1;
                                break;
                            }
                        }
                    }

                    if (a == 0)
                    {
                        var bet = new UserBetEntity()
                        {
                            UserId    = user.Id,
                            MatchId   = match.Id,
                            MoneyLost = match.PriceConfig.Price,
                            IsUpdated = 1
                        };
                        _betRepository.Add(bet);
                        _unitOfWork.SaveChanges();
                    }
                }
            }
            foreach (var user in listUser)
            {
                var amountEntity = _amoutRepository.Get(x => x.UserId == user.Id).Single();
                amountEntity.Total = 0;
                foreach (var bet in user.UserBets)
                {
                    amountEntity.Total += bet.MoneyLost;
                }
                _amoutRepository.Update(amountEntity, x => x.Total);
            }
            _unitOfWork.SaveChanges();
            return(Task.CompletedTask);
        }
コード例 #4
0
        public TheBetEntity SaveBet(UserBetEntity userBet)
        {
            try
            {
                var games         = gameRepository.GetAllGames();
                var gamesToSubmit = userBet.games.Where(x => x.OpenForBet && x.UserTeam1Goals != null && x.UserTeam2Goals != null).ToList();
                if ((gamesToSubmit == null || gamesToSubmit.Count == 0))
                {
                    return(new TheBetEntity()
                    {
                        ErrorMsg = "Error in BetService Save the BEt, NO USER INPUT TO SAVE"
                    });
                }
                else if (userBet.user == null || userBet.user.Id <= 0)
                {
                    return(new TheBetEntity()
                    {
                        ErrorMsg = "Error in BetService Save the BEt, MISSING USER ID"
                    });
                }

                foreach (var game in gamesToSubmit)
                {
                    foreach (var gameToCheck in games)
                    {
                        if (game.GameId == gameToCheck.Id)
                        {
                            if (!gameToCheck.OpenForBet)
                            {
                                return(new TheBetEntity()
                                {
                                    ErrorMsg = "Error in BetService Save the BEt, A GAME NOT OPEN FOR BET HAVE BEEN SUBMITTED. GameID = " + gameToCheck.Id
                                });
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }

                return(userRepository.SaveUserBet(gamesToSubmit, userBet.user.Id));
            }
            catch (Exception ex)
            {
                return(new TheBetEntity()
                {
                    Exception = ex.InnerException.Message, ErrorMsg = "Error in BetService Save the BEt"
                });
            }
        }
コード例 #5
0
        public Task <Guid> Create(UserBetModel model, Guid userId, CancellationToken cancellationToken = default)
        {
            CheckMatchExist(model.MatchId);
            CheckUserExist(userId);
            CheckBet(model.MatchId, userId);
            var match = _matchRepository.Get(x => x.Id == model.MatchId).Single();

            CheckTimeEditBet(match.TimeMatch);
            var betEntity = new UserBetEntity()
            {
                MatchId   = model.MatchId,
                UserId    = userId,
                TeamWinId = model.TeamWinId,
                TimeBet   = SystemHelper.GetNetworkTime()
            };

            _betRepository.Add(betEntity);
            _unitOfWork.SaveChanges();
            return(Task.FromResult(betEntity.Id));
        }
コード例 #6
0
        public void UpdateScoreTeamMatch(Guid userId, Guid matchId, UpdateTeamMatch model)
        {
            CheckExist(matchId);
            CheckIsAdmin(userId);

            var match = _matchRepository.Include(x => x.MatchTeams, x => x.PriceConfig).Single(x => x.Id == matchId);

            CheckTimeUpdateScore(match.TimeMatch);

            var firstTeam  = match.MatchTeams.First();
            var secondTeam = match.MatchTeams.Skip(1).First();

            firstTeam.Rate   = model.FirstTeamRate;
            firstTeam.Goals  = model.FirstTeamGoal;
            secondTeam.Goals = model.SecondTeamGoal;
            secondTeam.Rate  = model.SecondTeamRate;
            _matchTeamRepository.Update(firstTeam, x => x.Goals, x => x.Rate);
            _matchTeamRepository.Update(secondTeam, x => x.Goals, x => x.Rate);

            var checkWin = Guid.NewGuid();

            var temp = Guid.NewGuid();

            var check = ((firstTeam.Goals + firstTeam.Rate) - (secondTeam.Goals + secondTeam.Rate));

            if (check > 0)
            {
                checkWin = firstTeam.TeamId;
            }
            else
            {
                if (check < 0)
                {
                    checkWin = secondTeam.TeamId;
                }
                else
                {
                    checkWin = temp;
                }
            }

            var listUser = _userRepository.Include(x => x.Amout, x => x.UserBets).Where(x => x.DeletedTime == null).ToList();

            foreach (var user in listUser)
            {
                var a = 0;
                if (DateTime.Compare(user.CreatedTime.DateTime, match.TimeMatch) > 0)
                {
                    a = 1;
                }

                if (a != 1)
                {
                    foreach (var userBet in user.UserBets)
                    {
                        if (userBet.MatchId == match.Id)
                        {
                            var amount = _amoutRepository.Get(x => x.UserId == userBet.UserId).Single();
                            userBet.MoneyLost = 0;
                            amount.Total     -= userBet.MoneyLostLast;
                            if (userBet.TeamWinId == checkWin)
                            {
                                userBet.MoneyLost     = 0;
                                userBet.MoneyLostLast = 0;
                                _betRepository.Update(userBet, x => x.MoneyLost, x => x.MoneyLostLast);
                            }
                            else
                            {
                                if (userBet.TeamWinId != Guid.Empty && checkWin == temp)
                                {
                                    userBet.MoneyLost     = match.PriceConfig.Price * 50 / 100;
                                    userBet.MoneyLostLast = match.PriceConfig.Price * 50 / 100;
                                    _betRepository.Update(userBet, x => x.MoneyLost, x => x.MoneyLostLast);
                                }
                                else
                                {
                                    userBet.MoneyLost     = match.PriceConfig.Price;
                                    userBet.MoneyLostLast = match.PriceConfig.Price;
                                    _betRepository.Update(userBet, x => x.MoneyLost, x => x.MoneyLostLast);
                                }
                            }
                            amount.Total += userBet.MoneyLost;
                            _amoutRepository.Update(amount, x => x.Total);
                            a = 1;
                            break;
                        }
                    }
                }

                if (a == 0)
                {
                    var betEntity = new UserBetEntity()
                    {
                        UserId        = user.Id,
                        MatchId       = match.Id,
                        MoneyLost     = match.PriceConfig.Price,
                        MoneyLostLast = match.PriceConfig.Price,
                        IsUpdated     = 1
                    };
                    var amount = _amoutRepository.Get(x => x.UserId == user.Id).Single();
                    amount.Total += match.PriceConfig.Price;
                    _amoutRepository.Update(amount, x => x.Total);
                    _betRepository.Add(betEntity);
                    _unitOfWork.SaveChanges();
                }
            }
            match.IsUpdated = 1;
            _matchRepository.Update(match, x => x.IsUpdated);
            _unitOfWork.SaveChanges();
            //    UpdateTotalAmoutAll(userId);
        }