public GameWithPersonInfo(GameShelfContext db, int id) { ID = id; var gameWithPersonInfo = db.Games .Include(g => g.PlayTime) .Include(g => g.GamePersonRelationships) .ThenInclude(gpi => gpi.Person) .Single(m => m.ID == id); Title = gameWithPersonInfo.Title; MinPlayers = gameWithPersonInfo.MinPlayers; MaxPlayers = gameWithPersonInfo.MaxPlayers; PlayTimeID = gameWithPersonInfo.PlayTimeID; PlayTime = gameWithPersonInfo.PlayTime; Owners = gameWithPersonInfo.GamePersonRelationships.Where(gpr => gpr.Role == Role.Owner).OrderBy(gpr => gpr.Person.LastName).ThenBy(gpr => gpr.Person.FirstName).Select(gpr => gpr.Person).ToList(); Designers = gameWithPersonInfo.GamePersonRelationships.Where(gpr => gpr.Role == Role.Designer).OrderBy(gpr => gpr.Person.LastName).ThenBy(gpr => gpr.Person.FirstName).Select(gpr => gpr.Person).ToList(); }
public GameEditViewModel(GameShelfContext db) { GameWithPersonInfo = new GameWithPersonInfo(); var playTimeQuery = db.Playtimes.OrderBy(pt => pt.ID); PlayTimeSelect = new SelectList(playTimeQuery, "ID", "PlayTimeCategory"); var personQuery = db.People.OrderBy(p => p.LastName).ThenBy(p => p.FirstName); AllPersonsData = new List <AssignedPersonData>(); foreach (Person person in personQuery) { AllPersonsData.Add(new AssignedPersonData { PersonID = person.ID, FullName = person.FullName }); } }
public void UpdateGamePeople(int[] selectedPeople, GameShelfContext db, Role role) { var selectedPeopleHS = new HashSet <int>(selectedPeople); var currentPeopleHS = new HashSet <int>(this.GamePersonRelationships.Where(gpr => gpr.Role == role).Select(gpr => gpr.PersonID)); foreach (int selectedPersonID in selectedPeopleHS) { if (!currentPeopleHS.Contains(selectedPersonID)) { this.GamePersonRelationships.Add(new GamePersonRelationship { GameID = this.ID, PersonID = selectedPersonID, Role = role }); } } foreach (var currentPersonID in currentPeopleHS) { if (!selectedPeopleHS.Contains(currentPersonID)) { var personToRemove = this.GamePersonRelationships.Where(gpr => gpr.Role == role).Single(gpr => gpr.PersonID == currentPersonID); db.Remove(personToRemove); } } }
public PeopleController(GameShelfContext context) { db = context; }
public GamesController(GameShelfContext context) { db = context; }
public GameIndexViewModel( GameShelfContext db, string titleFilter, int minFilter, int maxFilter, int playTimeFilter, string ownerFilter, string designerFilter, string sort) { TitleFilter = titleFilter; MinFilter = minFilter; MaxFilter = maxFilter; PlayTimeFilter = playTimeFilter; OwnerFilter = ownerFilter; DesignerFilter = designerFilter; Sort = sort; var playTimeQuery = db.Playtimes.OrderBy(pt => pt.ID); PlayTimeSelect = new SelectList(playTimeQuery, "ID", "PlayTimeCategory"); var gamesIEnum = db.Games .Include(g => g.PlayTime) .Include(g => g.GamePersonRelationships) .ThenInclude(gpr => gpr.Person) .ToList() .Select(g => new GameWithPersonInfo(g)); if (!String.IsNullOrEmpty(titleFilter)) { gamesIEnum = gamesIEnum.Where(gpi => gpi.Title.ToLower().Contains(titleFilter.ToLower())); } if (minFilter != 0) { gamesIEnum = gamesIEnum.Where(gpi => gpi.MinPlayers == minFilter); } if (maxFilter != 0) { gamesIEnum = gamesIEnum.Where(gpi => gpi.MaxPlayers == maxFilter); } if (playTimeFilter != 0) { gamesIEnum = gamesIEnum.Where(gpi => gpi.PlayTimeID == playTimeFilter); } if (!String.IsNullOrEmpty(ownerFilter)) { gamesIEnum = gamesIEnum.Where(gpi => gpi.Owners.Any(o => o.FullName.ToLower().Contains(ownerFilter.ToLower()))); } if (!String.IsNullOrEmpty(designerFilter)) { gamesIEnum = gamesIEnum.Where(gpi => gpi.Designers.Any(d => d.FullName.ToLower().Contains(designerFilter.ToLower()))); } if (sort == "title-desc") { GameList = gamesIEnum.OrderByDescending(gpi => gpi.Title).ToList(); } else if (sort == "time-asc") { GameList = gamesIEnum.OrderBy(gpi => gpi.PlayTimeID).ThenBy(gpi => gpi.Title).ToList(); } else if (sort == "time-desc") { GameList = gamesIEnum.OrderByDescending(gpi => gpi.PlayTimeID).ThenByDescending(gpi => gpi.Title).ToList(); } else if (sort == "minplay-asc") { GameList = gamesIEnum.OrderBy(gpi => gpi.MinPlayers).ThenBy(gpi => gpi.Title).ToList(); } else if (sort == "minplay-desc") { GameList = gamesIEnum.OrderByDescending(gpi => gpi.MinPlayers).ThenByDescending(gpi => gpi.Title).ToList(); } else if (sort == "maxplay-asc") { GameList = gamesIEnum.OrderBy(gpi => gpi.MaxPlayers).ThenBy(gpi => gpi.Title).ToList(); } else if (sort == "maxplay-desc") { GameList = gamesIEnum.OrderByDescending(gpi => gpi.MaxPlayers).ThenByDescending(gpi => gpi.Title).ToList(); } else { GameList = gamesIEnum.OrderBy(gpi => gpi.Title).ToList(); } }