console start

master
Jolys Enzo 2 years ago
parent 527eaedbf0
commit 182792d689

@ -14,46 +14,40 @@ namespace Api_lol.Controllers
{
private readonly IDataManager data;
private readonly ILogger<Champions> _logger;
private readonly ILogger<Champions> logger;
public Champions(ILogger<Champions> logger,IDataManager manager)
{
_logger = logger;
this.logger = logger;
data = manager;
}
[HttpGet]
public IActionResult Get()
public async Task<IActionResult> Get()
{
List<Champion> champs = new List<Champion>();
champs = data.ChampionsMgr.GetItems(0,6);
var champs = (await data.ChampionsMgr.GetItems(0, await data.ChampionsMgr.GetNbItems())).Select(Model => Model.ModelToDto());
return Ok(champs);
}
[HttpPost]
public IActionResult Post(DtoChampions champHttp)
public IActionResult Post(DtoChampions champDTO)
{
champ.Add(champHttp.DtoToModel());
return Ok(champ);
Champion tmp = champDTO.DtoToModel();
return Ok();
}
[HttpGet]
[Route("{name}")]
public IActionResult GetChampion(string name)
public async Task<IActionResult> GetChampion(string name)
{
foreach (var champion in data.ChampionsMgr.GetItems(0, data.ChampionsMgr.GetNbItems)
{
if (champion.Name == name)
{
return Ok(champion);
}
}
return BadRequest("Name incorrect");
var champs = (await data.ChampionsMgr.GetItems(0, await data.ChampionsMgr.GetNbItems())).Where(i => i.Name == name).First();
DtoChampions result = champs.ModelToDto();
return Ok(champs);
}
}

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\DTO\DTO.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,33 @@
using DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Json;
using System.Text;
using System.Threading.Tasks;
namespace Client
{
public class ClientChampions
{
private readonly HttpClient httpClient_client;
private readonly string urlConstant = "Champions/";
public ClientChampions(HttpClient httpClient_client)
{
this.httpClient_client = httpClient_client;
}
public async void Get()
{
await tmp = httpClient_client.GetFromJsonAsync<List<DtoChampions>(urlConstant);
return tmp;
}
public void Post(DtoChampions champions)
{
}
}
}

@ -0,0 +1,2 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");

@ -1,7 +0,0 @@
namespace DTO
{
public class Class1
{
}
}

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DTO
{
public class EntityChampions
{
public long id { get; set; }
public string name { get; set; }
}
}

@ -5,10 +5,11 @@ namespace EntityFramwork
{
public class BDDContext : DbContext
{
public BDDContext() { }
public BDDContext(DbContextOptions<BDDContext> option) : base(option) { }
public DbSet<DtoChampions> Champions { get; set; }
public DbSet<EntityChampions> Champions { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DTO
{
public class EntityChampions
{
public long id { get; set; }
public string name { get; set; }
}
}

@ -4,6 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<StartWorkingDirectory>$(MSBuildProjectDirectory)</StartWorkingDirectory>
</PropertyGroup>
<ItemGroup>

@ -0,0 +1,39 @@
// <auto-generated />
using EntityFramwork;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EntityFramwork.Migrations
{
[DbContext(typeof(BDDContext))]
[Migration("20230130130012_monNomDeMigration")]
partial class monNomDeMigration
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("DTO.EntityChampions", b =>
{
b.Property<long>("id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("name")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("id");
b.ToTable("Champions");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,34 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EntityFramwork.Migrations
{
/// <inheritdoc />
public partial class monNomDeMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Champions",
columns: table => new
{
id = table.Column<long>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
name = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Champions", x => x.id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Champions");
}
}
}

@ -0,0 +1,36 @@
// <auto-generated />
using EntityFramwork;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EntityFramwork.Migrations
{
[DbContext(typeof(BDDContext))]
partial class BDDContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("DTO.EntityChampions", b =>
{
b.Property<long>("id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("name")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("id");
b.ToTable("Champions");
});
#pragma warning restore 612, 618
}
}
}

@ -19,7 +19,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Api-lol", "Api-lol\Api-lol.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DTO", "DTO\DTO.csproj", "{35D5E576-6E1A-4B2C-8FE6-C9C9B88FC452}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFramwork", "EntityFramwork\EntityFramwork.csproj", "{2225E38B-8445-40D2-A2FE-9F90F7ACD463}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntityFramwork", "EntityFramwork\EntityFramwork.csproj", "{2225E38B-8445-40D2-A2FE-9F90F7ACD463}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client", "Client\Client.csproj", "{B1BDE539-7DC3-4DC7-A908-36119E468FA8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -55,6 +57,10 @@ Global
{2225E38B-8445-40D2-A2FE-9F90F7ACD463}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2225E38B-8445-40D2-A2FE-9F90F7ACD463}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2225E38B-8445-40D2-A2FE-9F90F7ACD463}.Release|Any CPU.Build.0 = Release|Any CPU
{B1BDE539-7DC3-4DC7-A908-36119E468FA8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B1BDE539-7DC3-4DC7-A908-36119E468FA8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B1BDE539-7DC3-4DC7-A908-36119E468FA8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B1BDE539-7DC3-4DC7-A908-36119E468FA8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

Loading…
Cancel
Save