public async Task <ActionResult <Bet> > CreateBetByRoulette(int idRoulette, Bet item) { item.IdRoulette = idRoulette; if (item.StakeValue > 10000) { return(BadRequest("La apuesta debe ser menor a 10000 dólares.")); } if (item.BetType == "Color") { if (!item.PlayedValue.Contains("Red") || !item.PlayedValue.Contains("Black")) { return(BadRequest("Los colores apostados solo pueden ser Rojo o Negro")); } } if (item.BetType == "Number") { Int16 BetValue; if (Int16.TryParse(item.PlayedValue, out BetValue)) { if (BetValue > 36 || BetValue < 0) { return(BadRequest("La apuesta solo es de 0 a 36")); } } else { return(BadRequest("La apuesta no es numérica")); } } _context.BetItems.Add(item); await _context.SaveChangesAsync(); return(item); }
public async Task <IEnumerable <Bet> > CloseRoulette(int idRoulette) { Roulette roulette = await _context.Roulette.FindAsync(idRoulette); var bet = _context.Bet.Where(b => b.IdRoulette == idRoulette); if (roulette == null) { throw new BadRequestException("Ruleta no existe."); } else if (roulette.State == true) { roulette.State = false; roulette.EndDate = DateTime.UtcNow; } try { await _context.SaveChangesAsync(); } catch (Exception ex) { throw new BadRequestException("Error al cerrar la apuesta"); } return(bet.Select(b => new Bet { IdBet = b.IdBet, IdRoulette = b.IdRoulette, IdUser = b.IdUser, Money = b.Money, Position = b.Position, Color = b.Color })); }
[HttpPut("{id}")] // PUT: api/Roulettes public async Task <IActionResult> PutRoulette(long id, Roulette roulette) { if (id != roulette.Id) { return(BadRequest()); } _context.Entry(roulette).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RouletteExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Roulette> > PostRoulette() { var roulette = new Roulette(); _context.Roulettes.Add(roulette); await _context.SaveChangesAsync(); return(CreatedAtAction("GetRoulette", new { id = roulette.Id }, new { rouletteId = roulette.Id })); }
public async Task <ActionResult <int> > CreateRoulette() { Roulette item = new Roulette(); item.CreationDate = DateTime.Now; item.State = "Created"; _context.RouletteItems.Add(item); await _context.SaveChangesAsync(); return(item.Id); }
/// <summary> /// Create Roulete /// </summary> /// <returns>Data of roulette created</returns> public async Task <RouletteModel> PostRouletteModel() { RouletteModel rouletteModel = new RouletteModel { Id = Guid.NewGuid(), RouletteOpen = false, Open = null, Close = null }; _context.Roulettes.Add(rouletteModel); await _context.SaveChangesAsync(); return(rouletteModel); }
public async Task <Bet> CreateBet(Bet bet, string idUser) { var roulette = await _context.Roulette.FindAsync(bet.IdRoulette); if (roulette == null) { throw new BadRequestException("Ruleta no existe."); } Bet betplay = new Bet() { IdRoulette = bet.IdRoulette, IdUser = idUser, Money = bet.Money, Position = bet.Position, Color = bet.Color }; validation(betplay); _context.Bet.Add(betplay); try { await _context.SaveChangesAsync(); } catch (Exception) { throw new BadRequestException("Error al registrar la apuesta"); } return(betplay); }
public async Task <Roulette> CreateRoulette() { try { Roulette roulette = new Roulette(); roulette.StateRoulette = EnumerationStateRoulette.StateRoulette.Cerrado.ToString(); _rouletteContext.Roulette.Add(roulette); await _rouletteContext.SaveChangesAsync(); await _redisService.GetDatabase().StringSetAsync($"{roulette.IdRoulette}", roulette.StateRoulette); return(roulette); } catch (Exception) { throw; } }
public async Task <Roulette> AddAsync(Roulette entity) { try { await _dbContext.Roulette.AddAsync(entity); await _dbContext.SaveChangesAsync(); return(entity); } catch (Exception e) { throw e; } }
public async Task <Bet> AddAsync(Bet entity) { try { var res = await _dbContext.Bet.AddAsync(entity); await _dbContext.SaveChangesAsync(); return(res.Entity); } catch (Exception e) { throw; } }
public async Task <bool> UpdateRoulette(Entities.Roulette roulette) { try { var optionsBuilder = new DbContextOptionsBuilder <RouletteContext>(); optionsBuilder.UseSqlServer("RouletteContext"); using (var context = new RouletteContext(optionsBuilder.Options)) { context.Entry(roulette).State = EntityState.Modified; return(await context.SaveChangesAsync() > 0); } } catch (Exception ex) { throw ex; } }
public async Task <Bet> CreateBet(Bet bet) { try { ValidateRequestStructure(bet); await ValidateRoulette(bet.IdRouletteBet); _betContext.Bet.Add(bet); await _betContext.SaveChangesAsync(); await _redisService.GetDatabase().HashIncrementAsync("RouletteBets", $"{bet.IdRouletteBet}", bet.AmountBet); return(bet); } catch (Exception) { throw; } }
public async Task <int> SaveBet(Entities.Bet gameBet) { try { var optionsBuilder = new DbContextOptionsBuilder <Data.Context.RouletteContext>(); optionsBuilder.UseSqlServer("RouletteContext"); using var context = new RouletteContext(optionsBuilder.Options); context.Bet.Add(gameBet); if (await context.SaveChangesAsync() > 0) { return(gameBet.Id); } return(0); } catch (Exception ex) { throw ex; } }