public Market GetById(string marketId, bool populateBets) { var marketById = MarketRepository.GetById(marketId); if (!populateBets || marketById == null) { return(marketById); } marketById.MarketBets = BetService.GetAllByMarketId(marketId); return(marketById); }
private void validateNewBet(Bet newBet) { if (newBet == null) { throw new ArgumentNullException(nameof(newBet)); } if (newBet.BetAmount == 0) { throw new Exception("A bet needs an amount"); } if (string.IsNullOrEmpty(newBet.MarketId)) { throw new Exception("A bet needs to be linked to a market"); } var linkedMarket = MarketRepository.GetById(newBet.MarketId); if (linkedMarket == null) { throw new Exception($"The linked market with id {newBet.MarketId} could not be found."); } if (string.IsNullOrEmpty(linkedMarket.EventId)) { throw new Exception("No parent event could be found for the linked market."); } var linkedEvent = EventRepository.GetById(linkedMarket.EventId); if (linkedEvent == null) { throw new Exception($"The linked event with id {linkedMarket.EventId} could not be found."); } if (linkedEvent.EndDate < DateTime.Now) { throw new Exception("Bet cannot be placed, the event has ended."); } }
protected void Page_Init(object sender, EventArgs e) { Account account = new Account( "vietluyen", "385557456569739", "Si2Q2D3dxjqgya-Rl7-lZ0cy99Q"); Cloudinary = new Cloudinary(account); Session["Active"] = "Markets"; if (!IsPostBack) { Session["UserHotel"] = null; Session["CurrentPage"] = 1; if (Request.Params["id"] == null) { MarketMultiView.ActiveViewIndex = 0; MarketRepeater.DataSource = _marketRepositoty.GetAll(); MarketRepeater.DataBind(); } else { MarketMultiView.ActiveViewIndex = 1; int id = int.Parse(Request.Params["id"]); if (id == 0) // Add new { DdlHotels.Visible = false; AddHotelMarketButton.Visible = false; Deactivebutton.Visible = false; ActiveButton.Visible = false; MarketImage.Visible = false; UploadImage.Visible = false; } else { _markets = _marketRepositoty.GetById(id); if (_markets != null) { LocationNameText.Text = _markets.LocationName; MarketText.Text = _markets.MarketCode; PermalinkText.Text = _markets.Permalink; DdlState.SelectedValue = _markets.State; LatitudeText.Text = _markets.Latitude; LongtitudeText.Text = _markets.Longitude; IsCollectTax.Checked = _markets.IsCalculateTax; if (_markets.IsActive) { Deactivebutton.Visible = true; ActiveButton.Visible = false; } else { Deactivebutton.Visible = false; ActiveButton.Visible = true; } if (!string.IsNullOrEmpty(_markets.PublicId) && !string.IsNullOrEmpty(_markets.Format)) { var url = Cloudinary.Api.UrlImgUp.Secure() .Transform(new Transformation().Width(500).Height(500).Crop("fill")) .BuildUrl(string.Format("{0}.{1}", _markets.PublicId, _markets.Format)); MarketImageControl.ImageUrl = url; } } RebindHotelsByMarket(); } } } }