Skip to content
Snippets Groups Projects
Commit 5d4646d4 authored by Julien CLOSSON's avatar Julien CLOSSON
Browse files
parents ef4bed63 0dd8f386
Branches Julien
No related tags found
No related merge requests found
Showing
with 483 additions and 14 deletions
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
......@@ -8,10 +8,15 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NavalWar.DAL\NavalWar.DAL.csproj" />
<ProjectReference Include="..\NavalWar.DTO\NavalWar.DTO.csproj" />
<ProjectReference Include="..\NavalWar.Utils\NavalWar.Utils.csproj" />
</ItemGroup>
......
using Microsoft.EntityFrameworkCore;
using NavalWar.DAL;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
......@@ -6,6 +9,8 @@ builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddDbContext<NavalContext>(options => options.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=NavalWarDB;Trusted_Connection=True;MultipleActiveResultSets=true"));
var app = builder.Build();
......@@ -23,3 +28,4 @@ app.UseAuthorization();
app.MapControllers();
app.Run();
using NavalWar.DTO;
using NavalWar.DTO.WebDTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace NavalWar.DAL
{
public static class Extension
{
public static NavalWar.DTO.Player toDTO(this Player j){
return new NavalWar.DTO.Player() { _id=j._id,_name=j._name};
}
}
}
namespace NavalWar.DAL
{
public interface ISessionRepository
{
}
}
\ No newline at end of file
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using NavalWar.DAL;
#nullable disable
namespace NavalWar.DAL.Migrations
{
[DbContext(typeof(NavalContext))]
[Migration("20230127142630_init")]
partial class init
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.2")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("NavalWar.DAL.Player", b =>
{
b.Property<int>("_id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("_id"));
b.Property<int?>("SessionID")
.HasColumnType("int");
b.Property<string>("_name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("_id");
b.HasIndex("SessionID");
b.ToTable("Player", (string)null);
});
modelBuilder.Entity("NavalWar.DAL.Session", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<int>("Joueur1_id")
.HasColumnType("int");
b.Property<int>("Joueur2_id")
.HasColumnType("int");
b.HasKey("ID");
b.HasIndex("Joueur1_id");
b.HasIndex("Joueur2_id");
b.ToTable("Session", (string)null);
});
modelBuilder.Entity("NavalWar.DAL.Player", b =>
{
b.HasOne("NavalWar.DAL.Session", null)
.WithMany()
.HasForeignKey("SessionID");
});
modelBuilder.Entity("NavalWar.DAL.Session", b =>
{
b.HasOne("NavalWar.DAL.Player", "Joueur1")
.WithMany()
.HasForeignKey("Joueur1_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("NavalWar.DAL.Player", "Joueur2")
.WithMany()
.HasForeignKey("Joueur2_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Joueur1");
b.Navigation("Joueur2");
});
#pragma warning restore 612, 618
}
}
}
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace NavalWar.DAL.Migrations
{
/// <inheritdoc />
public partial class init : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Player",
columns: table => new
{
id = table.Column<int>(name: "_id", type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
name = table.Column<string>(name: "_name", type: "nvarchar(max)", nullable: false),
SessionID = table.Column<int>(type: "int", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Player", x => x.id);
});
migrationBuilder.CreateTable(
name: "Session",
columns: table => new
{
ID = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Joueur1id = table.Column<int>(name: "Joueur1_id", type: "int", nullable: false),
Joueur2id = table.Column<int>(name: "Joueur2_id", type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Session", x => x.ID);
table.ForeignKey(
name: "FK_Session_Player_Joueur1_id",
column: x => x.Joueur1id,
principalTable: "Player",
principalColumn: "_id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Session_Player_Joueur2_id",
column: x => x.Joueur2id,
principalTable: "Player",
principalColumn: "_id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Player_SessionID",
table: "Player",
column: "SessionID");
migrationBuilder.CreateIndex(
name: "IX_Session_Joueur1_id",
table: "Session",
column: "Joueur1_id");
migrationBuilder.CreateIndex(
name: "IX_Session_Joueur2_id",
table: "Session",
column: "Joueur2_id");
migrationBuilder.AddForeignKey(
name: "FK_Player_Session_SessionID",
table: "Player",
column: "SessionID",
principalTable: "Session",
principalColumn: "ID");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Player_Session_SessionID",
table: "Player");
migrationBuilder.DropTable(
name: "Session");
migrationBuilder.DropTable(
name: "Player");
}
}
}
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using NavalWar.DAL;
#nullable disable
namespace NavalWar.DAL.Migrations
{
[DbContext(typeof(NavalContext))]
partial class NavalContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.2")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("NavalWar.DAL.Player", b =>
{
b.Property<int>("_id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("_id"));
b.Property<int?>("SessionID")
.HasColumnType("int");
b.Property<string>("_name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("_id");
b.HasIndex("SessionID");
b.ToTable("Player", (string)null);
});
modelBuilder.Entity("NavalWar.DAL.Session", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<int>("Joueur1_id")
.HasColumnType("int");
b.Property<int>("Joueur2_id")
.HasColumnType("int");
b.HasKey("ID");
b.HasIndex("Joueur1_id");
b.HasIndex("Joueur2_id");
b.ToTable("Session", (string)null);
});
modelBuilder.Entity("NavalWar.DAL.Player", b =>
{
b.HasOne("NavalWar.DAL.Session", null)
.WithMany()
.HasForeignKey("SessionID");
});
modelBuilder.Entity("NavalWar.DAL.Session", b =>
{
b.HasOne("NavalWar.DAL.Player", "Joueur1")
.WithMany()
.HasForeignKey("Joueur1_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("NavalWar.DAL.Player", "Joueur2")
.WithMany()
.HasForeignKey("Joueur2_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Joueur1");
b.Navigation("Joueur2");
});
#pragma warning restore 612, 618
}
}
}
......@@ -9,5 +9,23 @@ namespace NavalWar.DAL
{
public class NavalContext : DbContext
{
public NavalContext(DbContextOptions<NavalContext> options):base(options) {
}
public DbSet<Player> Joueurs { get; set; }
public DbSet<Session> Sessions { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Player>()
.ToTable("Player")
.HasOne(b => b.Session);
modelBuilder.Entity<Session>()
.ToTable("Session")
.HasMany(p=>p.joueurs);
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
 <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.2">
<PrivateAssets>all</PrivateAssets>
......
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NavalWar.DTO;
namespace NavalWar.DAL
{
internal class Player
public class Player
{
[Key]
private string[,] _personalBoard = new string[_boardSize, _boardSize];
private string[,] _shotsBoard = new string[_boardSize, _boardSize];
private List<Navire> _listNavire = new List<Navire>(5);
public int _id { get; set; }
public string _name { get; set; }
public int SessionId { get; set; }
public Session Session { get; set; }
}
}
using NavalWar.DTO;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Reflection.Metadata.Ecma335;
using System.Text;
using System.Threading.Tasks;
namespace NavalWar.DAL
{
public class Session
{
[Key]
public int ID { get; set; }
public List<Player> joueurs { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NavalWar.DTO;
using NavalWar.DTO.WebDTO;
namespace NavalWar.DAL
{
public class SessionRepository : ISessionRepository
{
private readonly NavalContext _context;
public SessionRepository(NavalContext context)
{
_context = context;
}
public NavalWar.DTO.SessionDTO GetSession(int id)
{
try
{
Session session = _context.Sessions.FirstOrDefault(x => x.ID == id);
SessionDTO s = new SessionDTO { id= session.ID };
foreach(Player p in session.joueurs)
{
PlayerDTO po= new PlayerDTO() {_id=p._id,_name=p._name };
s.joueurs.Add(po);
}
return s;
}
catch(Exception) {
throw;
}
}
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
namespace NavalWar.DTO
{
......@@ -20,6 +14,9 @@ namespace NavalWar.DTO
private string[,] _personalBoard = new string[_boardSize,_boardSize];
private string[,] _shotsBoard = new string[_boardSize,_boardSize];
private List<Navire> _listNavire = new List<Navire>(5);
public string _name { get; set; }
public int _id { get; set; }
public Player()
{
......
using NavalWar.DTO.WebDTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NavalWar.DTO
{
public class SessionDTO
{
public List<PlayerDTO> joueurs= new List<PlayerDTO>();
public int id { get; set; }
}
}
......@@ -9,9 +9,13 @@ namespace NavalWar.DTO.WebDTO
public class PlayerDTO
{
public int _id { get; set; }
public string _name { get; set; }
public List<List<string>> ShipBoard { get; set; }
public List<List<string>> ShotBoard { get; set; }
}
}
{
"profiles": {
"NavalWar.Utils": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:57779;http://localhost:57780"
}
}
}
\ No newline at end of file
......@@ -3,11 +3,13 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33122.133
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NavalWar.API", "NavalWar.API\NavalWar.API.csproj", "{627C0168-119E-45FA-896E-47DC2CA0EDB5}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NavalWar.API", "NavalWar.API\NavalWar.API.csproj", "{627C0168-119E-45FA-896E-47DC2CA0EDB5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NavalWar.DTO", "NavalWar.DTO\NavalWar.DTO.csproj", "{5547977F-19B4-48D7-8D02-0A8A1A90AD2F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NavalWar.DTO", "NavalWar.DTO\NavalWar.DTO.csproj", "{5547977F-19B4-48D7-8D02-0A8A1A90AD2F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NavalWar.Utils", "NavalWar.Utils\NavalWar.Utils.csproj", "{6949C2A8-E479-49B6-84D8-C946874D7623}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NavalWar.Utils", "NavalWar.Utils\NavalWar.Utils.csproj", "{6949C2A8-E479-49B6-84D8-C946874D7623}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NavalWar.DAL", "NavalWar.DAL\NavalWar.DAL.csproj", "{806E9258-F4B3-45E6-A9F4-1D7090DCE9FE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
......@@ -27,6 +29,10 @@ Global
{6949C2A8-E479-49B6-84D8-C946874D7623}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6949C2A8-E479-49B6-84D8-C946874D7623}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6949C2A8-E479-49B6-84D8-C946874D7623}.Release|Any CPU.Build.0 = Release|Any CPU
{806E9258-F4B3-45E6-A9F4-1D7090DCE9FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{806E9258-F4B3-45E6-A9F4-1D7090DCE9FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{806E9258-F4B3-45E6-A9F4-1D7090DCE9FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{806E9258-F4B3-45E6-A9F4-1D7090DCE9FE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment