Ejemplo n.º 1
0
        public async Task <IHttpActionResult> LoadData(DateTime startdate, DateTime enddate)
        {
            if (enddate < startdate)
            {
                return(Ok("Error invalid dates"));
            }
            var date     = startdate;
            var lastDate = enddate.AddDays(1);


            var recordCount = 0;

            using (var db = new Mlb5Context())
            {
                while (date < lastDate)
                {
                    var result = await MlbApi.ImportGamesIfNeeded(db, date);

                    recordCount = recordCount + result;

                    date = date.AddDays(1);
                }
            }

            return(Ok(recordCount));
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> Json(int year, int month, int day)
        {
            var date = new DateTime(year, month, day);

            var mlbApi   = new MlbApi();
            var response = await mlbApi.Get(date);

            return(Ok(response));
        }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> Index(int year, int month, int day)
        {
            var date = new DateTime(year, month, day);

            var identity = User.Identity as ClaimsIdentity;

            var userId = Convert.ToInt32(identity.Claims.First(c => c.Type == "userId").Value);


            var games = new List <Game>();
            var picks = new List <Pick>();
            SimulationDateTime dateTime;

            using (var db = new Mlb5Context())
            {
                dateTime = db.SimulationDateTimes.First();
                await MlbApi.ImportGamesIfNeeded(db, date);

                games = db.Games.Where(x => x.Date == date).ToList();
                picks = db.Picks.Where(x => x.Game.Date == date).ToList();

                var currentTime = dateTime.GetCurrentTime();

                var gamePicks = new List <GamePick>();
                foreach (var game in games)
                {
                    var gamePick = Mapper.Map <GamePick>(game);
                    gamePick.SetStatus(currentTime);

                    var pick = picks.SingleOrDefault(x => x.Game.Id == gamePick.Id);
                    if (pick != null)
                    {
                        gamePick.MarkPicked(pick, db);
                    }
                    gamePicks.Add(gamePick);
                }


                // Get other picks where games are on a previous date and picks have not been awarded

                // Get updated Counts

                var viewModel = new PicksViewModel()
                {
                    Picks  = gamePicks,
                    Counts = GetUpdatedCounts(userId, db)
                };



                return(Ok(viewModel));
            }
        }