public async Task <CreateBetResult> RegisterBet(Bet bet) { CreateBetResult result = new CreateBetResult(); var roulette = await _rouletteRepository.GetRoulette(new Roulette { Id = bet.RouletteId }); if (roulette == null) { result.Success = false; result.Message = "Roulette not found"; return(result); } if (!roulette.Open) { result.Success = false; result.Message = "Roulette not Open,Please First Open the Roulette"; return(result); } await _betRepository.AddBet(bet); result.Data = bet.Id; result.Success = true; return(result); }
public HttpResponseMessage CreateBet(BetDomenModel newBetDomen) { if (newBetDomen != null) { var newBet = Mapper.Map <Bet>(newBetDomen); repository.AddBet(newBet); return(new HttpResponseMessage(HttpStatusCode.OK)); } return(new HttpResponseMessage(HttpStatusCode.BadRequest)); }
public async Task AddBet(BetViewModel betViewModel) { var betEntity = new Bet { BetDateUtc = betViewModel.BetDateUtc, BookMaker = new BookMaker { Name = betViewModel.BookMaker.Name }, Profit = betViewModel.Profit }; await _betRepository.AddBet(betEntity); }
public async Task <IActionResult> CreateBet([FromBody] CreateBetDto createBetDto) { try { if (createBetDto == null || !ModelState.IsValid) { return(BadRequest()); } var user = await GetUser(); if (user == null) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var bet = Mapper.Map <Bet>(createBetDto); bet.User = user; await _betRepository.AddBet(bet); if (!await _betRepository.Save()) { return(GetErrorStatusCodeAndGenericMessage()); } var betDtoToReturn = Mapper.Map <BetDto>(bet); return(CreatedAtRoute("GetBet", new { betId = betDtoToReturn.Id }, betDtoToReturn)); } catch (Exception) { return(GetErrorStatusCodeAndGenericMessage()); } }