public IActionResult Bet(string userId, [FromBody] Dictionary <string, object> bet) { Bet newBet = new Bet() { RouletteId = bet["rouletteId"].ToString(), UserId = Int32.Parse(userId), BetAmmount = Int32.Parse(bet["ammount"].ToString()), BetBox = bet["box"].ToString(), DateMade = bet["dateMade"].ToString() }; if (IsValidBet(newBet)) { var result = _rouleteService.CreateBet(newBet); return(Created($"{this.Request.Scheme}://{this.Request.Host}{this.Request.Path}/{userId}", result.Id)); } else { return(StatusCode(400)); } }
public HttpResponseMessage CreateBet(HttpRequestMessage request, [FromBody] Bets bet) { var response = Request.CreateResponse(HttpStatusCode.NotImplemented); var headers = request.Headers; var iduser = headers.GetValues("User"); bet.User_Id = Convert.ToInt32(iduser.FirstOrDefault()); var res = RouletteService.CreateBet(bet); if (res >= 1) { response = Request.CreateResponse(HttpStatusCode.Created); } else { response = Request.CreateResponse(HttpStatusCode.BadRequest); } return(response); }