コード例 #1
0
        public async Task CreateLeagueAsync(FantasyLeague fantasyLeague)
        {
            fantasyLeague.CurrentWeek = -1;
            fantasyLeague.IsActive    = false;
            fantasyLeague.IsFull      = false;
            fantasyLeague.IsSet       = false;

            await _context.AddAsync(fantasyLeague);

            await _context.SaveChangesAsync();

            //create league player list
            List <PlayerMyTeam>  playerMyTeams = new List <PlayerMyTeam>();
            IEnumerable <Player> players       = await GetActivePlayerList();

            foreach (Player p in players)
            {
                PlayerMyTeam pmt = new PlayerMyTeam()
                {
                    PlayerID        = p.PlayerID,
                    FantasyLeagueID = fantasyLeague.FantasyLeagueID
                };
                playerMyTeams.Add(pmt);
            }
            await _context.AddRangeAsync(playerMyTeams);

            await _context.SaveChangesAsync();
        }
コード例 #2
0
        public async Task Create(FantasyLeague fantasyLeague)
        {
            if (!await WeeksExist(fantasyLeague.FantasyLeagueID))
            {
                DateTime startDate = DateTime.Today.AddDays(-1);
                int      numWeeks  = (fantasyLeague.TeamsNav.Count() - 1) * 2;
                List <FantasyMatchupWeeks> list = new List <FantasyMatchupWeeks>();

                for (int i = 1; i <= numWeeks; i++)
                {
                    FantasyMatchupWeeks week = new FantasyMatchupWeeks
                    {
                        FantasyLeagueNav = fantasyLeague,
                        WeekNum          = i,
                        Date             = startDate.AddDays(i),
                    };
                    list.Add(week);
                }
                await _context.FantasyMatchupWeeks.AddRangeAsync(list);

                await _context.SaveChangesAsync();

                return;
            }
        }
コード例 #3
0
        public async Task Create(FantasyLeague fantasyLeague)
        {
            _context.Add(fantasyLeague);
            await _context.SaveChangesAsync();

            return;
        }
コード例 #4
0
        public async Task SetIsFull(int leagueID, bool full)
        {
            FantasyLeague league = await GetLeagueByIDAsync(leagueID);

            league.IsFull = full;
            _context.Update(league);
            await _context.SaveChangesAsync();
        }
コード例 #5
0
        public ActionResult DeleteConfirmed(int id)
        {
            FantasyLeague fantasyLeague = db.FantasyLeagues.Find(id);

            db.FantasyLeagues.Remove(fantasyLeague);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #6
0
 public ActionResult Edit([Bind(Include = "FantasyLeagueId,FantasyLeagueName")] FantasyLeague fantasyLeague)
 {
     if (ModelState.IsValid)
     {
         db.Entry(fantasyLeague).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(fantasyLeague));
 }
コード例 #7
0
        public async Task <Dictionary <int, MyTeam> > GetTeamsDictAsync(int id)
        {
            int           count  = 1;
            FantasyLeague league = await GetLeagueByIDAsync(id);

            if (league != null)
            {
                return(league.TeamsNav.ToDictionary(x => count++, x => x));
            }
            return(null);
        }
コード例 #8
0
        private async Task CreateMatchupsAsync(FantasyLeague fantasyLeague)
        {
            List <MyTeam> teams = fantasyLeague.TeamsNav;

            if (!await MatchupsExists(fantasyLeague.FantasyLeagueID))
            {
                int numWeeks = (teams.Count() - 1) * 2;
                int halfSize = teams.Count() / 2;

                List <MyTeam> listTeams = new List <MyTeam>();

                listTeams.AddRange(teams);
                listTeams.RemoveAt(0);

                int teamSize = listTeams.Count();

                List <FantasyMatchup> matchups = new List <FantasyMatchup>();

                for (int week = 0; week < numWeeks; week++)
                {
                    var matchup = new FantasyMatchup();
                    matchup.Week            = week + 1;
                    matchup.FantasyLeagueID = fantasyLeague.FantasyLeagueID;
                    matchup.Status          = "Scheduled";

                    int teamIdx = week % teamSize;

                    matchup.AwayTeamNav   = listTeams[teamIdx];
                    matchup.HomeTeamNav   = teams[0];
                    matchup.HomeTeamScore = 0;
                    matchup.AwayTeamScore = 0;

                    matchups.Add(matchup);

                    for (int i = 1; i < halfSize; i++)
                    {
                        var nextMatchup = new FantasyMatchup();
                        nextMatchup.Week            = week + 1;
                        nextMatchup.FantasyLeagueID = fantasyLeague.FantasyLeagueID;
                        nextMatchup.Status          = "Scheduled";

                        nextMatchup.AwayTeamNav   = listTeams[(week + i) % teamSize];
                        nextMatchup.HomeTeamNav   = listTeams[(week + teamSize - i) % teamSize];
                        nextMatchup.AwayTeamScore = 0;
                        nextMatchup.HomeTeamScore = 0;
                        matchups.Add(nextMatchup);
                    }
                }
                _context.FantasyMatchup.AddRange(matchups);
                await _context.SaveChangesAsync();

                return;
            }
        }
コード例 #9
0
        public ActionResult Create([Bind(Include = "FantasyLeagueId,FantasyLeagueName")] FantasyLeague fantasyLeague)
        {
            if (ModelState.IsValid)
            {
                db.FantasyLeagues.Add(fantasyLeague);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(fantasyLeague));
        }
コード例 #10
0
        public async Task Create(FantasyLeague fantasyLeague)
        {
            await _fantasyMatchupsWeeksService.Create(fantasyLeague);

            await CreateMatchupsAsync(fantasyLeague);

            await _fantasyLeagueStandingsService.Create(fantasyLeague);

            await _fantasyLeagueService.SetLeagueAsync(fantasyLeague);

            return;
        }
コード例 #11
0
        public async Task <IActionResult> Create([Bind("FantasyLeagueID,Name")] FantasyLeague fantasyLeague)
        {
            if (ModelState.IsValid)
            {
                fantasyLeague.CommissionerID = User.FindFirst(ClaimTypes.NameIdentifier).Value;
                await _service.CreateLeagueAsync(fantasyLeague);

                return(RedirectToAction("Details", new { id = fantasyLeague.FantasyLeagueID }));
            }
            //ViewData["CommissionerID"] = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            return(View(fantasyLeague));
        }
コード例 #12
0
        public async Task Edit(FantasyLeague fantasyLeague)
        {
            try
            {
                _context.Update(fantasyLeague);
                await _context.SaveChangesAsync();

                return;
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }
        }
コード例 #13
0
        // GET: FantasyLeague/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            FantasyLeague fantasyLeague = db.FantasyLeagues.Find(id);

            if (fantasyLeague == null)
            {
                return(HttpNotFound());
            }
            return(View(fantasyLeague));
        }
