예제 #1
0
        public virtual bool AddTipsterIfNotExists(DbTipster tipster)
        {
            OnInformationSending("Dodawanie tipstera...");
            if (_db.Tipsters.AsEnumerable().Any(t => t.NameDomainEquals(tipster)))
            {
                OnInformationSending("Dodano Tipstera");
                return(false);
            }

            var tipsterDomain = tipster.Link.UrlToDomain();
            var websiteId     = _db.Websites.SingleOrDefault(w => w.Address == tipsterDomain)?.Id;

            if (websiteId == null)
            {
                var newWId  = _db.Websites.Next(w => w.Id);
                var website = new DbWebsite(newWId, tipsterDomain, null);
                _db.Websites.Add(website);
                _db.SaveChanges();
                websiteId = newWId;
            }

            var tipsterToAdd = new DbTipster
            {
                Id        = _db.Tipsters.Next(v => v.Id),
                Name      = tipster.Name,
                Link      = tipster.Link,
                WebsiteId = websiteId
            };

            _db.Tipsters.AddOrUpdate(tipsterToAdd);
            _db.SaveChanges();

            OnInformationSending("Dodano Tipstera");
            return(true);
        }
예제 #2
0
 public static HintwiseTipsterResponse ToHintwiseTipsterResponse(DbTipster dbTipster)
 {
     return(new HintwiseTipsterResponse
     {
         Name = dbTipster.Name,
         Address = dbTipster.Link,
         Domain = dbTipster.Link.UrlToDomain()
     });
 }
예제 #3
0
 public static BetshootTipsterResponse ToBetshootTipsterResponse(DbTipster dbTipster)
 {
     return(new BetshootTipsterResponse
     {
         Name = dbTipster.Name,
         Address = dbTipster.Link,
         Domain = dbTipster.Link.UrlToDomain()
     });
 }
예제 #4
0
        public virtual List <DbTipster> GetTipstersExceptDefault()
        {
            var me         = DbTipster.Me();
            var dbTipsters = _db.Tipsters.Include(t => t.Website.Login).Where(t => t.Id != me.Id).OrderBy(t => t.Name).ToList();

            //foreach (var t in dbTipsters)
            //    db.Entry(t.Website).Reference(e => e.Login).Load(); // zamiast explicitly loading tutaj, eager loading u góry, zostawione dla odniesienia

            return(dbTipsters);
        }
예제 #5
0
        public virtual void UpsertBets(DbTipster tipster, List <DbBet> bets, bool addOnly = false, bool dontRemoveTwoDaysPeriod = false)
        {
            OnInformationSending("Zapisywanie zakładów...");

            if (!bets.Any())
            {
                OnInformationSending("Zapisano zakłady");
                return;
            }

            var tipsterId  = _db.Tipsters.Single(t => tipster.Name == t.Name && tipster.Link == t.Link).Id;
            var nextBetId  = _db.Bets.Next(b => b.Id);
            var nextPickId = _db.Picks.Next(p => p.Id);

            foreach (var bet in bets)
            {
                bet.Id        = nextBetId++;
                bet.TipsterId = tipsterId;

                var pick   = bet.Pick;
                var pickId = _db.Picks.SingleOrDefault(p => p.Choice == pick.Choice && p.Value == pick.Value)?.Id;
                if (pickId == null)
                {
                    pick.Id = nextPickId++;
                    _db.Picks.Add(pick);
                    _db.SaveChanges();
                    pickId = pick.Id;
                }
                bet.PickId = pickId.ToInt();
                bet.Pick   = null; // nie dodawaj do bazy właściwości z innych tabel
            }

            if (!addOnly)
            {
                var minDate = bets.Select(b => b.OriginalDate).Min(); // min d z nowych, zawiera wszystkie z tą datą
                _db.Bets.RemoveBy(b => b.OriginalDate >= minDate && b.TipsterId == tipsterId);

                if (!dontRemoveTwoDaysPeriod)
                {
                    var plusOneDay           = minDate.AddDays(1);
                    var minusOneDay          = minDate.AddDays(-1);
                    var twoDaysBets          = _db.Bets.Where(b => b.OriginalDate <plusOneDay && b.OriginalDate> minusOneDay && b.TipsterId == tipsterId).ToList(); // bez between, bo musi być przetłumaczalne na Linq to Entities
                    var sameMatchesInTwoDays = twoDaysBets.Where(b => twoDaysBets.Any(tdb => tdb.EqualsWoOriginalDate(b))).ToList();
                    _db.Bets.RemoveRange(sameMatchesInTwoDays);                                                                                                     // fix dla niespodziewanej zmiany strefy czasowej przez hintwise
                } // TODO: czy to na pewno działa poprawnie dla hintwise
            }

            _db.Bets.AddRange(bets.Distinct());
            // 1. jeśli obstawiono 2x ten sam mecz, ale tip jest ukryty to powstanie duplikat, możemy go odrzucić, bo kiedy poznamy zakład, to i tak obydwa mecze zostaną załadowane.
            // 2. bug hintwise mecze o tym samym czasie mogą być posortowane w dowolnej kolejności, czyli np na początku jednej strony i na końcu nastepnej mogą wystąpić te same, optymalnie poskakac po stronach pagera tam i z powrotem kilka razy
            _db.SaveChanges();

            OnInformationSending("Zapisano zakłady");
        }
예제 #6
0
        public virtual List <DbTipster> GetTipstersExceptDefaultById(params int[] ids)
        {
            if (!ids.Any())
            {
                return(new List <DbTipster>());
            }

            var me = DbTipster.Me();

            return(_db.Tipsters.Include(t => t.Website.Login).WhereByMany(t => t.Id, ids).Where(t => t.Id != me.Id).ToList());
        }
예제 #7
0
 public static TipsterGvVM ToTipsterGvVM(DbTipster dbTipster)
 {
     return(new TipsterGvVM
     {
         Id = dbTipster.Id,
         Name = dbTipster.Name,
         Link = dbTipster.Link,
         WebsiteAddress = dbTipster.Website?.Address, // VM nie powinien posiadać typów €ożonych
         WebsiteLoginName = dbTipster.Website?.Login?.Name,
         WebsiteLoginPassword = dbTipster.Website?.Login?.Password
     });
 }
예제 #8
0
        public virtual void EnsureDefaultTipsterExists()
        {
            var me = DbTipster.Me();

            if (_db.Tipsters.Any(t => t.Id == me.Id))
            {
                return;
            }

            _db.Tipsters.Add(me);
            _db.SaveChanges();
        }
예제 #9
0
 public void AddBet(DbTipster tipster, DbBet bet)
 {
     UpsertBet(tipster, bet, true);
 }
예제 #10
0
 public void AddBets(DbTipster tipster, List <DbBet> bets)
 {
     UpsertBets(tipster, bets, true);
 }
예제 #11
0
 public void UpsertMyBet(DbBet bet, bool addOnly = false)
 {
     UpsertBet(DbTipster.Me(), bet, addOnly);
 }
예제 #12
0
 public void UpsertMyBets(List <DbBet> bets, bool addOnly = false)
 {
     UpsertBets(DbTipster.Me(), bets, addOnly);
 }
예제 #13
0
 public void UpsertBet(DbTipster tipster, DbBet bet, bool addOnly = false)
 {
     UpsertBets(tipster, new[] { bet }.ToList(), addOnly);
 }