public ActionResult addEvent(SportEvent toAdd)
        {
            db.events.Add(toAdd);
            db.SaveChanges();

            return RedirectToAction("addEvent");
        }
Пример #2
0
        private float myBetCoefficient(Bet myBet, SportEvent sevent)
        {
            switch(myBet.betType)
            {
                case "П1":
                    return sevent.firstWin;
                case "П2":
                    return sevent.secondWin;
                case "Н":
                    return sevent.gameTie;
                case "НН":
                    return sevent.overallTie;
                case "Н1":
                    return sevent.tieByFirst;
                case "Н2":
                    return sevent.tieBySecond;
                case "Тотал":
                    return sevent.total;
                case "Б":
                    return sevent.b;
                case "М":
                    return sevent.m;
            }

            return 0.0f;
        }
 private void updateBets(SportEvent e)
 {
     var bets = db.bets
         .Where(b => b.betEventId == e.Id)
         .Select(b => b);
     var users = db.Users.ToList();
     var results = db.results.ToList();
     foreach (Bet b in bets)
     {
         if (b.state != "waiting") continue;
         string type = b.betType;
         int typeId = 0; float coff = 0;
         switch (type)
         {
             case "П1": typeId = 0; coff = e.firstWin; break;
             case "П2": typeId = 1; coff = e.secondWin; break;
             case "Н": typeId = 2; coff = e.gameTie; break;
             case "Н1": typeId = 3; coff = e.tieByFirst; break;
             case "Н2": typeId = 4; coff = e.tieBySecond; break;
             case "НН": typeId = 5; coff = e.overallTie; break;
             case "Тотал": typeId = 6; coff = e.total; break;
             case "Б": typeId = 7; coff = e.b; break;
             case "М": typeId = 8; coff = e.m; break;
         }
         ApplicationUser user = users.FirstOrDefault(u => u.Id == b.userId);
         Results result = results.FirstOrDefault(r => r.eId == e.Id);
         if (user != null && result != null)
         {
             if (((result.result >> typeId) & 1) == 1)
             {
                 user.userAmount += (b.amount * coff);
                 b.state = "won";
             }
             else b.state = "lost";
         }
     }
 }