@ -1,4 +1,5 @@
using Model ;
using Microsoft.EntityFrameworkCore ;
using Model ;
namespace EFLol.DBDataManager
@ -27,14 +28,12 @@ namespace EFLol.DBDataManager
{
if ( item = = null )
{
return null ;
throw new Exception ( "Item is null" ) ;
}
var addItem = await _context . AddAsync < Champion > ( item ) ;
await _context . SaveChangesAsync ( ) ;
return addItem . Entity ;
// Va chercher les info du context (Context.champions.get)(DbSet) et les map en champion model
// Dans Program.cs de API rajouter un scope (AddScope <IDataManager, EFDataManager>) -> Ca va dire que a chaque fois que j'utilise un IDataManager, il va créer un EFDataManager
_context . Add ( item . ChampionToEntity ( ) ) ;
_context . SaveChanges ( ) ;
return item ;
}
@ -44,35 +43,62 @@ namespace EFLol.DBDataManager
{
return false ;
}
var deletedItem = _context . Remove ( item ) ;
await _context . SaveChangesAsync ( ) ;
return true ;
var champ = _context . Champions . Select ( c = > c = = item . ChampionToEntity ( ) ) ;
if ( champ . Count ( ) < 1 )
{
return false ;
}
private Func < Champion , string , bool > filterByName = ( champion , substring ) = >
champion . Name . Contains ( substring , StringComparison . InvariantCultureIgnoreCase ) ;
_context . Champions . Remove ( item . ChampionToEntity ( ) ) ;
_context . SaveChanges ( ) ;
return true ;
}
public Task < Champion ? > UpdateItem ( Champion ? oldItem , Champion ? newItem )
public async Task < Champion ? > UpdateItem ( Champion ? oldItem , Champion ? newItem )
{
throw new NotImplementedException ( ) ;
if ( oldItem ! = null & & newItem ! = null )
{
var champEntity = await _context . Champions . FirstOrDefaultAsync ( c = > c . Name = = oldItem . Name ) ;
if ( champEntity = = null )
{
throw new Exception ( "Champion not found in database" ) ;
}
champEntity . Bio = newItem . Bio ;
_context . SaveChanges ( ) ;
return champEntity . ChampionToPoco ( ) ;
}
throw new Exception ( "Invalid input parameters" ) ;
}
public async Task < int > GetNbItems ( ) = > _context . Champions . Count ( ) ;
public async Task < IEnumerable < Champion ? > > GetItems ( int index , int count , string? orderingPropertyName = null , bool @descending = false )
public async Task < IEnumerable < Champion ? > > GetItems ( int index , int count , string? orderingPropertyName = null ,
bool descending = false )
{
IEnumerable < Champion > champions = _context . Champions . Skip ( index * count ) . Take ( count ) . OrderBy ( champion = > orderingPropertyName ) . Select ( champion = > champion . ChampionToPoco ( ) ) ;
IEnumerable < Champion > champions = _context . Champions . Skip ( index * count )
. Take ( count )
. OrderBy ( champions = > orderingPropertyName )
. Select ( champions = > champions . ChampionToPoco ( ) ) ;
return champions ;
}
public Task < int > GetNbItemsByName ( string substring )
{
throw new NotImplementedException ( ) ;
}
public Task < IEnumerable < Champion ? > > GetItemsByName ( string substring , int index , int count , string? orderingPropertyName = null ,
bool @descending = false )
private Func < Champion , string , bool > filterByName = ( champion , substring ) = >
champion . Name . IndexOf ( substring , StringComparison . InvariantCultureIgnoreCase ) > = 0 ;
public Task < IEnumerable < Champion ? > > GetItemsByName ( string substring , int index , int count ,
string? orderingPropertyName = null , bool descending = false )
= > _context . Champions . Select ( champion = > champion . ChampionToPoco ( ) )
. GetItemsWithFilterAndOrdering ( champ = > filterByName ( champ , substring ) , index , count ,
orderingPropertyName , descending ) ;
public Task < int > GetNbItemsByName ( string substring )
{
throw new NotImplementedException ( ) ;
}
@ -83,7 +109,8 @@ namespace EFLol.DBDataManager
throw new NotImplementedException ( ) ;
}
public Task < IEnumerable < Champion ? > > GetItemsByCharacteristic ( string charName , int index , int count , string? orderingPropertyName = null ,
public Task < IEnumerable < Champion ? > > GetItemsByCharacteristic ( string charName , int index , int count ,
string? orderingPropertyName = null ,
bool @descending = false )
{
throw new NotImplementedException ( ) ;
@ -94,7 +121,8 @@ namespace EFLol.DBDataManager
throw new NotImplementedException ( ) ;
}
public Task < IEnumerable < Champion ? > > GetItemsByClass ( ChampionClass championClass , int index , int count , string? orderingPropertyName = null ,
public Task < IEnumerable < Champion ? > > GetItemsByClass ( ChampionClass championClass , int index , int count ,
string? orderingPropertyName = null ,
bool @descending = false )
{
throw new NotImplementedException ( ) ;
@ -105,7 +133,8 @@ namespace EFLol.DBDataManager
throw new NotImplementedException ( ) ;
}
public Task < IEnumerable < Champion ? > > GetItemsBySkill ( Skill ? skill , int index , int count , string? orderingPropertyName = null , bool @descending = false )
public Task < IEnumerable < Champion ? > > GetItemsBySkill ( Skill ? skill , int index , int count ,
string? orderingPropertyName = null , bool @descending = false )
{
throw new NotImplementedException ( ) ;
}
@ -115,7 +144,8 @@ namespace EFLol.DBDataManager
throw new NotImplementedException ( ) ;
}
public Task < IEnumerable < Champion ? > > GetItemsByRunePage ( RunePage ? runePage , int index , int count , string? orderingPropertyName = null ,
public Task < IEnumerable < Champion ? > > GetItemsByRunePage ( RunePage ? runePage , int index , int count ,
string? orderingPropertyName = null ,
bool @descending = false )
{
throw new NotImplementedException ( ) ;
@ -126,7 +156,8 @@ namespace EFLol.DBDataManager
throw new NotImplementedException ( ) ;
}
public Task < IEnumerable < Champion ? > > GetItemsBySkill ( string skill , int index , int count , string? orderingPropertyName = null , bool @descending = false )
public Task < IEnumerable < Champion ? > > GetItemsBySkill ( string skill , int index , int count ,
string? orderingPropertyName = null , bool @descending = false )
{
throw new NotImplementedException ( ) ;
}