コード例 #14
0
        // GET: FantasyLeagues/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            FantasyLeague league = await _service.GetLeagueByIDAsync(id.Value);

            if (league != null)
            {
                return(View(league));
            }
            return(NotFound());
        }
コード例 #15
0
        public async Task IsActiveFalseAsync(FantasyLeague fantasyLeague)
        {
            fantasyLeague.IsActive = false;
            try
            {
                _context.Update(fantasyLeague);
                await _context.SaveChangesAsync();

                return;
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }
        }
コード例 #16
0
        public async Task UpdateCurrentWeekAsync(FantasyLeague fantasyLeague, int week)
        {
            fantasyLeague.CurrentWeek = week;
            try
            {
                _context.Update(fantasyLeague);
                await _context.SaveChangesAsync();

                return;
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }
        }
コード例 #17
0
        public async Task <IActionResult> Create([Bind("FantasyLeagueID,Name,IsFull,IsSet,IsActive")] FantasyLeague fantasyLeague)
        {
            if (!User.IsInRole("Administrator"))
            {
                return(new ChallengeResult());
            }
            fantasyLeague.CommissionerID = _userManager.GetUserId(User);

            if (ModelState.IsValid)
            {
                await _fantasyLeagueService.Create(fantasyLeague);

                return(RedirectToAction("Details", "FantasyLeagues", new { id = fantasyLeague.FantasyLeagueID }));
            }
            return(View(fantasyLeague));
        }
コード例 #18
0
        public async Task <IActionResult> Edit(int id, [Bind("FantasyLeagueID,Name,IsFull,IsSet,IsActive")] FantasyLeague fantasyLeague)
        {
            if (id != fantasyLeague.FantasyLeagueID)
            {
                return(NotFound());
            }
            fantasyLeague.CommissionerID = _userManager.GetUserId(User);

            if (ModelState.IsValid && await _fantasyLeagueService.FantasyLeagueExists(id))
            {
                await _fantasyLeagueService.Edit(fantasyLeague);

                return(RedirectToAction("Details", "FantasyLeagues", new { id = fantasyLeague.FantasyLeagueID }));
            }
            return(View(fantasyLeague));
        }
コード例 #19
0
        public async Task SetLeagueAsync(FantasyLeague fantasyLeague)
        {
            fantasyLeague.IsSet       = true;
            fantasyLeague.IsActive    = true;
            fantasyLeague.CurrentWeek = 1;
            try
            {
                _context.Update(fantasyLeague);
                await _context.SaveChangesAsync();

                return;
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }
        }
コード例 #20
0
        public async Task Create(FantasyLeague fantasyLeague)
        {
            var teams = fantasyLeague.TeamsNav;
            List <FantasyLeagueStandings> createdStandings = new List <FantasyLeagueStandings>();

            foreach (var t in teams)
            {
                FantasyLeagueStandings created = new FantasyLeagueStandings
                {
                    FantasyLeagueNav = fantasyLeague,
                    MyTeamNav        = t,
                };
                createdStandings.Add(created);
            }
            await _context.AddRangeAsync(createdStandings);

            await _context.SaveChangesAsync();

            return;
        }
コード例 #21
0
        //shows league tables for different rounds
        public ActionResult RoundDetails(int?id, int?round)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            FantasyLeague fantasyLeague = db.FantasyLeagues.Find(id);

            if (fantasyLeague == null)
            {
                return(HttpNotFound());
            }
            if (round == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            else
            {
                ViewBag.Round = round;
            }

            return(View(fantasyLeague));
        }
コード例 #22
0
        public async Task <int> GetTeamsCount(int id)
        {
            FantasyLeague league = await GetLeagueByIDAsync(id);

            return(league.TeamsNav.Count());
        }