public List <BE.SportBet> GetEventOdd(string matchID) { using (var db = new BE.ADOLDBEntities()) { return(db.SportBets.Where(p => p.SportEvent.Code.Equals(matchID)).ToList()); } }
public List <BE.Sport> GetActiveSports() { using (var db = new BE.ADOLDBEntities()) { return(db.Sports.Where(p => p.Active).ToList()); } }
public BE.SportBet GetSportBet(int sportBetID) { using (var db = new BE.ADOLDBEntities()) { return(db.SportBets.Include(s => s.SportEvent).Include(p => p.SportEvent.Sport).Where(p => p.ID.Equals(sportBetID)).First()); } }
public bool StoreUserBet(List <BE.UserBet> bets) { try { using (var db = new BE.ADOLDBEntities()) { using (TransactionScope scope = new TransactionScope()) { var linkID = Guid.NewGuid(); foreach (var bet in bets) { db.UserBets.Add(bet); db.SaveChanges(); } scope.Complete(); return(true); } } } catch (Exception ex) { //do something with ex return(false); } }
public List <BE.SportEvent> GetEventsByIDs(int[] ids) { using (var db = new BE.ADOLDBEntities()) { return(db.SportEvents.Include(p => p.SportBets).Include(p => p.Sport).Where(p => ids.Contains(p.ID)).Distinct().ToList()); } }
public List <BE.SportEvent> GetCurrentEvents() { using (var dbcontext = new BE.ADOLDBEntities()) { return(dbcontext.SportEvents.Include("SportBets").Where(p => p.Active && p.Init > DateTime.UtcNow).ToList()); } }
public BE.User GetUser(string sessionToken) { using (var db = new BE.ADOLDBEntities()) { return(db.Users.Where(p => p.SessionToken.Equals(sessionToken)).FirstOrDefault()); } }
public BE.SportEvent GetSportEvent(string eventCode) { BE.SportEvent returnValue = new BE.SportEvent(); using (var db = new BE.ADOLDBEntities()) { returnValue = db.SportEvents.First(e => e.Code == eventCode); } return(returnValue); }
public List <Tuple <string, BE.UserBet> > GetPendings(string[] events) { List <Tuple <string, BE.UserBet> > returnValue = new List <Tuple <string, BE.UserBet> >(); using (var db = new BE.ADOLDBEntities()) { var bet = db.UserBets.Where(p => events.Contains(p.SportBet.SportEvent.Code) && p.Hit == null).ToList(); if (bet != null) { bet.ForEach(p => returnValue.Add(new Tuple <string, BE.UserBet>(p.SportBet.SportEvent.Code, p))); } } return(returnValue); }
public BE.User UpdateUser(BE.User userData) { using (var db = new BE.ADOLDBEntities()) { var user = db.Users.Where(p => p.UID.Equals(userData.UID)).First(); user.LaunchToken = userData.LaunchToken; user.SessionToken = userData.SessionToken; user.Balance = userData.Balance; db.Users.Attach(user); db.Entry(user).State = System.Data.EntityState.Modified; db.SaveChanges(); } return(userData); }
public List <BE.SportEvent> GetSportEvents(string sportCode) { List <BE.SportEvent> returnValue = new List <BE.SportEvent>(); using (var db = new BE.ADOLDBEntities()) { BE.SportEvent sportEvent = new BE.SportEvent(); var events = db.Sports.Where(p => p.Code.Equals(sportCode)).First().SportEvents.ToList(); foreach (var singleEvent in events) { sportEvent = singleEvent; sportEvent.SportBets = singleEvent.SportBets; returnValue.Add(sportEvent); } } return(returnValue); }
public List <BE.SportEvent> GetEventsByTournament(string tournamentId) { //List<BE.SportEvent> returnValue = new List<BE.SportEvent>(); using (var db = new BE.ADOLDBEntities()) { //BE.SportEvent sportEvent = new BE.SportEvent(); //var sports = db.Sports.ToList(); //var events = db.Sports.Where(p => p.TournamentID.Equals(tournamentId)).First().SportEvents.ToList(); return(db.SportEvents.Include(p => p.SportBets).Where(p => p.Sport.TournamentID.Equals(tournamentId)).ToList()); //foreach (var singleEvent in events) //{ // sportEvent = singleEvent; // sportEvent.SportBets = singleEvent.SportBets; // returnValue.Add(sportEvent); //} } //return returnValue; }
public List <BE.UserBet> GetUserBets(string userToken) { List <BE.UserBet> returnValue = new List <BE.UserBet>(); using (var db = new BE.ADOLDBEntities()) { var userBets = db.UserBets.Where(p => p.User.SessionToken.Equals(userToken)).ToList(); foreach (var userBet in userBets) { BE.UserBet item = new BE.UserBet(); var sportOdd = userBet.SportBet; item = userBet; item.SportBet = sportOdd; returnValue.Add(item); } } return(returnValue); }
public void StoreEvents(List <BE.SportEvent> updatedEvents) { using (var dbcontext = new BE.ADOLDBEntities()) { try { foreach (var updatedEvent in updatedEvents) { if (dbcontext.SportEvents.Any(p => p.Code.Equals(updatedEvent.Code))) { var storedEvent = dbcontext.SportEvents.Where(p => p.Code.Equals(updatedEvent.Code)).First(); foreach (var bet in updatedEvent.SportBets) { var storedOdd = storedEvent.SportBets.Where(p => p.Code.Equals(bet.Code)).FirstOrDefault(); if (storedOdd != null) { storedOdd.Odd1 = bet.Odd1; storedOdd.Odd2 = bet.Odd2; storedOdd.Odd3 = bet.Odd3; } else { storedEvent.SportBets.Add(bet); } } storedEvent = updatedEvent; //storedEvent.Deporte = dbcontext.Deportes.Where(p => p.Codigo.Equals("1")).First(); } else { foreach (var singleBet in updatedEvent.SportBets) { dbcontext.SportBets.Add(singleBet); } //evento.Deporte = dbcontext.Deportes.Where(p => p.Codigo.Equals("1")).First(); updatedEvent.Active = true; dbcontext.SportEvents.Add(updatedEvent); } } dbcontext.SaveChanges(); } catch (DbEntityValidationException ex) { var error = ex.EntityValidationErrors.First().ValidationErrors.First(); //this.ModelState.AddModelError(error.PropertyName, error.ErrorMessage); //return View(); } catch (Exception exn) { StringBuilder sb = new StringBuilder(); var innerException = AddInnerException(exn, sb); while (innerException != null) { innerException = AddInnerException(innerException, sb); } //var errors = sb.ToString(); throw new Exception(sb.ToString()); } } }