protected override void OnModelCreating(ModelBuilder modelBuilder) { // Set up the many to many relationship between Person and Sport modelBuilder.Entity <PersonSport>() .HasKey(sc => new { sc.PersonId, sc.SportId }); modelBuilder.Entity <PersonSport>() .HasOne <Person>(sc => sc.Person) .WithMany(s => s.PersonSports) .HasForeignKey(sc => sc.PersonId); modelBuilder.Entity <PersonSport>() .HasOne <Sport>(sc => sc.Sport) .WithMany(s => s.PersonSports) .HasForeignKey(sc => sc.SportId); //modelBuilder.Entity<PersonSport>() // .HasOne<Sport>(sc => sc.Sport) // .WithMany(s => s.PersonSports) // .HasForeignKey(sc => sc.SportId); // Seed the data in code tables constant values modelBuilder.Entity <Sport>().HasData(SportCodeService.Select()); modelBuilder.Entity <CollectibleStatus>().HasData(CollectibleStatusCodeService.Select()); modelBuilder.Entity <CardType>().HasData(CardTypeCodeService.Select()); modelBuilder.Entity <CollectibleType>().HasData(CollectibleTypeCodeService.Select()); modelBuilder.Entity <League>().HasData(LeagueCodeService.Select()); modelBuilder.Entity <ProductStatus>().HasData(ProductStatusCodeService.Select()); modelBuilder.Entity <ProductType>().HasData(ProductTypeCodeService.Select()); base.OnModelCreating(modelBuilder); }
public Sport Get(int id) { try { var sportData = SportCodeService.Select(id); if (sportData == null) { throw new DataNotFoundException("Sport not found. Invalid id provided."); } var sport = new Sport { Id = sportData.Id, Identifier = sportData.Identifier, Name = sportData.Name }; return(sport); } catch { throw new DataNotFoundException("Sport not found. Invalid id provided."); } }
public void Select_Succeeds() { // Run the test var sports = SportCodeService.Select(); // Verify results match expected results Assert.NotNull(sports); Assert.True(sports.Count > 0); }
public void Select_WithValidId_Succeeds() { int footballId = SportCodeService.Football.Id; // Run test var sport = SportCodeService.Select(footballId); // Verify that card was returned Assert.NotNull(sport); Assert.Equal(sport.Id, footballId); }
public List <Sport> Get() { var sportsData = SportCodeService.Select(); var sports = sportsData .Select(x => new Quinlan.Domain.Models.Sport { Id = x.Id, Identifier = x.Identifier, Name = x.Name }) .ToList(); return(sports); }
public PersonSearch Get(PersonSearchFilterOptions filterOptions) { var personFilterOptions = QueryFilterService.BuildPersonFilterOptions(filterOptions); var peopleData = _personQueryService.Execute(personFilterOptions); var sportsData = SportCodeService.Select(); var people = peopleData .Select(x => new Person { Id = x.Id, Identifier = x.Identifier, Name = String.Format("{0} {1}", x.FirstName ?? "", x.LastName), LastName = x.LastName, FirstName = x.FirstName, MiddleName = x.MiddleName, Suffix = x.Suffix, College = x.College != null ? new College { Id = x.College.Id, Identifier = x.College.Identifier, Name = x.College.Name, Nickname = x.College.Nickname } : null, Sports = x.PersonSports.Select(ps => new Sport { Id = ps.SportId, Identifier = sportsData.Single(s => s.Id == ps.SportId).Identifier, Name = sportsData.Single(s => s.Id == ps.SportId).Name }).ToList(), HOFFlag = x.HOFFlag == true, HeismanFlag = x.HeismanFlag == true, NotableFlag = x.NotableFlag == true }) .ToList(); var personSearch = new PersonSearch { PersonFilterOptions = filterOptions, People = people }; return(personSearch); }
public Person Get(int id) { var personData = _personDataService.Select(id); if (personData == null) { throw new DataNotFoundException("Person not found. Invalid id provided."); } var sportsData = SportCodeService.Select(); var person = new Person { Id = personData.Id, Identifier = personData.Identifier, Name = string.Format("{0} {1}", personData.FirstName ?? "", personData.LastName), LastName = personData.LastName, FirstName = personData.FirstName, MiddleName = personData.MiddleName, Suffix = personData.Suffix, HOFFlag = personData.HOFFlag == true, HeismanFlag = personData.HeismanFlag == true, NotableFlag = personData.NotableFlag == true, College = personData.College == null ? null : new College { Id = personData.College.Id, Identifier = personData.College.Identifier, Name = personData.College.Name, Nickname = personData.College.Nickname }, Sports = personData.PersonSports == null ? null : personData.PersonSports.Select(x => new Sport { Id = x.SportId, Identifier = sportsData.Single(s => s.Id == x.SportId).Identifier, Name = sportsData.Single(s => s.Id == x.SportId).Name }).ToList() }; return(person); }
public void Select_WithInvalidId_Fails() { try { int invalidSportId = SportCodeService.Select().Count + 1; // Run test var sport = SportCodeService.Select(invalidSportId); // Fail test if exception is not thrown Assert.Equal(1, 0); } catch (InvalidIdException invalidIdException) { Assert.NotNull(invalidIdException); } catch { // Fail test if expected exception not thrown Assert.Equal(1, 0); } }
public static void SeedCodeValues(DbContextOptions <QdbContext> options) { using (var context = new QdbContext(options)) { if (context.CollectibleStatuses.Count() > 0) { return; } foreach (var cardType in CardTypeCodeService.Select()) { context.CardTypes.Add(cardType); } foreach (var collectibleStatus in CollectibleStatusCodeService.Select()) { context.CollectibleStatuses.Add(collectibleStatus); } foreach (var collectibleType in CollectibleTypeCodeService.Select()) { context.CollectibleTypes.Add(collectibleType); } foreach (var league in LeagueCodeService.Select()) { context.Leagues.Add(league); } foreach (var productStatus in ProductStatusCodeService.Select()) { context.ProductStatuses.Add(productStatus); } foreach (var sport in SportCodeService.Select()) { context.Sports.Add(sport); } context.SaveChanges(); } }