Пример #1
0
 public async Task<Game> AssignValuesAsync(ApplicationDbContext db)
 {
     List<Player> players = new List<Player>();
     List<Lane> lanes = new List<Lane>();
     foreach (var item in SelectedPlayers)
     {
         players.Add(await db.Players.FindAsync(item));
     }
     foreach (var item in SelectedLanes)
     {
         lanes.Add(await db.Lanes.FindAsync(item));
     }
     foreach (var item in players)
     {
         item.GamesPlayed.Add(this);
     }
     this.Lanes = lanes;
     TeamFactory teamFactory = new TeamFactory(players);
     teamFactory.PlayersPerTeam = PlayersPerTeam;
     if (IsScramble) teamFactory.ScramblePlayers();
     Rounds = Utilities.GetRounds(teamFactory.CreateTeams(), lanes);
     int counter = 1;
     foreach (var item in Rounds)
     {
         item.PlayOrder = counter;
         counter++;
     }
     this.Teams = teamFactory.Teams;
     return this;
 }
Пример #2
0
        public async Task<ActionResult> Fix()
        {

            ApplicationDbContext db = new ApplicationDbContext();
            var sven = await db.Clubs.FindAsync(2);
            var uni = await db.Clubs.FindAsync(4);
            foreach (var item in sven.Players.Where(s=> s.CreatedOn > new DateTime(2016,03,30)))
            {
                item.Club = uni;
            }
            await db.SaveChangesAsync();
            return RedirectToAction("About", "Home");
        }
Пример #3
0
        private async Task<JSONPlayerListData> AssignAsync(ApplicationDbContext db, ApplicationUser user)
        {
           
            var listings = db.PlayerLists.Where(s => s.ClubID == user.Club.ID && !s.Deleted).ToList();
            var players = user.Club.Players.Where(p => !p.Deleted && !p.IsTemporary).ToList();
            //var games = user.Club.Games.Where(p => !p.Deleted).OrderByDescending(d => d.Started).ToArray();
            AllPlayers = players.GetJSON();
            PlayerLists = new List<JSONPlayerList>();
            //Games = new List<JSONPlayerList>();
            foreach (var item in listings)
            {
                PlayerLists.Add(new JSONPlayerList(item));

            }
            //foreach (var item in games)
            //{
            //    Games.Add(new JSONPlayerList() {ID = item.ID, Name = item.Name, Players = item.Players.ToList().GetJSON() });
            //}
            return this;
        }
Пример #4
0
 public async Task<Player> GetPlayerAsync(ApplicationDbContext db)
 {
     return await db.Players.FindAsync(ID);
 }
Пример #5
0
 public static async Task<List<TeamSetting>> GetTeamSettingsAsync(this List<JSONTeamSetting> model, ApplicationDbContext db)
 {
     var result = new List<TeamSetting>();
     foreach (var item in model)
     {
         var toAdd = await item.GetTeamSettingAsync(db);
         if (toAdd != null) result.Add(toAdd);
     }
     return result;
 }
Пример #6
0
        public static async Task<List<Game>> GetGamesAsync(this List<JSONGame> model, ApplicationDbContext db)
        {
            var result = new List<Game>();
            foreach (var item in model)
            {
                var toAdd = await item.GetGameAsync(db);
                if (toAdd != null) result.Add(toAdd);

            }
            return result;
        }
Пример #7
0
 public static async Task<List<Team>> GetTeamsAsync(this List<JSONTeam> model, ApplicationDbContext db)
 {
     var result = new List<Team>();
     if (model == null) return result;
     if (model.Count == 0) return result;
     foreach (var item in model)
     {
         var toAdd = await item.GetTeamAsync(db);
         if (toAdd != null) result.Add(toAdd);
     }
     return result;
 }
Пример #8
0
 public async Task<Game> GetGameAsync(ApplicationDbContext db)
 {
     return await db.Games.FindAsync(ID);
 }
Пример #9
0
 public async Task<Lane> GetLaneAsync(ApplicationDbContext db)
 {
     return await db.Lanes.FindAsync(ID);
 }
Пример #10
0
 public async Task<JSONPlayerListData> GetJSON(ApplicationDbContext db, ApplicationUser user)
 {
     return await AssignAsync(db, user);
     //return JsonConvert.SerializeObject(await AssignAsync(db, user), Formatting.None);
 }
