DbManager and MAUI Done

pull/10/head
Emre KARTAL 2 years ago
parent ac20890cb6
commit cf320b341b

@ -61,9 +61,9 @@ namespace ApiLol.Controllers.v1
{
_logger.LogInformation("method {Action} - CHAMPION - V1.0 call with {name} and {item}", nameof(Put), name, champion);
var dtos = (await _manager.ChampionsMgr.GetItemByName(name, 0, await _manager.ChampionsMgr.GetNbItems()));
var champs = (await _manager.ChampionsMgr.GetItemByName(name, 0, await _manager.ChampionsMgr.GetNbItems()));
return Ok((await _manager.ChampionsMgr.UpdateItem(dtos.First(), champion.ToModel())).ToDto());
return Ok((await _manager.ChampionsMgr.UpdateItem(champs.First(), champion.ToModel())).ToDto());
}
@ -87,9 +87,9 @@ namespace ApiLol.Controllers.v1
{
_logger.LogInformation("method {Action} - CHAMPION - V1.0 call with {name}", nameof(Delete), name);
var dtos = (await _manager.ChampionsMgr.GetItemByName(name, 0, await _manager.ChampionsMgr.GetNbItems()));
var champs = (await _manager.ChampionsMgr.GetItemByName(name, 0, await _manager.ChampionsMgr.GetNbItems()));
await _manager.ChampionsMgr.DeleteItem(dtos.First());
await _manager.ChampionsMgr.DeleteItem(champs.First());
return NoContent();
}

