Skip to content

Commit

Permalink
ENTITY RELATIONS
Browse files Browse the repository at this point in the history
  • Loading branch information
SonicTheCat committed Mar 9, 2019
1 parent 4e232c0 commit 44e4d2a
Show file tree
Hide file tree
Showing 48 changed files with 1,925 additions and 0 deletions.
Binary file not shown.
25 changes: 25 additions & 0 deletions 05.Entity Relations/BookmakerSystem/BookmakerSystem.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.136
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P03_FootballBetting", "P03_FootballBetting\P03_FootballBetting.csproj", "{2EF6C49E-1FE3-4301-8481-2FFAF0E199CC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2EF6C49E-1FE3-4301-8481-2FFAF0E199CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2EF6C49E-1FE3-4301-8481-2FFAF0E199CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2EF6C49E-1FE3-4301-8481-2FFAF0E199CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2EF6C49E-1FE3-4301-8481-2FFAF0E199CC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FB86C300-E61C-4C4C-BD30-9BA95C6354EB}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace P03_FootballBetting.Data.EntityConfigurations
{
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

using P03_FootballBetting.Data.Models;

public class BetConfig : IEntityTypeConfiguration<Bet>
{
public void Configure(EntityTypeBuilder<Bet> builder)
{
builder.HasKey(b => b.BetId);

builder.HasOne(b => b.Game)
.WithMany(g => g.Bets)
.HasForeignKey(b => b.GameId);

builder.HasOne(b => b.User)
.WithMany(u => u.Bets)
.HasForeignKey(b => b.UserId);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace P03_FootballBetting.Data.EntityConfigurations
{
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

using P03_FootballBetting.Data.Models;

public class GameConfig : IEntityTypeConfiguration<Game>
{
public void Configure(EntityTypeBuilder<Game> builder)
{
builder.HasKey(g => g.GameId);

builder.HasOne(g => g.HomeTeam)
.WithMany(t => t.HomeGames)
.HasForeignKey(g => g.HomeTeamId)
.OnDelete(DeleteBehavior.Restrict);

builder.HasOne(g => g.AwayTeam)
.WithMany(t => t.AwayGames)
.HasForeignKey(g => g.AwayTeamId)
.OnDelete(DeleteBehavior.Restrict);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace P03_FootballBetting.Data.EntityConfigurations
{
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

using P03_FootballBetting.Data.Models;

public class PlayerConfig : IEntityTypeConfiguration<Player>
{
public void Configure(EntityTypeBuilder<Player> builder)
{
builder.HasKey(p => p.PlayerId);

builder.HasOne(p => p.Team)
.WithMany(t => t.Players)
.HasForeignKey(p => p.TeamId);

builder.HasOne(p => p.Position)
.WithMany(p => p.Players)
.HasForeignKey(p => p.PositionId);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace P03_FootballBetting.Data.EntityConfigurations
{
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

using P03_FootballBetting.Data.Models;

public class PlayerStatisticConfig : IEntityTypeConfiguration<PlayerStatistic>
{
public void Configure(EntityTypeBuilder<PlayerStatistic> builder)
{
builder.HasKey(ps => new { ps.GameId, ps.PlayerId });

builder.HasOne(ps => ps.Game)
.WithMany(g => g.PlayerStatistics)
.HasForeignKey(ps => ps.GameId);

builder.HasOne(ps => ps.Player)
.WithMany(p => p.PlayerStatistics)
.HasForeignKey(ps => ps.PlayerId);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace P03_FootballBetting.Data.EntityConfigurations
{
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

using P03_FootballBetting.Data.Models;

public class TeamConfig : IEntityTypeConfiguration<Team>
{
public void Configure(EntityTypeBuilder<Team> builder)
{
builder.HasKey(e => e.TeamId);

builder.HasOne(e => e.PrimaryKitColor)
.WithMany(pkc => pkc.PrimaryKitTeams)
.HasForeignKey(e => e.PrimaryKitColorId)
.OnDelete(DeleteBehavior.Restrict);

builder.HasOne(e => e.SecondaryKitColor)
.WithMany(skc => skc.SecondaryKitTeams)
.HasForeignKey(e => e.SecondaryKitColorId)
.OnDelete(DeleteBehavior.Restrict);

builder.HasOne(e => e.Town)
.WithMany(t => t.Teams)
.HasForeignKey(e => e.TownId);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace P03_FootballBetting.Data.EntityConfigurations
{
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

using P03_FootballBetting.Data.Models;

public class TownConfig : IEntityTypeConfiguration<Town>
{
public void Configure(EntityTypeBuilder<Town> builder)
{
builder.HasKey(t => t.TownId);

builder.HasOne(t => t.Country)
.WithMany(c => c.Towns)
.HasForeignKey(t => t.CountryId);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
namespace P03_FootballBetting.Data
{
using System;
using System.IO;

using Microsoft.EntityFrameworkCore;

using P03_FootballBetting.Data.EntityConfigurations;
using P03_FootballBetting.Data.Models;

public class FootballBettingContext : DbContext
{
public FootballBettingContext() { }

public FootballBettingContext(DbContextOptions options)
: base(options)
{
}

public DbSet<Bet> Bets { get; set; }

public DbSet<User> Users { get; set; }

public DbSet<Game> Games { get; set; }

public DbSet<PlayerStatistic> PlayerStatistics { get; set; }

public DbSet<Player> Players { get; set; }

public DbSet<Team> Teams { get; set; }

public DbSet<Color> Colors { get; set; }

public DbSet<Country> Countries { get; set; }

public DbSet<Town> Towns { get; set; }

public DbSet<Position> Positions { get; set; }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
var path = Path.Combine(Environment.CurrentDirectory, @"C:\Users\Pavel\ConnectionString.txt");
optionsBuilder.UseSqlServer(File.ReadAllText(path));
}
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfiguration(new BetConfig());
modelBuilder.ApplyConfiguration(new GameConfig());
modelBuilder.ApplyConfiguration(new PlayerConfig());
modelBuilder.ApplyConfiguration(new PlayerStatisticConfig());
modelBuilder.ApplyConfiguration(new TeamConfig());
modelBuilder.ApplyConfiguration(new TownConfig());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace P03_FootballBetting.Data.Models
{
using System;

public class Bet
{
public int BetId { get; set; }

public decimal Amount { get; set; }

public string Prediction { get; set; }

public DateTime DateTime { get; set; }

public int UserId { get; set; }
public User User { get; set; }

public int GameId { get; set; }
public Game Game { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace P03_FootballBetting.Data.Models
{
using System.Collections.Generic;

public class Color
{
public int ColorId { get; set; }

public string Name { get; set; }

public ICollection<Team> PrimaryKitTeams { get; set; }

public ICollection<Team> SecondaryKitTeams { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace P03_FootballBetting.Data.Models
{
using System.Collections.Generic;

public class Country
{
public int CountryId { get; set; }

public string Name { get; set; }

public ICollection<Town> Towns { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace P03_FootballBetting.Data.Models
{
using System;
using System.Collections.Generic;

public class Game
{
public int GameId { get; set; }

public int HomeTeamId { get; set; }
public Team HomeTeam { get; set; }

public int AwayTeamId { get; set; }
public Team AwayTeam { get; set; }

public int HomeTeamGoals { get; set; }

public int AwayTeamGoals { get; set; }

public DateTime DateTime { get; set; }

public decimal HomeTeamBetRate { get; set; }

public decimal AwayTeamBetRate { get; set; }

public decimal DrawBetRate { get; set; }

public string Result { get; set; }

public ICollection<PlayerStatistic> PlayerStatistics { get; set; }

public ICollection<Bet> Bets { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace P03_FootballBetting.Data.Models
{
using System.Collections.Generic;

public class Player
{
public int PlayerId { get; set; }

public string Name { get; set; }

public int SquadNumber { get; set; }

public bool IsInjured { get; set; }

public int TeamId { get; set; }
public Team Team { get; set; }

public int PositionId { get; set; }
public Position Position { get; set; }

public ICollection<PlayerStatistic> PlayerStatistics { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace P03_FootballBetting.Data.Models
{
public class PlayerStatistic
{
public int GameId { get; set; }
public Game Game { get; set; }

public int PlayerId { get; set; }
public Player Player { get; set; }

public int ScoredGoals { get; set; }

public int Assists { get; set; }

public int MinutesPlayed { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace P03_FootballBetting.Data.Models
{
using System.Collections.Generic;

public class Position
{
public int PositionId { get; set; }

public string Name { get; set; }

public ICollection<Player> Players { get; set; }
}
}
Loading

0 comments on commit 44e4d2a

Please sign in to comment.