示例#1
0
 public List <BE.SportBet> GetEventOdd(string matchID)
 {
     using (var db = new BE.ADOLDBEntities())
     {
         return(db.SportBets.Where(p => p.SportEvent.Code.Equals(matchID)).ToList());
     }
 }
示例#2
0
 public List <BE.Sport> GetActiveSports()
 {
     using (var db = new BE.ADOLDBEntities())
     {
         return(db.Sports.Where(p => p.Active).ToList());
     }
 }
示例#3
0
 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());
     }
 }
示例#4
0
 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);
     }
 }
示例#5
0
 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());
     }
 }
示例#6
0
 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());
     }
 }
示例#8
0
        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);
        }
示例#9
0
        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);
        }
示例#10
0
        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);
        }
示例#11
0
        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);
        }
示例#12
0
        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;
        }
示例#13
0
        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);
        }
示例#14
0
        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());
                }
            }
        }