Exemplo n.º 1
0
        public void AddManualUserPick(UserPick pick)
        {
            PowerballPicks manualPick = new PowerballPicks()
            {
                ball1     = pick.ball1,
                ball2     = pick.ball2,
                ball3     = pick.ball3,
                ball4     = pick.ball4,
                ball5     = pick.ball5,
                powerball = pick.lottoball,
                pick_date = DateTime.Now,
                powerplay = "0X",
                isPicked  = true
            };

            var existingPick = this._ctx.PowerPicks.FirstOrDefault(
                x => x.ball1 == manualPick.ball1 && x.ball2 == manualPick.ball2 && x.ball3 == manualPick.ball3 &&
                x.ball4 == manualPick.ball4 && x.ball5 == manualPick.ball5 &&
                x.powerball == manualPick.powerball);

            if (existingPick == null)
            {
                this._ctx.PowerPicks.Add(manualPick);

                if (_ctx.SaveChanges() >= 0)
                {
                    pick.pick_id    = manualPick.id;
                    pick.saved_date = DateTime.Now;
                    this._ctx.UserPicks.Add(pick);
                }
            }
        }
Exemplo n.º 2
0
 public async Task <IActionResult> Post([FromBody] UserPick pick)
 {
     try
     {
         this._powerballRepository.AddManualUserPick(pick);
         if (_powerballRepository.SaveAll())
         {
             return(this.Ok());
         }
         else
         {
             return(this.BadRequest($"Save of manual pick wasn't successful"));
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
Exemplo n.º 3
0
        public static void Save(int userId, int tournamentId, int golferId)
        {
            using (var db = new FantasyGolfContext())
            {
                var query = from up in db.UserPick
                            where up.UserId == userId && up.TournamentId == tournamentId
                            select up;

                var pick = query.FirstOrDefault();

                if (pick == null)
                {
                    pick = new UserPick();
                    db.UserPick.Add(pick);
                }
                else
                {
                    db.Entry(pick).State = System.Data.Entity.EntityState.Modified;
                }

                pick.UserId       = userId;
                pick.TournamentId = tournamentId;
                pick.GolferId     = golferId;
                pick.CreatedOn    = DateTime.Now;

                var pickChange = new UserPickChangeLog
                {
                    UserId       = userId,
                    TournamentId = tournamentId,
                    GolferId     = golferId,
                    CreatedOn    = DateTime.Now
                };

                db.UserPickChangeLog.Add(pickChange);
                db.SaveChanges();
            }
        }