@ -22,7 +22,7 @@ namespace DbLib
public async Task<bool> DeleteItem(Champion? item)
{
var toDelete = parent.DbContext.Champions.Find(item.Name);
var toDelete = parent.DbContext.Champions.Where(c => c.Name == item.Name).First();
if (toDelete != null)
{
parent.DbContext.Champions.Remove(toDelete);
@ -38,12 +38,12 @@ namespace DbLib
private Func<Champion, string, bool> filterByName = (champ, substring) => champ.Name.Equals(substring, StringComparison.InvariantCultureIgnoreCase);
public async Task<IEnumerable<Champion?>> GetItemByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
=> parent.DbContext.Champions.GetItemsWithFilterAndOrdering(champ => filterByName(champ.ToModel(), substring), index, count, orderingPropertyName, descending)
=> parent.DbContext.Champions.Include(c => c.Skills).Include(c => c.Characteristics).Include(c => c.Skins).Include(c => c.Image).GetItemsWithFilterAndOrdering(champ => filterByName(champ.ToModel(), substring), index, count, orderingPropertyName, descending)
.Select(c => c.ToModel());
public async Task<IEnumerable<Champion?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
=> parent.DbContext.Champions.GetItemsWithFilterAndOrdering(
=> parent.DbContext.Champions.Include(c => c.Skills).Include(c => c.Characteristics).Include(c => c.Skins).Include(c => c.Image).GetItemsWithFilterAndOrdering(
c => true,
index, count,
orderingPropertyName, descending).Select(c => c.ToModel());
@ -51,34 +51,34 @@ namespace DbLib
private Func<Champion, string, bool> filterByCharacteristic = (champ, charName) => champ.Characteristics.Keys.Any(k => k.Contains(charName, StringComparison.InvariantCultureIgnoreCase));
public async Task<IEnumerable<Champion?>> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false)
=> parent.DbContext.Champions.Include(c => c.Characteristics).GetItemsWithFilterAndOrdering(
=> parent.DbContext.Champions.Include(c => c.Skills).Include(c => c.Characteristics).Include(c => c.Skins).Include(c => c.Image).GetItemsWithFilterAndOrdering(
champ => filterByCharacteristic(champ.ToModel(), charName),
index, count, orderingPropertyName, descending).Select(c => c.ToModel());
private Func<Champion, ChampionClass, bool> filterByClass = (champ, championClass) => champ.Class == championClass;
public async Task<IEnumerable<Champion?>> GetItemsByClass(ChampionClass championClass, int index, int count, string? orderingPropertyName = null, bool descending = false)
=> parent.DbContext.Champions.GetItemsWithFilterAndOrdering(
=> parent.DbContext.Champions.Include(c => c.Skills).Include(c => c.Characteristics).Include(c => c.Skins).Include(c => c.Image).GetItemsWithFilterAndOrdering(
champ => filterByClass(champ.ToModel(), championClass),
index, count, orderingPropertyName, descending).Select(c => c.ToModel());
public async Task<IEnumerable<Champion?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
=> parent.DbContext.Champions.GetItemsWithFilterAndOrdering(champ => filterByNameContains(champ.ToModel(), substring), index, count, orderingPropertyName, descending)
=> parent.DbContext.Champions.Include(c => c.Skills).Include(c => c.Characteristics).Include(c => c.Skins).Include(c => c.Image).GetItemsWithFilterAndOrdering(champ => filterByNameContains(champ.ToModel(), substring), index, count, orderingPropertyName, descending)
.Select(c => c.ToModel());
public async Task<IEnumerable<Champion?>> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false)
=> parent.DbContext.Champions.Include("RunePages").GetItemsWithFilterAndOrdering(
=> parent.DbContext.Champions.Include(c => c.Skills).Include(c => c.Characteristics).Include(c => c.Skins).Include(c => c.Image).GetItemsWithFilterAndOrdering(
c => c.RunePages.Any(rp => rp.Equals(runePage.ToEntity(parent.DbContext))),
index, count,
orderingPropertyName, descending).Select(c => c.ToModel());
public async Task<IEnumerable<Champion?>> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
=> parent.DbContext.Champions.GetItemsWithFilterAndOrdering(champ => filterBySkill(champ.ToModel(), skill), index, count, orderingPropertyName, descending)
=> parent.DbContext.Champions.Include(c => c.Skills).Include(c => c.Characteristics).Include(c => c.Skins).Include(c => c.Image).GetItemsWithFilterAndOrdering(champ => filterBySkill(champ.ToModel(), skill), index, count, orderingPropertyName, descending)
.Select(c => c.ToModel());
public async Task<IEnumerable<Champion?>> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
=> parent.DbContext.Champions.GetItemsWithFilterAndOrdering(champ => filterBySkillSubstring(champ.ToModel(), skill), index, count, orderingPropertyName, descending)
=> parent.DbContext.Champions.Include(c => c.Skills).Include(c => c.Characteristics).Include(c => c.Skins).Include(c => c.Image).GetItemsWithFilterAndOrdering(champ => filterBySkillSubstring(champ.ToModel(), skill), index, count, orderingPropertyName, descending)
.Select(c => c.ToModel());
public async Task<int> GetNbItems()
@ -112,10 +112,17 @@ namespace DbLib
public async Task<Champion?> UpdateItem(Champion? oldItem, Champion? newItem)
{
var toUpdate = parent.DbContext.Champions.Find(oldItem.Name);
toUpdate = newItem.ToEntity(parent.DbContext);
var toUpdate = parent.DbContext.Champions.FirstOrDefault(champ => champ.Name == oldItem.Name);
var newEntity = newItem.ToEntity(parent.DbContext);
toUpdate.Bio = newEntity.Bio;
toUpdate.Class = newEntity.Class;
toUpdate.Icon = newEntity.Icon;
toUpdate.Image = newEntity.Image;
toUpdate.Skins = newEntity.Skins;
toUpdate.Skills = newEntity.Skills;
toUpdate.Characteristics = newEntity.Characteristics;
parent.DbContext.SaveChanges();
return newItem;
return toUpdate?.ToModel();
}
}
}

@ -1,9 +1,6 @@
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DbManager.Mapper;
using Microsoft.EntityFrameworkCore;
using Model;
namespace DbLib
{
@ -16,64 +13,80 @@ namespace DbLib
public RunePagesManager(DbManager parent)
=> this.parent = parent;
public Task<RunePage?> AddItem(RunePage? item)
public async Task<RunePage?> AddItem(RunePage? item)
{
throw new NotImplementedException();
var RunePage = await parent.DbContext.RunePages.AddAsync(item.ToEntity(parent.DbContext));
parent.DbContext.SaveChanges();
return RunePage.Entity.ToModel(parent.DbContext);
}
public Task<bool> DeleteItem(RunePage? item)
public async Task<bool> DeleteItem(RunePage? item)
{
throw new NotImplementedException();
}
public Task<IEnumerable<RunePage?>> GetItemByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
var toDelete = parent.DbContext.RunePages.Find(item.Name);
if (toDelete != null)
{
throw new NotImplementedException();
parent.DbContext.RunePages.Remove(toDelete);
parent.DbContext.SaveChanges();
return true;
}
public Task<IEnumerable<RunePage?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
return false;
}
public Task<IEnumerable<RunePage?>> GetItemsByChampion(Champion? champion, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
private static Func<RunePage, string, bool> filterByName
= (rp, substring) => rp.Name.Equals(substring, StringComparison.InvariantCultureIgnoreCase);
public Task<IEnumerable<RunePage?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
private static Func<RunePage, string, bool> filterByNameContains
= (rp, substring) => rp.Name.Contains(substring, StringComparison.InvariantCultureIgnoreCase);
public Task<IEnumerable<RunePage?>> GetItemsByRune(Model.Rune? rune, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
private static Func<RunePage, Rune?, bool> filterByRune
= (rp, rune) => rune != null && rp.Runes.Values.Contains(rune!);
public async Task<IEnumerable<RunePage?>> GetItemByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
=> parent.DbContext.RunePages.Include(rp => rp.Champions).Include(rp => rp.DictionaryCategoryRunes).GetItemsWithFilterAndOrdering(
rp => filterByName(rp.ToModel(parent.DbContext), substring),
index, count, orderingPropertyName, descending).Select(c => c.ToModel(parent.DbContext));
public async Task<IEnumerable<RunePage?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
=> parent.DbContext.RunePages.Include(rp => rp.Champions).Include(rp => rp.DictionaryCategoryRunes).GetItemsWithFilterAndOrdering(
rp => true,
index, count, orderingPropertyName, descending).Select(c => c.ToModel(parent.DbContext));
public async Task<IEnumerable<RunePage?>> GetItemsByChampion(Champion? champion, int index, int count, string? orderingPropertyName = null, bool descending = false)
=> parent.DbContext.RunePages.Include(rp => rp.Champions).Include(rp => rp.DictionaryCategoryRunes).GetItemsWithFilterAndOrdering(
rp => rp.Champions.Any(c => c.Name.Equals(champion.Name)),
index, count,
orderingPropertyName, descending).Select(rp => rp.ToModel(parent.DbContext));
public async Task<IEnumerable<RunePage?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
=> parent.DbContext.RunePages.Include(rp => rp.Champions).Include(rp => rp.DictionaryCategoryRunes).GetItemsWithFilterAndOrdering(
rp => filterByNameContains(rp.ToModel(parent.DbContext), substring),
index, count, orderingPropertyName, descending).Select(c => c.ToModel(parent.DbContext));
public async Task<IEnumerable<RunePage?>> GetItemsByRune(Rune? rune, int index, int count, string? orderingPropertyName = null, bool descending = false)
=> parent.DbContext.RunePages.Include(rp => rp.Champions).Include(rp => rp.DictionaryCategoryRunes).GetItemsWithFilterAndOrdering(
rp => filterByRune(rp.ToModel(parent.DbContext), rune),
index, count, orderingPropertyName, descending).Select(c => c.ToModel(parent.DbContext));
public Task<int> GetNbItems()
{
throw new NotImplementedException();
}
=> parent.DbContext.RunePages.GetNbItemsWithFilter(
rp => true);
public Task<int> GetNbItemsByChampion(Champion? champion)
{
throw new NotImplementedException();
}
public async Task<int> GetNbItemsByChampion(Champion? champion)
=> parent.DbContext.RunePages.Where(rp => rp.Champions.Any(c => c.Name.Equals(champion.Name))).Count();
public Task<int> GetNbItemsByName(string substring)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsByRune(Model.Rune? rune)
{
throw new NotImplementedException();
}
public async Task<int> GetNbItemsByName(string substring)
=> parent.DbContext.RunePages.Where(rp => rp.Name.Contains(substring)).Count();
public async Task<int> GetNbItemsByRune(Rune? rune)
=> parent.DbContext.RunePages.Where(rp => rp.DictionaryCategoryRunes.Any(r => r.RuneName.Equals(rune.Name))).Count();
public Task<RunePage?> UpdateItem(RunePage? oldItem, RunePage? newItem)
public async Task<RunePage?> UpdateItem(RunePage? oldItem, RunePage? newItem)
{
throw new NotImplementedException();
var toUpdate = parent.DbContext.RunePages.Find(oldItem.Name);
toUpdate.DictionaryCategoryRunes = newItem.ToEntity(parent.DbContext).DictionaryCategoryRunes;
parent.DbContext.SaveChanges();
return toUpdate.ToModel(parent.DbContext);
}
}
}

@ -1,9 +1,5 @@
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DbManager.Mapper;
using Model;
namespace DbLib
{
@ -15,54 +11,77 @@ namespace DbLib
public RunesManager(DbManager parent)
=> this.parent = parent;
public Task<Model.Rune?> AddItem(Model.Rune? item)
public async Task<Rune?> AddItem(Rune? item)
{
throw new NotImplementedException();
var rune = await parent.DbContext.Runes.AddAsync(item.ToEntity());
parent.DbContext.SaveChanges();
return rune.Entity.ToModel();
}
public Task<bool> DeleteItem(Model.Rune? item)
public async Task<bool> DeleteItem(Rune? item)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Model.Rune?>> GetItemByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
var toDelete = parent.DbContext.Runes.Find(item.Name);
if (toDelete != null)
{
throw new NotImplementedException();
parent.DbContext.Runes.Remove(toDelete);
parent.DbContext.SaveChanges();
return true;
}
public Task<IEnumerable<Model.Rune?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
return false;
}
public Task<IEnumerable<Model.Rune?>> GetItemsByFamily(RuneFamily family, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
private static Func<Rune, RuneFamily, bool> filterByRuneFamily
= (rune, family) => rune.Family == family;
public Task<IEnumerable<Model.Rune?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
private static Func<Rune, string, bool> filterByName
= (rune, substring) => rune.Name.Equals(substring, StringComparison.InvariantCultureIgnoreCase);
private static Func<Rune, string, bool> filterByNameContains
= (rune, substring) => rune.Name.Contains(substring, StringComparison.InvariantCultureIgnoreCase);
public async Task<IEnumerable<Rune?>> GetItemByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
=> parent.DbContext.Runes.GetItemsWithFilterAndOrdering(
rune => filterByName(rune.ToModel(), substring),
index, count, orderingPropertyName, descending).Select(c => c.ToModel());
public async Task<IEnumerable<Rune?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
=> parent.DbContext.Runes.GetItemsWithFilterAndOrdering(
r => true,
index, count, orderingPropertyName, descending).Select(c => c.ToModel());
public async Task<IEnumerable<Rune?>> GetItemsByFamily(RuneFamily family, int index, int count, string? orderingPropertyName = null, bool descending = false)
=> parent.DbContext.Runes.GetItemsWithFilterAndOrdering(
rune => filterByRuneFamily(rune.ToModel(), family),
index, count, orderingPropertyName, descending).Select(c => c.ToModel());
public async Task<IEnumerable<Rune?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
=> parent.DbContext.Runes.GetItemsWithFilterAndOrdering(
rune => filterByNameContains(rune.ToModel(), substring),
index, count, orderingPropertyName, descending).Select(c => c.ToModel());
public Task<int> GetNbItems()
{
throw new NotImplementedException();
}
=> parent.DbContext.Runes.GetNbItemsWithFilter(
rune => true);
public Task<int> GetNbItemsByFamily(RuneFamily family)
{
throw new NotImplementedException();
}
=> parent.DbContext.Runes.GetNbItemsWithFilter(
rune => filterByRuneFamily(rune.ToModel(), family));
public Task<int> GetNbItemsByName(string substring)
{
throw new NotImplementedException();
}
=> parent.DbContext.Runes.GetNbItemsWithFilter(
rune => filterByName(rune.ToModel(), substring));
public Task<Model.Rune?> UpdateItem(Model.Rune? oldItem, Model.Rune? newItem)
public async Task<Rune?> UpdateItem(Rune? oldItem, Rune? newItem)
{
throw new NotImplementedException();
var toUpdate = parent.DbContext.Runes.Find(oldItem.Name);
var newEntity = newItem.ToEntity();
toUpdate.Description = newEntity.Description;
toUpdate.Icon = newEntity.Icon;
toUpdate.Family = newEntity.Family;
toUpdate.Image = newEntity.Image;
parent.DbContext.SaveChanges();
return toUpdate.ToModel();
}
}

@ -1,4 +1,6 @@
using Model;
using DbManager.Mapper;
using Microsoft.EntityFrameworkCore;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
@ -16,54 +18,74 @@ namespace DbLib
public SkinsManager(DbManager parent)
=> this.parent = parent;
public Task<Skin?> AddItem(Skin? item)
public async Task<Skin?> AddItem(Skin? item)
{
throw new NotImplementedException();
var skin = await parent.DbContext.Skins.AddAsync(item.ToEntity(parent.DbContext));
parent.DbContext.SaveChanges();
return skin.Entity.ToModel();
}
public Task<bool> DeleteItem(Skin? item)
public async Task<bool> DeleteItem(Skin? item)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Skin?>> GetItemByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
var toDelete = parent.DbContext.Skins.Find(item.Name);
if (toDelete != null)
{
throw new NotImplementedException();
parent.DbContext.Skins.Remove(toDelete);
parent.DbContext.SaveChanges();
return true;
}
public Task<IEnumerable<Skin?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
return false;
}
public Task<IEnumerable<Skin?>> GetItemsByChampion(Champion? champion, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
private static Func<Skin, Champion?, bool> filterByChampion = (skin, champion) => champion != null && skin.Champion.Equals(champion!);
public Task<IEnumerable<Skin?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
private static Func<Skin, string, bool> filterByName = (skin, substring) => skin.Name.Equals(substring, StringComparison.InvariantCultureIgnoreCase);
private static Func<Skin, string, bool> filterByNameContains = (skin, substring) => skin.Name.Contains(substring, StringComparison.InvariantCultureIgnoreCase);
public async Task<IEnumerable<Skin?>> GetItemByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
=> parent.DbContext.Skins.Include(s => s.Champion).Include(s => s.Image).GetItemsWithFilterAndOrdering(
skin => filterByName(skin.ToModel(), substring),
index, count, orderingPropertyName, descending).Select(c => c.ToModel());
public async Task<IEnumerable<Skin?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
=> parent.DbContext.Skins.Include(s => s.Champion).Include(s => s.Image).GetItemsWithFilterAndOrdering(
skin => true,
index, count, orderingPropertyName, descending).Select(c => c.ToModel());
public async Task<IEnumerable<Skin?>> GetItemsByChampion(Champion? champion, int index, int count, string? orderingPropertyName = null, bool descending = false)
=> parent.DbContext.Skins.Include(s => s.Champion).Include(s => s.Image).GetItemsWithFilterAndOrdering(
skin => filterByChampion(skin.ToModel(), champion),
index, count, orderingPropertyName, descending).Select(c => c.ToModel());
public async Task<IEnumerable<Skin?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
=> parent.DbContext.Skins.Include(s => s.Champion).Include(s => s.Image).GetItemsWithFilterAndOrdering(
skin => filterByNameContains(skin.ToModel(), substring),
index, count, orderingPropertyName, descending).Select(c => c.ToModel());
public Task<int> GetNbItems()
{
throw new NotImplementedException();
}
=> parent.DbContext.Skins.GetNbItemsWithFilter(
c => true);
public Task<int> GetNbItemsByChampion(Champion? champion)
{
throw new NotImplementedException();
}
=> parent.DbContext.Skins.GetNbItemsWithFilter(
skin => filterByChampion(skin.ToModel(), champion));
public Task<int> GetNbItemsByName(string substring)
{
throw new NotImplementedException();
}
=> parent.DbContext.Skins.GetNbItemsWithFilter(
skin => filterByName(skin.ToModel(), substring));
public Task<Skin?> UpdateItem(Skin? oldItem, Skin? newItem)
public async Task<Skin?> UpdateItem(Skin? oldItem, Skin? newItem)
{
throw new NotImplementedException();
var toUpdate = parent.DbContext.Skins.Find(oldItem.Name);
var newEntity = newItem.ToEntity(parent.DbContext);
toUpdate.Description = newEntity.Description;
toUpdate.Icon = newEntity.Icon;
toUpdate.Price = newEntity.Price;
toUpdate.Champion = newEntity.Champion;
toUpdate.Image = newEntity.Image;
parent.DbContext.SaveChanges();
return toUpdate.ToModel();
}
}

@ -8,14 +8,21 @@ namespace DbManager.Mapper
{
public static Champion ToModel(this ChampionEntity championEntity)
{
Champion champion = new (championEntity.Name, championEntity.Class.ToModel(), championEntity.Icon, "", championEntity.Bio);
Champion champion = new (championEntity.Name, championEntity.Class.ToModel(), championEntity.Icon, championEntity.Image.Base64, championEntity.Bio);
foreach (var skill in championEntity.Skills)
{
champion.AddSkill(skill.ToModel());
}
foreach (var skin in championEntity.Skins)
{
champion.AddSkin(skin.ToModel());
champion.AddSkin(new Skin(skin.Name, champion, skin.Price, skin.Icon, skin.Image.Base64, skin.Description));
}
if (championEntity.Characteristics != null)
{
foreach (var c in championEntity.Characteristics)
{
champion.AddCharacteristics(c.ToModel());
}
}
return champion;
}
@ -31,12 +38,13 @@ namespace DbManager.Mapper
};
foreach (var skill in champion.Skills)
{
champ.Skills.Add(skill.ToEntity(champ));
champ.Skills.Add(skill.ToEntity(champ, context));
}
foreach (var skin in champion.Skins)
{
champ.Skins.Add(skin.ToEntity(context));
}
champ.Characteristics = champion.Characteristics.Select(x => x.ToEntity(champ, context)).ToList();
return champ;
}
}

