Пример #1
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);
     }
 }
Пример #2
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);
        }
Пример #3
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());
                }
            }
        }