private List <BetDTO> GetEventOdds(ICollection <SportBet> collection) { List <BetDTO> bets = new List <BetDTO>(); foreach (var bet in collection) { BetDTO betAvailable = new BetDTO(); betAvailable.ID = bet.ID; betAvailable.OddType = bet.Code; List <OddDTO> oddCollection = new List <OddDTO>(); foreach (var oddType in bet.OddProvider.GetAvailables()) { OddDTO singleOdd = new OddDTO(); singleOdd.ID = string.Format("{0}_{1}", bet.ID, oddType.Key); singleOdd.Code = oddType.Key; singleOdd.Price = bet.GetOddPrice(oddType.Key); oddCollection.Add(singleOdd); } betAvailable.OddCollection = oddCollection; bets.Add(betAvailable); } return(bets); }
public void PlaceBetTest() { StubUnitOfWork uow = new StubUnitOfWork(); BargainingService service = new BargainingService(uow); Category category = uow.Categories.GetAll().FirstOrDefault(); Lot lot = new Lot() { Id = uow.Lots.GetAll().Count() + 1, Name = "Test Bargaining", StartPrice = 322, CurrPrice = 322, BuyNowPrice = 1337, IsAllowed = true, IsOpen = true, CategoryId = category.Id, Category = category, Description = "zxc" }; uow.Lots.Create(lot); BetDTO bet = new BetDTO() { LotId = lot.Id, Price = uow.Lots.Get(lot.Id).CurrPrice + 100 }; service.PlaceBet(bet); Lot tempLot = uow.Lots.Get(lot.Id); Assert.AreEqual(tempLot.CurrPrice, bet.Price); }
public BetResultDTO GameRoundBet(BetDTO bet, string username) { BetResultDTO result = new BetResultDTO(); PersonDTO person = _personService.GetPersonByEmail(username); if (person != null && bet.Bet <= person.Points) { Random rd = new Random(); int randomNumber = rd.Next(0, 9); if (randomNumber == bet.Number) { int winnerPoints = bet.Bet * 9; person.Points += winnerPoints; result.PointsWon = winnerPoints; result.Status = "Won"; } else { person.Points -= bet.Bet; result.PointsWon = -bet.Bet; result.Status = "Lost"; } result.CurrentPoints = person.Points; result.Username = username; result.Bet = bet.Bet; result.RandomResult = randomNumber; createGameRound(person, result); _personService.Update(person); } return(result); }
public ActionResult <BetResultDTO> GuessNumber(BetDTO bet) { if (ModelState.IsValid) { if (bet.Number >= 1 && bet.Number <= 9) { var claims = User.Claims.ToList(); string username = claims.FirstOrDefault(x => x.Type == "Username").Value; BetResultDTO betresult = _gameRoundService.GameRoundBet(bet, username); if (betresult == null) { return(BadRequest("Wrong bet parameters")); } return(betresult); } else { return(BadRequest("Insert a valid number between 1 and 9")); } } else { return(BadRequest("Invalid model")); } }
public void PlaceBetTestException2() { StubUnitOfWork uow = new StubUnitOfWork(); BargainingService service = new BargainingService(uow); Category category = uow.Categories.GetAll().FirstOrDefault(); Lot lot = new Lot() { Id = uow.Lots.GetAll().Count() + 1, Name = "Test Bargaining", StartPrice = 322, CurrPrice = 322, BuyNowPrice = 1337, IsAllowed = false, IsOpen = true, CategoryId = category.Id, Category = category, Description = "zxc" }; uow.Lots.Create(lot); BetDTO bet = new BetDTO() { LotId = lot.Id, Price = uow.Lots.Get(lot.Id).CurrPrice + 10 }; Assert.ThrowsException <ValidationException>(() => service.PlaceBet(bet)); }
public void PlaceBet(BetDTO bet) { using (Database) { Lot lot = Database.Lots.Get(bet.LotId); if (lot == null) { throw new ItemNotFoundException($"Item {bet.LotId} not found"); } if (lot.IsAllowed && lot.IsOpen) { if (lot.CurrPrice < bet.Price) { lot.CurrPrice = bet.Price; Database.Lots.Update(lot); Database.Save(); } else { throw new BargainingException("Ставка не может быть ниже текущей цены лота..."); } } else { throw new ValidationException("Лот закрыт или неподтвержден..."); } } }
public async Task <ResultGameDTO> GetRoulettesAsync([FromBody] BetDTO betRoulette) { var headers = Headers.GetUserByTokenHeader(this.Request); if (headers.IsError) { return(headers); } betRoulette.UserId = (int)headers.ResultObject; return(await iBetRouletteBll.CreateBetAsync(betRoulette)); }
public async Task <IActionResult> CreateBet([FromBody] BetDTO betDto) { if (Request.Headers.TryGetValue("idUser", out var headerValue)) { betDto.User = headerValue.ToString(); return(Ok(await bet.CreateBet(betDto))); } else { return(Ok("No se encontró el ID del Usuario")); } }
private ResultGameDTO ValidationMoneyCap(BetDTO betRoulette) { ResultGameDTO Result = new ResultGameDTO(); if (betRoulette.BetMoney > Constant.MaximumBet) { Result.IsError = true; Result.Message = Messages.ErrorMaximumBet; } return(Result); }
private BetRoulette SetBet(BetDTO betRoulette) { BetRoulette resultRoulette = new BetRoulette(); resultRoulette.BetMoney = betRoulette.BetMoney; resultRoulette.UserId = betRoulette.UserId; resultRoulette.BetFor = betRoulette.BetFor; resultRoulette.IsGame = true; resultRoulette.StartRouletteId = (int)UserGameInformation.StartRouletteId; return(resultRoulette); }
public String PlaceBet(BetDTO bet) { try { BetService.PlaceBet(bet); return("Success"); } catch (Exception ex) { return("ERROR: " + ex.Message); } }
private ResultGameDTO ValidBetValues(BetDTO betRoulette) { ResultGameDTO Result = new ResultGameDTO(); CreateValues(); if (!ValuesInGame.Contains(betRoulette.BetFor.ToLower())) { Result.IsError = true; Result.Message = Messages.ErrorInValuesBet; } return(Result); }
public IActionResult RegisterBet(BetDTO betDTO) { try { int BetId = 0; var oBet = _mapper.Map <Bet>(betDTO); BetId = _betRepository.RegisterBet(oBet); return(Ok(BetId)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public void PlaceBetTestException1() { StubUnitOfWork uow = new StubUnitOfWork(); BargainingService service = new BargainingService(uow); int lotId = uow.Lots.GetAll().Count() + 1; BetDTO bet = new BetDTO() { LotId = lotId, Price = 100 }; Assert.ThrowsException <ItemNotFoundException>(() => service.PlaceBet(bet)); }
// todo refractor into smaller functions public async Task AddBetAsync(BetDTO betDTO) { if (betDTO == null) { return; } var bet = mapper.Map <Bet>(betDTO); bet.DateOfBetting = DateTime.UtcNow; var user = await this._userRepository.GetUserWithoutBetsAsync(bet.UserId); if (user == null) { throw new Exception("No userDTO with given Id"); } user.Points = user.Points - (bet.BetOnTeamA + bet.BetOnTeamB); if (user.Points < 0) { throw new Exception("You don't have enough points!"); } var match = await this._matchRepository.GetMatchAsync(bet.MatchId); if (match == null) { throw new Exception($"Match with given id {bet.MatchId} not found"); } if (match.MatchTime.CompareTo(DateTime.UtcNow) <= 0) { match.Status = MatchStatus.OnGoing; await this._matchRepository.UpdateMatchAsync(match); throw new Exception("Match already started."); } match.TeamAPoints += bet.BetOnTeamA; match.TeamBPoints += bet.BetOnTeamB; await _matchRepository.UpdateMatchAsync(match); await _userRepository.UpdateUserAsync(user); await _betRepository.AddBetAsync(bet); }
public async Task <IActionResult> Add([FromBody] BetDTO bet) { try { await _betService.AddBetAsync(bet); Log.Info( $"Bet placed, user: {bet.UserId}, bet on team A:{bet.BetOnTeamA}, bet on team B:{bet.BetOnTeamB}"); return(Ok()); } catch (Exception ex) { Log.Error($"{bet.UserId} - {ex.Message}"); return(BadRequest(ex.Message)); } }
public async Task <StartBetDTO> ValidBetByUserIdAsync(BetDTO betUser) { StartBetDTO startBet = new StartBetDTO(); using (SqlConnection connection = new SqlConnection(BaseContext.GetParameterConnection())) { await connection.OpenAsync(); string sql = string.Format(Querys.QueryValidBetByUserId, betUser.UserId, betUser.UserId, betUser.RouletteId); SqlCommand command = new SqlCommand(sql, connection); using (SqlDataReader dataReader = await command.ExecuteReaderAsync()) { startBet = await SetDataValidBetByUserId(dataReader); } await connection.CloseAsync(); } return(startBet); }
private async Task <ResultGameDTO> Validations(BetDTO betRoulette) { ResultGameDTO resultBet = new ResultGameDTO(); var ValidateDataBet = await ValidBetByUserIdAsync(betRoulette); if (ValidateDataBet.IsError) { return(ValidateDataBet); } var ValidateValueInBet = ValidBetValues(betRoulette); if (ValidateValueInBet.IsError) { return(ValidateValueInBet); } return(resultBet); }
public async Task <string> CreateBet(BetDTO betDTO) { string response = ""; if (ValidateRoulette(betDTO.IdRoulette)) { IDatabase db = connectionMultiplexer.GetDatabase(); RedisKey key = new RedisKey(nameTable); IList <BetDTO> bets = ListBets() ?? new List <BetDTO>(); bets.Add(betDTO); await db.StringSetAsync(key, JsonConvert.SerializeObject(bets)); response = "OK"; } else { response = "El ID de la apuesta no existe o la ruleta se encuentra cerrada."; } return(response); }
public async Task <ResultGameDTO> ValidBetByUserIdAsync(BetDTO betUser) { ResultGameDTO result = new ResultGameDTO(); UserGameInformation = await this.iBetRouletteDAL.ValidBetByUserIdAsync(betUser); if (UserGameInformation.RouletteId == 0 || UserGameInformation.RouletteId == null) { result.IsError = true; result.Message = Messages.ErrorClosedRoulettes; return(result); } if (UserGameInformation.UserMoney < betUser.BetMoney) { result.IsError = true; result.Message = Messages.ErrorInsufficientBalance; return(result); } return(result); }
public async Task <ResultGameDTO> CreateBetAsync(BetDTO betRoulette) { ResultGameDTO result = new ResultGameDTO(); var valitationsCap = ValidationMoneyCap(betRoulette); if (valitationsCap.IsError) { return(valitationsCap); } var resultValidations = await Validations(betRoulette); if (resultValidations.IsError) { return(resultValidations); } await iBetRouletteDAL.CreateBetAsync(SetBet(betRoulette)); result.Message = Messages.SuccessfulBet; return(result); }
public async Task <ActionResult <Roulette> > AddBetToRoulette(long id, BetDTO bet) { var roulette = await _context.Roulettes.FindAsync(id); if (roulette == null) { return(NotFound()); } else { Bet newBet = new Bet(bet.Token, bet.Value); if (roulette.AddBet(newBet)) { _context.Update(roulette); await _context.SaveChangesAsync(); return(Ok(new { Status = "Added", bets = roulette.Bets.Count })); } else { return(Conflict(new { status = "Roulette closed" })); } } }
static System.Collections.Generic.List <BetDTO> ConvertData(string data, System.Collections.Generic.Dictionary <string, System.DateTime> oldBetList, string accountName) { System.Collections.Generic.List <BetDTO> list = null; if (data != string.Empty) { if (!data.Contains("No information is available")) { list = new List <BetDTO>(); HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(data); foreach (HtmlNode table in doc.DocumentNode.SelectNodes("//table/tr/td/table")) { foreach (HtmlNode row in table.SelectNodes("tr")) { //iBet.Utilities.WriteLog.Write("------------Bet-------------"); HtmlNodeCollection cells = row.SelectNodes("td"); string refID = cells[1].InnerText.Substring(8, 10); if (row.InnerText.Contains("Soccer")) { //string stringEntry = cells[2].FirstChild.FirstChild.FirstChild.InnerText; string stringEntry = cells[2].FirstChild.FirstChild.NextSibling.InnerText; if (!stringEntry.Contains("Mix Parlay")) { BetDTO betDTO = new BetDTO(); betDTO.Account = accountName; betDTO.RefID = refID; betDTO.DateTime = DateTime.Parse(cells[1].FirstChild.NextSibling.InnerText); string string1 = string.Empty, string2 = string.Empty, string3 = string.Empty, string4 = string.Empty; string[] array1 = null, array2 = null; try { if (stringEntry != string.Empty && !stringEntry.Contains("FT.") && !stringEntry.Contains("HT.")) { betDTO.Dumb = false; //betDTO.Choice = cells[2].FirstChild.FirstChild.FirstChild.FirstChild.InnerText; betDTO.Choice = cells[2].FirstChild.FirstChild.NextSibling.FirstChild.InnerText.Trim(); betDTO.Odd = cells[2].FirstChild.FirstChild.NextSibling.FirstChild.NextSibling.InnerText.Trim(); //if (cells[2].FirstChild.FirstChild.FirstChild.FirstChild.NextSibling.LastChild.InnerHtml.Contains("[")) //string1 = cells[2].FirstChild.FirstChild.FirstChild.FirstChild.NextSibling.NextSibling.NextSibling.InnerText.Trim().Replace("[", "").Replace("]", ""); if (stringEntry.Contains("[")) { array1 = stringEntry.Split(new string[] { "[" }, System.StringSplitOptions.None); array2 = array1[1].Split(new string[] { "]" }, System.StringSplitOptions.None); string1 = array2[0]; } //string1 = cells[2].FirstChild.FirstChild.FirstChild.FirstChild.NextSibling.NextSibling.NextSibling.InnerText.Trim().Replace("[", "").Replace("]", ""); string2 = cells[2].FirstChild.FirstChild.NextSibling.InnerText; string3 = cells[2].FirstChild.FirstChild.NextSibling.NextSibling.NextSibling.InnerText; string4 = cells[2].FirstChild.FirstChild.NextSibling.NextSibling.InnerText; betDTO.League = cells[2].FirstChild.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.InnerText; } else { string stringEntry2 = cells[2].FirstChild.FirstChild.FirstChild.NextSibling.FirstChild.InnerText; bool _htChoice = stringEntry2.Contains("HT."); bool _ftChoice = stringEntry2.Contains("FT."); if (_htChoice || _ftChoice) { betDTO.Dumb = false; betDTO.Choice = stringEntry2.Replace(" ", ""); betDTO.Odd = "12"; try { string1 = cells[2].FirstChild.FirstChild.FirstChild.NextSibling.FirstChild.NextSibling.InnerText.Replace("[", "").Replace("]", ""); } catch { string1 = string.Empty; } string2 = cells[2].FirstChild.FirstChild.NextSibling.NextSibling.FirstChild.InnerText; string3 = cells[2].FirstChild.FirstChild.NextSibling.NextSibling.NextSibling.FirstChild.InnerText; string4 = cells[2].FirstChild.FirstChild.NextSibling.NextSibling.InnerText; betDTO.League = cells[2].FirstChild.FirstChild.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.FirstChild.NextSibling.InnerText; } else { betDTO.Dumb = false; betDTO.Choice = stringEntry2; betDTO.Odd = cells[2].FirstChild.FirstChild.NextSibling.FirstChild.NextSibling.InnerText; if (cells[2].FirstChild.FirstChild.NextSibling.LastChild.InnerHtml.Contains("[")) { string1 = cells[2].FirstChild.FirstChild.FirstChild.NextSibling.FirstChild.NextSibling.NextSibling.NextSibling.InnerText.Trim().Replace("[", "").Replace("]", ""); } string2 = cells[2].FirstChild.FirstChild.NextSibling.NextSibling.FirstChild.InnerText; string3 = cells[2].FirstChild.FirstChild.NextSibling.NextSibling.NextSibling.FirstChild.InnerText; string4 = cells[2].FirstChild.FirstChild.NextSibling.NextSibling.InnerText; betDTO.League = cells[2].FirstChild.FirstChild.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.FirstChild.NextSibling.InnerText.Replace(" ", ""); } } // if (betDTO.Dumb != true) { if (string1 != string.Empty) { betDTO.Score = string1; array1 = string1.Split(new string[] { "-" }, System.StringSplitOptions.None); betDTO.HomeScore = array1[0]; betDTO.AwayScore = array1[1]; betDTO.Live = true; } else { betDTO.Score = "?-?"; betDTO.HomeScore = "0"; betDTO.AwayScore = "0"; betDTO.Live = false; } if (string3.Contains("nbsp")) { array2 = string3.Split(new string[] { " - vs - " }, System.StringSplitOptions.None); betDTO.HomeTeamName = array2[0]; betDTO.AwayTeamName = array2[1].TrimEnd(' '); } else { //iBet.Utilities.WriteLog.Write("Can not parse name of match: " + string3); } if (string4 != string.Empty) { if (string4.Contains("1st Handicap")) { betDTO.Type = eOddType.FirstHalfHandicap; } else if (string4.Contains("1st Over")) { betDTO.Type = eOddType.FirstHalfOverUnder; } else if (string4.Contains("Handicap")) { betDTO.Type = eOddType.FulltimeHandicap; } else if (string4.Contains("Over")) { betDTO.Type = eOddType.FulltimeOverUnder; } else if (string4.Contains("FT.1X2")) { betDTO.Type = eOddType.FT; } else if (string4.Contains("1st 1X2")) { betDTO.Type = eOddType.HT; } else { betDTO.Type = eOddType.Unknown; } } betDTO.OddValue = cells[3].FirstChild.InnerText; betDTO.Stake = int.Parse(cells[4].InnerText.Replace(",", "")); //if (cells[5].FirstChild.InnerText.StartsWith("Run")) // betDTO.Status = true; //else // betDTO.Status = false; //betDTO.IP = cells[5].FirstChild.NextSibling.InnerText; } // } catch (Exception ex) { betDTO.Dumb = true; //iBet.Utilities.WriteLog.Write("----bet convert Dumb----"); //iBet.Utilities.WriteLog.Write("Meassge: " + ex); //iBet.Utilities.WriteLog.Write(row.InnerHtml); //iBet.Utilities.WriteLog.Write("----end----"); } if (betDTO.Dumb == false) { list.Add(betDTO); } } } } } } } return(list); }
public IEnumerable <UserDTO> Get(BetDTO bet) { return(_userService.GetByBet(bet)); }
public static void PlaceBet(BetDTO dto) { var fullEvent = EventService.GetFullEvent(dto.EventID); if (dto.isParlay) { // get odds var fighterNames = dto.Wagers.Select(x => x.FighterName).ToList(); var allOdds = fullEvent.BetLines .Where(x => fighterNames.Contains(x.FighterName)) .Select(x => x.Odds) .ToList(); var parlayOdds = CalculateParlayOdds(allOdds); var individualBets = dto.Wagers .Select(x => { return(new SingleBet { FighterName = x.FighterName, Stake = x.Stake, Result = Result.TBD, Odds = 0 }); }).ToList(); var bet = new Bet { EventID = dto.EventID, SeasonID = dto.SeasonID, TimePlaced = DateTime.Now, PlayerName = dto.PlayerName, Result = Result.TBD, Stake = dto.ParlayStake, Odds = parlayOdds, IndividualBets = individualBets }; var bets = new List <Bet> { bet }; PlaceBets(bets); } else // bet is not parlay, it is many separate single bets { var bets = new List <Bet>(); foreach (var wager in dto.Wagers) { var line = fullEvent.BetLines .FirstOrDefault(x => x.FighterName == wager.FighterName); if (line == null) { throw new Exception("error getting odds for " + wager.FighterName); } var odds = line.Odds; bets.Add(new Bet { EventID = dto.EventID, SeasonID = dto.SeasonID, PlayerName = dto.PlayerName, TimePlaced = DateTime.Now, Stake = wager.Stake, Result = Result.TBD, Odds = odds, IndividualBets = new List <SingleBet> { new SingleBet { FighterName = wager.FighterName, Odds = odds, Stake = wager.Stake, Result = Result.TBD } } }); } PlaceBets(bets); } }
public async Task <string> CreateBet(BetDTO betDTO) { betDTO.Id = Guid.NewGuid().ToString(); return(await dBRedis.CreateBet(betDTO)); }
public BetDTO Get(int id) { BetDTO bet = ibs.GetById(id); return(bet); }
public void Post([FromBody] BetDTO value) { ibs.Create(value); }
public void Put(int id, [FromBody] BetDTO value) { }
public void Delete(int id) { BetDTO bet = ibs.GetById(id); ibs.Delete(bet); }