diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/API_LoL_Project.csproj b/EntityFramework_LoL/Sources/API_LoL_Project/API_LoL_Project.csproj index f7057e6..1df2c4a 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/API_LoL_Project.csproj +++ b/EntityFramework_LoL/Sources/API_LoL_Project/API_LoL_Project.csproj @@ -14,6 +14,7 @@ + diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs index 48775fc..ce3fe29 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs @@ -4,7 +4,6 @@ using DTO; using Microsoft.AspNetCore.Mvc; using Model; using StubLib; -using System.Text.Json; using System.Xml.Linq; // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 @@ -43,9 +42,9 @@ namespace API_LoL_Project.Controllers return BadRequest("No chamions found with Id "); } _logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request);; - var champions = await dataManager.GetItems(request.PageNumber, totalcount, request.orderingPropertyName, (request.descending == null ? false : (bool)request.descending)); - IEnumerable res = champions.Select(c => c.toDTO()); - if (res.Count() >= 0 || res == null) + var champions = await dataManager.GetItems(request.index, request.count, request.orderingPropertyName, request.descending); + IEnumerable res = champions.Select(c => c.ToDTO()); + if (res.Count() <= 0 || res == null) { _logger.LogWarning("No chamions found with Id"); return BadRequest("No chamions found with Id "); @@ -73,7 +72,7 @@ namespace API_LoL_Project.Controllers var champion = await dataManager .GetItemsByName(name, 0, await dataManager.GetNbItems()); _logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsByName), name); - ChampionDTO res = champion.First().toDTO(); + ChampionDTO res = champion.First().ToDTO(); if (res == null) { _logger.LogWarning("No chamions found with {name}", name); ; @@ -96,7 +95,7 @@ namespace API_LoL_Project.Controllers { try { - var newChampion = value.toModel(); + var newChampion = value.ToModel(); await dataManager.AddItem(newChampion); return CreatedAtAction(nameof(Get), newChampion) ; } @@ -118,7 +117,7 @@ namespace API_LoL_Project.Controllers { var champion = await dataManager .GetItemsByName(name, 0, await dataManager.GetNbItems()); - await dataManager.UpdateItem(champion.First(), value.toModel()); + await dataManager.UpdateItem(champion.First(), value.ToModel()); return Ok(); } catch(Exception e) diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Request/PageRequest.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Request/PageRequest.cs index 1950fa3..d4b5580 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Request/PageRequest.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Request/PageRequest.cs @@ -2,28 +2,9 @@ { public class PageRequest { - //max leght public string? orderingPropertyName { get; set; } = null; - public bool? descending { get; set; } = false; - const int maxPageSize = 50; - public int PageNumber { get; set; } = 1; - + public bool descending { get; set; } = false; public int index { get; set; } = 1; public int count { get; set; } = 1; - - - //max lentght - private int _pageSize; - public int PageSize - { - get - { - return _pageSize; - } - set - { - _pageSize = (value > maxPageSize) ? maxPageSize : value; - } - } } } diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RuneController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RuneController.cs index 7b9a2f2..f22363b 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RuneController.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RuneController.cs @@ -12,7 +12,7 @@ namespace API_LoL_Project.Controllers [ApiController] public class RuneController : ControllerBase { - public IRunesManager runesManager; + /*public IRunesManager runesManager; // you should create a custom logger to be prety private readonly ILogger _logger; @@ -26,7 +26,7 @@ namespace API_LoL_Project.Controllers - /*// GET: api/ + *//*// GET: api/ [HttpGet] public async Task> Get() { @@ -42,7 +42,7 @@ namespace API_LoL_Project.Controllers return BadRequest(e.Message); } - }*/ + }*//* // GET: api/ [HttpGet] @@ -127,6 +127,6 @@ namespace API_LoL_Project.Controllers [HttpDelete("{id}")] public void Delete(int id) { - } + }*/ } } diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RunePageController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RunePageController.cs index 2d0934b..76a0d96 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RunePageController.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RunePageController.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Mvc; +using DTO; +using Microsoft.AspNetCore.Mvc; // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 @@ -8,7 +9,7 @@ namespace API_LoL_Project.Controllers [ApiController] public class RunePageController : ControllerBase { - // GET: api/ +/* // GET: api/ [HttpGet] public async Task>> Get([FromQuery] Request.PageRequest request) { @@ -65,6 +66,6 @@ namespace API_LoL_Project.Controllers [HttpDelete("{id}")] public void Delete(int id) { - } + }*/ } } diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkillController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkillController.cs index 950897f..042bc7e 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkillController.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkillController.cs @@ -8,7 +8,7 @@ namespace API_LoL_Project.Controllers [ApiController] public class SkillController : ControllerBase { - // GET: api/ + /* // GET: api/ [HttpGet] public async Task>> Get([FromQuery] Request.PageRequest request) { @@ -65,6 +65,6 @@ namespace API_LoL_Project.Controllers [HttpDelete("{id}")] public void Delete(int id) { - } + }*/ } } diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkinController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkinController.cs index db11f8d..fa3ddfd 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkinController.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkinController.cs @@ -8,7 +8,7 @@ namespace API_LoL_Project.Controllers [ApiController] public class SkinController : ControllerBase { - // GET: api/ + /* // GET: api/ [HttpGet] public async Task>> Get([FromQuery] Request.PageRequest request) { @@ -65,6 +65,6 @@ namespace API_LoL_Project.Controllers [HttpDelete("{id}")] public void Delete(int id) { - } + }*/ } } diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db b/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db new file mode 100644 index 0000000..81dae89 Binary files /dev/null and b/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db differ diff --git a/EntityFramework_LoL/Sources/EntityFramework/EntityFramework.Champions.db-shm b/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db-shm similarity index 92% rename from EntityFramework_LoL/Sources/EntityFramework/EntityFramework.Champions.db-shm rename to EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db-shm index fe9ac28..fbf3991 100644 Binary files a/EntityFramework_LoL/Sources/EntityFramework/EntityFramework.Champions.db-shm and b/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db-shm differ diff --git a/EntityFramework_LoL/Sources/Entities/Entities.Champions.db b/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db-wal similarity index 88% rename from EntityFramework_LoL/Sources/Entities/Entities.Champions.db rename to EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db-wal index 9ee7a58..ea04235 100644 Binary files a/EntityFramework_LoL/Sources/Entities/Entities.Champions.db and b/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db-wal differ diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs index a7c1e89..15f2889 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs @@ -43,10 +43,9 @@ namespace API_LoL_Project.Mapper { Name = item.Name, Bio = item.Bio, - Characteristics = item.Characteristics, skills = item.Skills, skins = item.Skins, - LargeImage = item.Image + LargeImage = item.Image.Base64 }; diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RuneMapper.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RuneMapper.cs index 3b2b752..8c6d64a 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RuneMapper.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RuneMapper.cs @@ -1,27 +1,31 @@ namespace API_LoL_Project.Mapper { using DTO; - using Entities; using Model; namespace API_LoL_Project.Mapper { public static class RuneMapper { - public static RuneEntity ToEntity(this Rune item) + public static RuneDTO ToDTO(this Rune item) { - throw new NotImplementedException(); - } + return new RuneDTO() + { + Name = item.Name, + Family = item.Family, + }; + } - public static Rune ToModel(this RuneEntity entity) + public static Rune ToModel(this RuneDTO dto) { - throw new NotImplementedException(); - + /*if (dto == null) + { + *//* var message = string.Format("Champion with name = {} not found", dto.Name); + throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message));*//* + }*/ + return new Rune(dto.Name, dto.Family); } - } } } - -} diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RunePageMapper.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RunePageMapper.cs index 611ed6e..9a15c1e 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RunePageMapper.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RunePageMapper.cs @@ -5,15 +5,6 @@ namespace API_LoL_Project.Mapper { public static class RunePageMapper { - public static RunePageEntity ToEntity(this RunePage item) - { - throw new NotImplementedException(); - } - public static RunePage ToModel(this RunePageEntity entity) - { - throw new NotImplementedException(); - - } } } diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RunesMappeur.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RunesMappeur.cs deleted file mode 100644 index 18e23d6..0000000 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RunesMappeur.cs +++ /dev/null @@ -1,29 +0,0 @@ -using DTO; -using Model; - -namespace API_LoL_Project.Mapper -{ - public static class RunesMappeur - { - public static RuneDTO toDTO(this Rune item) - { - - return new RuneDTO() - { - Name = item.Name, - Family = item.Family, - }; - } - - public static Rune toModel(this RuneDTO dto) - { - /*if (dto == null) - { - *//* var message = string.Format("Champion with name = {} not found", dto.Name); - throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message));*//* - }*/ - return new Rune(dto.Name, dto.Family); - } - - } -} diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/SkinMapper.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/SkinMapper.cs index ad5a96b..e658fc3 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/SkinMapper.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/SkinMapper.cs @@ -6,18 +6,8 @@ namespace API_LoL_Project.Mapper { public static class SkinMapper { - public static SkinEntity ToEntity(this Skin item) - { - throw new NotImplementedException(); - } - public static Skin ToModel(this SkinEntity entity) - { - throw new NotImplementedException(); - - } - } } -} + diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Program.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Program.cs index 79eb2d3..68e54ad 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Program.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Program.cs @@ -1,31 +1,38 @@ +using Business; +using Entities; +using Microsoft.EntityFrameworkCore; using Model; using StubLib; -var builder = WebApplication.CreateBuilder(args); - -// Add services to the container. - -builder.Services.AddControllers(); -// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle -builder.Services.AddEndpointsApiExplorer(); -builder.Services.AddSwaggerGen(); - -builder.Services.AddSingleton(); -var app = builder.Build(); - - -// Configure the HTTP request pipeline. -if (app.Environment.IsDevelopment()) -{ - app.UseSwagger(); - app.UseSwaggerUI(); -} - -app.UseHttpsRedirection(); - -app.UseAuthorization(); - -app.MapControllers(); - - -app.Run(); +var builder = WebApplication.CreateBuilder(args); + +var connectionString = builder.Configuration.GetConnectionString("LolDatabase"); +builder.Services.AddDbContext(options => + options.UseSqlite(connectionString), ServiceLifetime.Singleton); + +builder.Services.AddControllers(); +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +builder.Services.AddSingleton(); +//builder.Services.AddSingleton(); + +var app = builder.Build(); + +app?.Services?.GetService()?.Database.EnsureCreated(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + + +app.Run(); diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/appsettings.Development.json b/EntityFramework_LoL/Sources/API_LoL_Project/appsettings.Development.json index 0c208ae..c64007f 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/appsettings.Development.json +++ b/EntityFramework_LoL/Sources/API_LoL_Project/appsettings.Development.json @@ -4,5 +4,8 @@ "Default": "Information", "Microsoft.AspNetCore": "Warning" } + }, + "ConnectionStrings": { + "LolDatabase": "Data Source=Entities.LolDatabase.db" } } diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/appsettings.Production.json b/EntityFramework_LoL/Sources/API_LoL_Project/appsettings.Production.json new file mode 100644 index 0000000..c64007f --- /dev/null +++ b/EntityFramework_LoL/Sources/API_LoL_Project/appsettings.Production.json @@ -0,0 +1,11 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "ConnectionStrings": { + "LolDatabase": "Data Source=Entities.LolDatabase.db" + } +} diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/appsettings.json b/EntityFramework_LoL/Sources/API_LoL_Project/appsettings.json index 10f68b8..064a744 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/appsettings.json +++ b/EntityFramework_LoL/Sources/API_LoL_Project/appsettings.json @@ -5,5 +5,8 @@ "Microsoft.AspNetCore": "Warning" } }, + "ConnectionStrings": { + "LolDatabase": "Data Source=Entities.LolDatabase.db" + }, "AllowedHosts": "*" } diff --git a/EntityFramework_LoL/Sources/Business/Business.csproj b/EntityFramework_LoL/Sources/Business/Business.csproj index ac7fce7..a8d9633 100644 --- a/EntityFramework_LoL/Sources/Business/Business.csproj +++ b/EntityFramework_LoL/Sources/Business/Business.csproj @@ -7,8 +7,8 @@ - + diff --git a/EntityFramework_LoL/Sources/Business/DbData.Champions.cs b/EntityFramework_LoL/Sources/Business/DbData.Champions.cs index 0c31b3f..c768c6c 100644 --- a/EntityFramework_LoL/Sources/Business/DbData.Champions.cs +++ b/EntityFramework_LoL/Sources/Business/DbData.Champions.cs @@ -1,7 +1,6 @@ -using API_LoL_Project.Mapper; +using EntityMapper; using Model; using Shared; -using System.Data.SqlTypes; namespace Business { @@ -28,6 +27,7 @@ namespace Business public async Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) { + Console.WriteLine("GET"); return parent.DbContext.champions.GetItemsWithFilterAndOrdering( c => true, index, count, diff --git a/EntityFramework_LoL/Sources/Business/DbData.RunePages.cs b/EntityFramework_LoL/Sources/Business/DbData.RunePages.cs index 3de4937..0601236 100644 --- a/EntityFramework_LoL/Sources/Business/DbData.RunePages.cs +++ b/EntityFramework_LoL/Sources/Business/DbData.RunePages.cs @@ -1,7 +1,5 @@ -using API_LoL_Project.Mapper; +using EntityMapper; using Model; -using System.Data.SqlTypes; -using System.Linq; namespace Business { diff --git a/EntityFramework_LoL/Sources/Business/DbData.Runes.cs b/EntityFramework_LoL/Sources/Business/DbData.Runes.cs index 9c97b23..3b827e1 100644 --- a/EntityFramework_LoL/Sources/Business/DbData.Runes.cs +++ b/EntityFramework_LoL/Sources/Business/DbData.Runes.cs @@ -1,5 +1,4 @@ -using API_LoL_Project.Mapper; -using API_LoL_Project.Mapper.API_LoL_Project.Mapper; +using EntityMapper; using Model; using Shared; diff --git a/EntityFramework_LoL/Sources/Business/DbData.Skins.cs b/EntityFramework_LoL/Sources/Business/DbData.Skins.cs index 47b7ada..07abf34 100644 --- a/EntityFramework_LoL/Sources/Business/DbData.Skins.cs +++ b/EntityFramework_LoL/Sources/Business/DbData.Skins.cs @@ -1,7 +1,5 @@ -using API_LoL_Project.Mapper; -using API_LoL_Project.Mapper.API_LoL_Project.Mapper; +using EntityMapper; using Model; -using System.Data.SqlTypes; namespace Business { diff --git a/EntityFramework_LoL/Sources/Business/DbData.cs b/EntityFramework_LoL/Sources/Business/DbData.cs index 99c30e9..f983819 100644 --- a/EntityFramework_LoL/Sources/Business/DbData.cs +++ b/EntityFramework_LoL/Sources/Business/DbData.cs @@ -6,7 +6,6 @@ namespace Business { public partial class DbData : IDataManager { - public DbData(LolDbContext dbContext) { DbContext = dbContext; @@ -15,6 +14,7 @@ namespace Business RunesMgr = new RunesManager(this); RunePagesMgr = new RunePagesManager(this); } + protected LolDbContext DbContext{ get; } public IChampionsManager ChampionsMgr { get; } diff --git a/EntityFramework_LoL/Sources/Business/Extensions.cs b/EntityFramework_LoL/Sources/Business/Extensions.cs index 9f99257..ac81eaa 100644 --- a/EntityFramework_LoL/Sources/Business/Extensions.cs +++ b/EntityFramework_LoL/Sources/Business/Extensions.cs @@ -22,7 +22,7 @@ namespace Business : temp.OrderBy(item => prop.GetValue(item)); } } - return temp.Skip(index * count).Take(count) + return temp.Skip(index * count).Take(count); } } } diff --git a/EntityFramework_LoL/Sources/DTO/ChampionDTO.cs b/EntityFramework_LoL/Sources/DTO/ChampionDTO.cs index 5d0e9f6..0f77a48 100644 --- a/EntityFramework_LoL/Sources/DTO/ChampionDTO.cs +++ b/EntityFramework_LoL/Sources/DTO/ChampionDTO.cs @@ -1,4 +1,5 @@ using Model; +using System.Buffers.Text; namespace DTO { @@ -14,7 +15,7 @@ namespace DTO public string Name { get; set; } public string Bio { get; set; } public string Characteristics { get; set; } - public byte[] LargeImage { get; set; } + public string LargeImage { get; set; } public IEnumerable skins { get; set; } public IEnumerable skills { get; set; } diff --git a/EntityFramework_LoL/Sources/DTO/RuneDTO.cs b/EntityFramework_LoL/Sources/DTO/RuneDTO.cs index 495f618..f0a5d4f 100644 --- a/EntityFramework_LoL/Sources/DTO/RuneDTO.cs +++ b/EntityFramework_LoL/Sources/DTO/RuneDTO.cs @@ -1,4 +1,5 @@ using Model; +using Shared; using System; using System.Collections.Generic; using System.Linq; diff --git a/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-shm b/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-shm deleted file mode 100644 index 927dd66..0000000 Binary files a/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-shm and /dev/null differ diff --git a/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-wal b/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-wal deleted file mode 100644 index 50a0bc3..0000000 Binary files a/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-wal and /dev/null differ diff --git a/EntityFramework_LoL/Sources/Entities/LolDbContext.cs b/EntityFramework_LoL/Sources/Entities/LolDbContext.cs index 52795fd..c2bcad4 100644 --- a/EntityFramework_LoL/Sources/Entities/LolDbContext.cs +++ b/EntityFramework_LoL/Sources/Entities/LolDbContext.cs @@ -1,4 +1,5 @@ using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; using Shared; using System.Reflection.Metadata; using System.Security.Claims; @@ -15,11 +16,14 @@ namespace Entities public DbSet runes { get; set; } public DbSet runepages { get; set; } public DbSet largeimages { get; set; } - + public LolDbContext(DbContextOptions configuration) : base(configuration){} protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlite($"Data Source=Entities.Champions.db"); + if (!optionsBuilder.IsConfigured) { + Console.WriteLine("!IsConfigured..."); + optionsBuilder.UseSqlite($"Data Source=Entities.Champions.db"); + } } protected override void OnModelCreating(ModelBuilder modelBuilder) diff --git a/EntityFramework_LoL/Sources/Entities/Program.cs b/EntityFramework_LoL/Sources/Entities/Program.cs index 13fdf1b..61929c4 100644 --- a/EntityFramework_LoL/Sources/Entities/Program.cs +++ b/EntityFramework_LoL/Sources/Entities/Program.cs @@ -7,7 +7,7 @@ ChampionEntity imri = new() Bio = "Fou Furieux", Class = ChampionClass.Assassin }; -using (var context = new LolDbContext()) +using (var context = new LolDbContext(null)) { // Crée des nounours et les insère dans la base Console.WriteLine("Creates and inserts new Champion"); diff --git a/EntityFramework_LoL/Sources/EntityFramework/DbContexts/ChampionDbContext.cs b/EntityFramework_LoL/Sources/EntityFramework/DbContexts/ChampionDbContext.cs deleted file mode 100644 index 532648c..0000000 --- a/EntityFramework_LoL/Sources/EntityFramework/DbContexts/ChampionDbContext.cs +++ /dev/null @@ -1,19 +0,0 @@ -using EntityFramework.Entities; -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace EntityFramework.DbContexts -{ - internal class ChampionDbContext : DbContext - { - public DbSet champions { get; set; } - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - optionsBuilder.UseSqlite($"Data Source=EntityFramework.Champions.db"); - } - } -} diff --git a/EntityFramework_LoL/Sources/EntityFramework/Entities/ChampionEntity.cs b/EntityFramework_LoL/Sources/EntityFramework/Entities/ChampionEntity.cs deleted file mode 100644 index 631bfca..0000000 --- a/EntityFramework_LoL/Sources/EntityFramework/Entities/ChampionEntity.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.ComponentModel.DataAnnotations; - -namespace EntityFramework.Entities -{ - internal class ChampionEntity - { - [Key] - [MaxLength(256)] - public string Name { get; set; } - [Required] - [MaxLength(500)] - public string Bio { get; set; } - [Required] - public string Icon { get; set; } - - } -} diff --git a/EntityFramework_LoL/Sources/EntityFramework/EntityFramework.Champions.db b/EntityFramework_LoL/Sources/EntityFramework/EntityFramework.Champions.db deleted file mode 100644 index 2643996..0000000 Binary files a/EntityFramework_LoL/Sources/EntityFramework/EntityFramework.Champions.db and /dev/null differ diff --git a/EntityFramework_LoL/Sources/EntityFramework/EntityFramework.Champions.db-wal b/EntityFramework_LoL/Sources/EntityFramework/EntityFramework.Champions.db-wal deleted file mode 100644 index e531c0b..0000000 Binary files a/EntityFramework_LoL/Sources/EntityFramework/EntityFramework.Champions.db-wal and /dev/null differ diff --git a/EntityFramework_LoL/Sources/EntityFramework/EntityFramework.csproj b/EntityFramework_LoL/Sources/EntityFramework/EntityFramework.csproj deleted file mode 100644 index 95f8b96..0000000 --- a/EntityFramework_LoL/Sources/EntityFramework/EntityFramework.csproj +++ /dev/null @@ -1,30 +0,0 @@ - - - - Exe - net6.0 - enable - enable - $(MSBuildProjectDirectory) - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - diff --git a/EntityFramework_LoL/Sources/EntityFramework/Migrations/20230201154310_migr.Designer.cs b/EntityFramework_LoL/Sources/EntityFramework/Migrations/20230201154310_migr.Designer.cs deleted file mode 100644 index 7d92db0..0000000 --- a/EntityFramework_LoL/Sources/EntityFramework/Migrations/20230201154310_migr.Designer.cs +++ /dev/null @@ -1,44 +0,0 @@ -// -using EntityFramework.DbContexts; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace EntityFramework.Migrations -{ - [DbContext(typeof(ChampionDbContext))] - [Migration("20230201154310_migr")] - partial class migr - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - - modelBuilder.Entity("EntityFramework.Entities.ChampionEntity", b => - { - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("TEXT"); - - b.Property("Bio") - .IsRequired() - .HasMaxLength(500) - .HasColumnType("TEXT"); - - b.Property("Icon") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Name"); - - b.ToTable("champions"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/EntityFramework_LoL/Sources/EntityFramework/Migrations/20230201154310_migr.cs b/EntityFramework_LoL/Sources/EntityFramework/Migrations/20230201154310_migr.cs deleted file mode 100644 index adfed99..0000000 --- a/EntityFramework_LoL/Sources/EntityFramework/Migrations/20230201154310_migr.cs +++ /dev/null @@ -1,34 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace EntityFramework.Migrations -{ - /// - public partial class migr : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "champions", - columns: table => new - { - Name = table.Column(type: "TEXT", maxLength: 256, nullable: false), - Bio = table.Column(type: "TEXT", maxLength: 500, nullable: false), - Icon = table.Column(type: "TEXT", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_champions", x => x.Name); - }); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "champions"); - } - } -} diff --git a/EntityFramework_LoL/Sources/EntityFramework/Migrations/20230209124258_myFirstMigration.Designer.cs b/EntityFramework_LoL/Sources/EntityFramework/Migrations/20230209124258_myFirstMigration.Designer.cs deleted file mode 100644 index b64a1d8..0000000 --- a/EntityFramework_LoL/Sources/EntityFramework/Migrations/20230209124258_myFirstMigration.Designer.cs +++ /dev/null @@ -1,44 +0,0 @@ -// -using EntityFramework.DbContexts; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace EntityFramework.Migrations -{ - [DbContext(typeof(ChampionDbContext))] - [Migration("20230209124258_myFirstMigration")] - partial class myFirstMigration - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - - modelBuilder.Entity("EntityFramework.Entities.ChampionEntity", b => - { - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("TEXT"); - - b.Property("Bio") - .IsRequired() - .HasMaxLength(500) - .HasColumnType("TEXT"); - - b.Property("Icon") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Name"); - - b.ToTable("champions"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/EntityFramework_LoL/Sources/EntityFramework/Migrations/20230209124258_myFirstMigration.cs b/EntityFramework_LoL/Sources/EntityFramework/Migrations/20230209124258_myFirstMigration.cs deleted file mode 100644 index 9f3f929..0000000 --- a/EntityFramework_LoL/Sources/EntityFramework/Migrations/20230209124258_myFirstMigration.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace EntityFramework.Migrations -{ - /// - public partial class myFirstMigration : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - - } - } -} diff --git a/EntityFramework_LoL/Sources/EntityFramework/Migrations/ChampionDbContextModelSnapshot.cs b/EntityFramework_LoL/Sources/EntityFramework/Migrations/ChampionDbContextModelSnapshot.cs deleted file mode 100644 index 171949d..0000000 --- a/EntityFramework_LoL/Sources/EntityFramework/Migrations/ChampionDbContextModelSnapshot.cs +++ /dev/null @@ -1,41 +0,0 @@ -// -using EntityFramework.DbContexts; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace EntityFramework.Migrations -{ - [DbContext(typeof(ChampionDbContext))] - partial class ChampionDbContextModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - - modelBuilder.Entity("EntityFramework.Entities.ChampionEntity", b => - { - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("TEXT"); - - b.Property("Bio") - .IsRequired() - .HasMaxLength(500) - .HasColumnType("TEXT"); - - b.Property("Icon") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Name"); - - b.ToTable("champions"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/EntityFramework_LoL/Sources/EntityFramework/Program.cs b/EntityFramework_LoL/Sources/EntityFramework/Program.cs deleted file mode 100644 index 8772279..0000000 --- a/EntityFramework_LoL/Sources/EntityFramework/Program.cs +++ /dev/null @@ -1,17 +0,0 @@ -using EntityFramework.DbContexts; -using EntityFramework.Entities; -using Model; - -ChampionEntity dave = new ChampionEntity() -{ - Name = "Dave", - Bio = "Le meilleur Jazzman de France", - Icon = "aaa" -}; -using (var context = new ChampionDbContext()) -{ - // Crée des nounours et les insère dans la base - Console.WriteLine("Creates and inserts new Champion"); - context.Add(dave); - context.SaveChanges(); -} diff --git a/EntityFramework_LoL/Sources/EntityMappers/ChampionMapper.cs b/EntityFramework_LoL/Sources/EntityMappers/ChampionMapper.cs new file mode 100644 index 0000000..fe54594 --- /dev/null +++ b/EntityFramework_LoL/Sources/EntityMappers/ChampionMapper.cs @@ -0,0 +1,26 @@ +using Entities; +using Model; + +namespace EntityMapper +{ + public static class ChampionMapper { + + public static ChampionEntity ToEntity(this Champion item) + { + return new() + { + Name = item.Name, + Bio = item.Bio, + Icon = item.Icon, + Class = item.Class, + Image = new() { Base64 = item.Image.Base64 }, + }; + } + + public static Champion ToModel(this ChampionEntity entity) + { + return new(entity.Name, entity.Class, entity.Icon, "", entity.Bio); + } + + } +} diff --git a/EntityFramework_LoL/Sources/EntityMappers/EntityMappers.csproj b/EntityFramework_LoL/Sources/EntityMappers/EntityMappers.csproj new file mode 100644 index 0000000..440d174 --- /dev/null +++ b/EntityFramework_LoL/Sources/EntityMappers/EntityMappers.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/EntityFramework_LoL/Sources/EntityMappers/RuneMapper.cs b/EntityFramework_LoL/Sources/EntityMappers/RuneMapper.cs new file mode 100644 index 0000000..05c8bf2 --- /dev/null +++ b/EntityFramework_LoL/Sources/EntityMappers/RuneMapper.cs @@ -0,0 +1,23 @@ +using Entities; +using Model; + +namespace EntityMapper +{ + public static class RuneMapper + { + public static RuneEntity ToEntity(this Rune item) + { + throw new NotImplementedException(); + } + + + public static Rune ToModel(this RuneEntity entity) + { + throw new NotImplementedException(); + + } + + } +} + + diff --git a/EntityFramework_LoL/Sources/EntityMappers/RunePageMapper.cs b/EntityFramework_LoL/Sources/EntityMappers/RunePageMapper.cs new file mode 100644 index 0000000..8044010 --- /dev/null +++ b/EntityFramework_LoL/Sources/EntityMappers/RunePageMapper.cs @@ -0,0 +1,19 @@ +using Entities; +using Model; + +namespace EntityMapper +{ + public static class RunePageMapper + { + public static RunePageEntity ToEntity(this RunePage item) + { + throw new NotImplementedException(); + } + + public static RunePage ToModel(this RunePageEntity entity) + { + throw new NotImplementedException(); + + } + } +} diff --git a/EntityFramework_LoL/Sources/EntityMappers/SkinMapper.cs b/EntityFramework_LoL/Sources/EntityMappers/SkinMapper.cs new file mode 100644 index 0000000..a5ccc39 --- /dev/null +++ b/EntityFramework_LoL/Sources/EntityMappers/SkinMapper.cs @@ -0,0 +1,21 @@ +using Entities; +using Model; + +namespace EntityMapper +{ + public static class SkinMapper + { + public static SkinEntity ToEntity(this Skin item) + { + throw new NotImplementedException(); + } + + + public static Skin ToModel(this SkinEntity entity) + { + throw new NotImplementedException(); + + } + + } +} diff --git a/EntityFramework_LoL/Sources/LeagueOfLegends.sln b/EntityFramework_LoL/Sources/LeagueOfLegends.sln index ef88d8c..8f1d4ea 100644 --- a/EntityFramework_LoL/Sources/LeagueOfLegends.sln +++ b/EntityFramework_LoL/Sources/LeagueOfLegends.sln @@ -25,7 +25,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entities", "Entities\Entiti EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test_Api", "Test_Api\Test_Api.csproj", "{C35C38F6-5774-4562-BD00-C81BCE13A260}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Business", "Business\Business.csproj", "{A447B0BE-62AE-4F66-B887-D1F3D46B0DB3}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Business", "Business\Business.csproj", "{A447B0BE-62AE-4F66-B887-D1F3D46B0DB3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityMappers", "EntityMappers\EntityMappers.csproj", "{3A70A719-4F42-4CC3-846A-53437F3B4CC5}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -61,10 +63,18 @@ Global {C463E2E1-237A-4339-A4C4-6EA3BE7002AE}.Debug|Any CPU.Build.0 = Debug|Any CPU {C463E2E1-237A-4339-A4C4-6EA3BE7002AE}.Release|Any CPU.ActiveCfg = Release|Any CPU {C463E2E1-237A-4339-A4C4-6EA3BE7002AE}.Release|Any CPU.Build.0 = Release|Any CPU + {C35C38F6-5774-4562-BD00-C81BCE13A260}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C35C38F6-5774-4562-BD00-C81BCE13A260}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C35C38F6-5774-4562-BD00-C81BCE13A260}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C35C38F6-5774-4562-BD00-C81BCE13A260}.Release|Any CPU.Build.0 = Release|Any CPU {A447B0BE-62AE-4F66-B887-D1F3D46B0DB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {A447B0BE-62AE-4F66-B887-D1F3D46B0DB3}.Debug|Any CPU.Build.0 = Debug|Any CPU {A447B0BE-62AE-4F66-B887-D1F3D46B0DB3}.Release|Any CPU.ActiveCfg = Release|Any CPU {A447B0BE-62AE-4F66-B887-D1F3D46B0DB3}.Release|Any CPU.Build.0 = Release|Any CPU + {3A70A719-4F42-4CC3-846A-53437F3B4CC5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3A70A719-4F42-4CC3-846A-53437F3B4CC5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3A70A719-4F42-4CC3-846A-53437F3B4CC5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3A70A719-4F42-4CC3-846A-53437F3B4CC5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -74,6 +84,7 @@ Global {B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB} = {2C607793-B163-4731-A4D1-AFE8A7C4C170} {C463E2E1-237A-4339-A4C4-6EA3BE7002AE} = {BC2FFCA4-3801-433F-A83E-B55345F3B31E} {A447B0BE-62AE-4F66-B887-D1F3D46B0DB3} = {BC2FFCA4-3801-433F-A83E-B55345F3B31E} + {3A70A719-4F42-4CC3-846A-53437F3B4CC5} = {BC2FFCA4-3801-433F-A83E-B55345F3B31E} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {92F3083D-793F-4552-8A9A-0AD6534159C9} diff --git a/EntityFramework_LoL/Sources/Model/Properties/launchSettings.json b/EntityFramework_LoL/Sources/Model/Properties/launchSettings.json new file mode 100644 index 0000000..de72c15 --- /dev/null +++ b/EntityFramework_LoL/Sources/Model/Properties/launchSettings.json @@ -0,0 +1,7 @@ +{ + "profiles": { + "Model": { + "commandName": "Project" + } + } +} \ No newline at end of file