Пример #11
0
        public async Task<PlayerList> GeneratePlayerListAsync(ApplicationDbContext db, ApplicationUser user)
        {
            if (user == null) return null;
            var result = new PlayerList();
            result.Active = true;
            result.ClubID = user.Club.ID;
            result.SetCreated(user);
            result.Name = Name;
            if (Players == null) Players = new List<JSONPlayer>();

            result.Players = await Players.GetPlayersAsync(db);
            if (File != null)
            {
                StreamReader reader = new StreamReader(File.InputStream, System.Text.Encoding.UTF8);
                var csvstring = await reader.ReadToEndAsync();
                var players = Utilities.ImportCSV(csvstring);
                foreach (var item in players)
                {
                    item.Club = user.Club;
                    result.Players.Add(item);
                }
            }

            return result;
        }
Пример #12
0
 public async Task<ICollection<Player>> GetPlayersAsync(ApplicationDbContext db)
 {
     var result = new List<Player>();
     foreach (var item in this.Players)
     {
         result.Add(await db.Players.FindAsync(item.ID));
     }
     return result;
 }
Пример #13
0
        public async Task<ActionResult> Fix()
        {

            ApplicationDbContext db = new ApplicationDbContext();
            if (db.Roles.Where(r => r.Name == "Admin").Count() == 0)
            {
                db.Roles.Add(new Microsoft.AspNet.Identity.EntityFramework.IdentityRole("Admin"));
                db.SaveChanges();
            }
            if (db.Roles.Where(r => r.Name == "ClubAdmin").Count() == 0)
            {
                db.Roles.Add(new Microsoft.AspNet.Identity.EntityFramework.IdentityRole("ClubAdmin"));
                db.SaveChanges();
            }
            if (db.Roles.Where(r => r.Name == "ClubMember").Count() == 0)
            {
                db.Roles.Add(new Microsoft.AspNet.Identity.EntityFramework.IdentityRole("ClubMember"));
                db.SaveChanges();
            }
            var stellan = await db.Users.Where(u => u.UserName == "Cellana").FirstOrDefaultAsync();
            var christian = await db.Users.Where(u => u.UserName == "unicurl").FirstOrDefaultAsync();
            var niclas = await db.Users.Where(u => u.UserName == "Capplequoppe").FirstOrDefaultAsync();
            await UserManager.AddToRoleAsync(stellan.Id, "ClubAdmin");
            await UserManager.AddToRoleAsync(christian.Id, "ClubAdmin");
            await UserManager.AddToRoleAsync(niclas.Id, "ClubAdmin");
            await UserManager.AddToRoleAsync(niclas.Id, "Admin");
            return RedirectToAction("About", "Home");
        }
Пример #14
0
 private async Task<JSONTeamSettingsData> AssignAsync(ApplicationDbContext db, ApplicationUser user)
 {
     var listings = db.SavedTeams.Where(s => s.ClubID == user.Club.ID && !s.Deleted).ToList();
     var games = user.Club.Games.Where(g => !g.Deleted).ToList();
     var players = user.Club.Players.Where(p => !p.Deleted).ToList();
     var lanes = user.Club.Lanes.Where(l => !l.Deleted).ToList();
     Listings = listings.GetJSON();
     AllPlayers = players.GetJSON();
     Lanes = lanes.GetJSON();
     PrevGames = games.GetJSON();
     return this;
 }
Пример #15
0
 public async Task<TeamSetting> GenerateTeamSettingAsync(ApplicationDbContext db, ApplicationUser user)
 {
     if (user == null) return null;
     var result = new TeamSetting();
     result.Active = true;
     result.ClubID = user.Club.ID;
     result.SetCreated(user);
     result.Name = Name;
     if (Teams == null) Teams = new List<JSONTeam>();
     var teams = await Teams.GetTeamsAsync(db);
     if (Players == null) Players = new List<JSONPlayer>();
     var players = await Players.GetPlayersAsync(db);
     if (players.Count > 0)
     {
         TeamFactory factory = new TeamFactory(players);
         factory.PlayersPerTeam = TeamSize;
         teams.AddRange(factory.CreateTeams());
     }
     result.Teams = teams;
     var counter = 1;
     foreach (var item in result.Teams)
     {
         item.AltName = counter.ToString();
         counter++;
     }
     return result;
 }
Пример #16
0
 public async Task<TeamSetting> GetTeamSettingAsync(ApplicationDbContext db)
 {
     return await db.SavedTeams.FindAsync(ID);
 }