@ -0,0 +1,27 @@
using MyFlib.Entities;
using MyFlib;
namespace DbManager.Mapper
{
public static class CharacteristicMapper
{
public static CharacteristicEntity ToEntity(this KeyValuePair<string, int> item, ChampionEntity champion, LolDbContext context)
{
var characteristicEntity = context.Characteristic.Find(item.Key, champion.Id);
if (characteristicEntity == null)
{
return new()
{
Name = item.Key,
Value = item.Value,
ChampionForeignKey = champion.Id
};
}
return characteristicEntity;
}
public static Tuple<string, int> ToModel(this CharacteristicEntity entity)
=> new(entity.Name, entity.Value);
}
}

@ -6,7 +6,7 @@ namespace DbManager.Mapper
{
public static class RuneMapper
{
public static Rune ToModel(this RuneEntity rune) => new(rune.Name, rune.Family.ToModel(), rune.Icon, rune.Image.Base64, rune.Description);
public static Rune ToModel(this RuneEntity rune) => new(rune.Name, rune.Family.ToModel(), rune.Icon, "", rune.Description);
public static RuneEntity ToEntity(this Rune rune)
=> new()
{

@ -8,8 +8,10 @@ namespace DbManager.Mapper
{
public static Skill ToModel(this SkillEntity skillEntity) => new(skillEntity.Name, skillEntity.Type.ToModel(), skillEntity.Description);
public static SkillEntity ToEntity(this Skill skill, ChampionEntity championEntity)
public static SkillEntity ToEntity(this Skill skill, ChampionEntity championEntity, LolDbContext context)
{
var skillSearch = context.Skills.Find(skill.Name);
if (skillSearch == null)
{
return new()
{
@ -19,6 +21,8 @@ namespace DbManager.Mapper
Champion = championEntity
};
}
throw new Exception("Skill was already exist");
}
}
}

@ -9,14 +9,21 @@ namespace DbManager.Mapper
=> new(skinEntity.Name, skinEntity.Champion.ToModel(), skinEntity.Price, skinEntity.Icon, skinEntity.Image.Base64, skinEntity.Description);
public static SkinEntity ToEntity(this Skin skin, LolDbContext context)
=> new()
{
var skinSearch = context.Skins.Find(skin.Name);
if(skinSearch == null)
{
return new()
{
Name = skin.Name,
Description = skin.Description,
Icon = skin.Icon,
Price = skin.Price,
Champion = context.Champions.Find(skin.Champion.Name),
Champion = context.Champions.FirstOrDefault(c => c.Name == skin.Champion.Name),
Image = skin.Image.ToEntity()
};
}
throw new Exception("Skin was already exist");
}
}
}

@ -96,6 +96,10 @@ namespace MyFlib
);
//CharacteristicEntity
modelBuilder.Entity<CharacteristicEntity>()
.HasOne(m => m.Champion)
.WithMany(a => a.Characteristics)
.HasForeignKey("ChampionForeignKey");
modelBuilder.Entity<CharacteristicEntity>().HasKey(c => new { c.Name, c.ChampionForeignKey });
modelBuilder.Entity<CharacteristicEntity>().HasData(

@ -11,7 +11,7 @@ using MyFlib;
namespace MyFlib.Migrations
{
[DbContext(typeof(LolDbContext))]
[Migration("20230325153221_myMigration")]
[Migration("20230325231552_myMigration")]
partial class myMigration
{
/// <inheritdoc />
Loading…
Cancel
Save