Update Manager
continuous-integration/drone/push Build is failing Details

master
Louwar 2 years ago
parent 60b5c43571
commit 8aaadc0c8d

@ -33,7 +33,7 @@ namespace EFManager
var toDelete = parent.DbContext.Champions.Find(item.Name); var toDelete = parent.DbContext.Champions.Find(item.Name);
if (toDelete != null) if (toDelete != null)
{ {
parent.DbContext.Champions.Remove(item.toEF(parent.DbContext)); parent.DbContext.Champions.Remove(toDelete);
parent.DbContext.SaveChangesAsync(); parent.DbContext.SaveChangesAsync();
return true; return true;
} }
@ -51,30 +51,16 @@ namespace EFManager
{ {
if (descending) if (descending)
{ {
return await Task.FromResult(parent.DbContext.Champions.OrderByDescending( return await Task.FromResult(parent.DbContext.Champions.OrderByDescending(champ => typeof(EFChampion).GetProperty(orderingPropertyName)).Skip(index * count).Take(count).Select(efChampion => efChampion.toModel()));
c => typeof(EFChampion).GetProperty(orderingPropertyName))
.Skip(index * count)
.Take(count)
.Select(ce => ce.toModel())
);
} }
else else
{ {
return await Task.FromResult(parent.DbContext.Champions.OrderBy( return await Task.FromResult(parent.DbContext.Champions.OrderBy(champ => typeof(EFChampion).GetProperty(orderingPropertyName)).Skip(index * count).Take(count).Select(efChampion => efChampion.toModel()));
c => typeof(EFChampion).GetProperty(orderingPropertyName))
.Skip(index * count)
.Take(count)
.Select(ce => ce.toModel())
);
} }
} }
else else
{ {
return await Task.FromResult(parent.DbContext.Champions return await Task.FromResult(parent.DbContext.Champions.Skip(index * count).Take(count).Select(efChampion => efChampion.toModel()));
.Skip(index * count)
.Take(count)
.Select(ce => ce.toModel())
);
} }
} }
@ -90,10 +76,25 @@ namespace EFManager
} }
public Task<IEnumerable<Champion?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false) public async Task<IEnumerable<Champion?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
{ {
throw new NotImplementedException(); var EfChampion = from champ in parent.DbContext.Champions where champ.Name.Contains(substring) select champ;
if (orderingPropertyName != null)
{
if (descending)
{
return await Task.FromResult(EfChampion.OrderByDescending(champ => typeof(EFChampion).GetProperty(orderingPropertyName)).Skip(index * count).Take(count).Select(efChampion => efChampion.toModel()));
}
else
{
return await Task.FromResult(EfChampion.OrderBy(champ => typeof(EFChampion).GetProperty(orderingPropertyName)).Skip(index * count).Take(count).Select(efChampion => efChampion.toModel()));
}
}
else
{
return await Task.FromResult(EfChampion.Skip(index * count).Take(count).Select(efChampion => efChampion.toModel()));
}
} }
public Task<IEnumerable<Champion?>> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false) public Task<IEnumerable<Champion?>> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false)
@ -122,12 +123,12 @@ namespace EFManager
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<int> GetNbItemsByClass(ChampionClass championClass) public async Task<int> GetNbItemsByClass(ChampionClass championClass)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<int> GetNbItemsByName(string substring) public async Task<int> GetNbItemsByName(string substring)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@ -137,24 +138,25 @@ namespace EFManager
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<int> GetNbItemsBySkill(Skill? skill) public async Task<int> GetNbItemsBySkill(Skill? skill)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public async Task<int> GetNbItemsBySkill(string skill) public async Task<int> GetNbItemsBySkill(string skill)
{ {
return parent.DbContext.Champions.Where(champ => skill != null && champ.Skills.Any(Skill => Skill.Name.Equals(skill))) throw new NotImplementedException();
.Count();
} }
public async Task<Champion?> UpdateItem(Champion? oldItem, Champion? newItem) public async Task<Champion?> UpdateItem(Champion? oldItem, Champion? newItem)
{ {
var toUpdate = parent.DbContext.Champions.Find(oldItem.Name); var toUpdate = parent.DbContext.Champions.Find(oldItem.Name);
try
toUpdate = newItem.toEF(); {
parent.DbContext.SaveChanges(); toUpdate = newItem.toEF(parent.DbContext);
parent.DbContext.SaveChanges();
}
catch(DbUpdateException) { }
return newItem; return newItem;
} }
} }

@ -7,51 +7,54 @@ using System.Threading.Tasks;
namespace EFManager namespace EFManager
{ {
public class ManagerRune : IRunesManager public partial class ManagerData
{ {
public Task<Model.Rune?> AddItem(Model.Rune? item) public class ManagerRune : IRunesManager
{ {
throw new NotImplementedException(); public Task<Model.Rune?> AddItem(Model.Rune? item)
} {
throw new NotImplementedException();
public Task<bool> DeleteItem(Model.Rune? item) }
{
throw new NotImplementedException(); public Task<bool> DeleteItem(Model.Rune? item)
} {
throw new NotImplementedException();
public Task<IEnumerable<Model.Rune?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) }
{
throw new NotImplementedException(); public Task<IEnumerable<Model.Rune?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
} {
throw new NotImplementedException();
public Task<IEnumerable<Model.Rune?>> GetItemsByFamily(RuneFamily family, int index, int count, string? orderingPropertyName = null, bool descending = false) }
{
throw new NotImplementedException(); public Task<IEnumerable<Model.Rune?>> GetItemsByFamily(RuneFamily family, int index, int count, string? orderingPropertyName = null, bool descending = false)
} {
throw new NotImplementedException();
public Task<IEnumerable<Model.Rune?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false) }
{
throw new NotImplementedException(); public Task<IEnumerable<Model.Rune?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
} {
throw new NotImplementedException();
public Task<int> GetNbItems() }
{
throw new NotImplementedException(); public Task<int> GetNbItems()
} {
throw new NotImplementedException();
public Task<int> GetNbItemsByFamily(RuneFamily family) }
{
throw new NotImplementedException(); public Task<int> GetNbItemsByFamily(RuneFamily family)
} {
throw new NotImplementedException();
public Task<int> GetNbItemsByName(string substring) }
{
throw new NotImplementedException(); public Task<int> GetNbItemsByName(string substring)
} {
throw new NotImplementedException();
public Task<Model.Rune?> UpdateItem(Model.Rune? oldItem, Model.Rune? newItem) }
{
throw new NotImplementedException(); public Task<Model.Rune?> UpdateItem(Model.Rune? oldItem, Model.Rune? newItem)
{
throw new NotImplementedException();
}
} }
} }
} }

@ -7,61 +7,64 @@ using System.Threading.Tasks;
namespace EFManager namespace EFManager
{ {
public class ManagerRunePage : IRunePagesManager public partial class ManagerData
{ {
public Task<RunePage?> AddItem(RunePage? item) public class ManagerRunePage : IRunePagesManager
{ {
throw new NotImplementedException(); public Task<RunePage?> AddItem(RunePage? item)
} {
throw new NotImplementedException();
}
public Task<bool> DeleteItem(RunePage? item) public Task<bool> DeleteItem(RunePage? item)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IEnumerable<RunePage?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) public Task<IEnumerable<RunePage?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IEnumerable<RunePage?>> GetItemsByChampion(Champion? champion, int index, int count, string? orderingPropertyName = null, bool descending = false) public Task<IEnumerable<RunePage?>> GetItemsByChampion(Champion? champion, int index, int count, string? orderingPropertyName = null, bool descending = false)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IEnumerable<RunePage?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false) public Task<IEnumerable<RunePage?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IEnumerable<RunePage?>> GetItemsByRune(Model.Rune? rune, int index, int count, string? orderingPropertyName = null, bool descending = false) public Task<IEnumerable<RunePage?>> GetItemsByRune(Model.Rune? rune, int index, int count, string? orderingPropertyName = null, bool descending = false)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<int> GetNbItems() public Task<int> GetNbItems()
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<int> GetNbItemsByChampion(Champion? champion) public Task<int> GetNbItemsByChampion(Champion? champion)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<int> GetNbItemsByName(string substring) public Task<int> GetNbItemsByName(string substring)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<int> GetNbItemsByRune(Model.Rune? rune) public Task<int> GetNbItemsByRune(Model.Rune? rune)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<RunePage?> UpdateItem(RunePage? oldItem, RunePage? newItem) public Task<RunePage?> UpdateItem(RunePage? oldItem, RunePage? newItem)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
}
} }
} }
} }

@ -1,4 +1,7 @@
using Model; using EFlib;
using EFMapping;
using Microsoft.EntityFrameworkCore;
using Model;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -7,54 +10,100 @@ using System.Threading.Tasks;
namespace EFManager namespace EFManager
{ {
public class ManagerSkin : ISkinsManager public partial class ManagerData
{ {
private readonly ManagerData parent; public class ManagerSkin : ISkinsManager
public ManagerSkin(ManagerData parent)
=> this.parent = parent;
public Task<Skin?> AddItem(Skin? item)
{ {
throw new NotImplementedException(); private readonly ManagerData parent;
} public ManagerSkin(ManagerData parent)
=> this.parent = parent;
public async Task<Skin?> AddItem(Skin? item)
{
try
{
await parent.DbContext.Skins.AddAsync(item.toEF(parent.DbContext));
parent.DbContext.SaveChangesAsync();
}
catch (OperationCanceledException) { }
catch (DbUpdateException) { }
return item;
}
public Task<bool> DeleteItem(Skin? item) public async Task<bool> DeleteItem(Skin? item)
{ {
throw new NotImplementedException(); try
} {
var toDelete = parent.DbContext.Skins.Find(item.Name);
if (toDelete != null)
{
parent.DbContext.Skins.Remove(toDelete);
parent.DbContext.SaveChangesAsync();
return true;
}
return false;
}
catch (DbUpdateException)
{
return false;
}
}
public Task<IEnumerable<Skin?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) public async Task<IEnumerable<Skin?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
{ {
throw new NotImplementedException(); if (orderingPropertyName != null)
} {
if (descending)
{
return await Task.FromResult(parent.DbContext.Skins.OrderByDescending(skin => typeof(EFSkin).GetProperty(orderingPropertyName)).Skip(index * count).Take(count).Select(efSkin => efSkin.toModel()));
}
else
{
return await Task.FromResult(parent.DbContext.Skins.OrderBy(skin => typeof(EFSkin).GetProperty(orderingPropertyName)).Skip(index * count).Take(count).Select(efSkin => efSkin.toModel()));
}
}
else
{
return await Task.FromResult(parent.DbContext.Skins.Skip(index * count).Take(count).Select(efSkin => efSkin.toModel()));
}
}
public Task<IEnumerable<Skin?>> GetItemsByChampion(Champion? champion, int index, int count, string? orderingPropertyName = null, bool descending = false) public Task<IEnumerable<Skin?>> GetItemsByChampion(Champion? champion, int index, int count, string? orderingPropertyName = null, bool descending = false)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IEnumerable<Skin?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false) public Task<IEnumerable<Skin?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<int> GetNbItems() public async Task<int> GetNbItems()
{ {
throw new NotImplementedException(); return parent.DbContext.Skins.Count();
} }
public Task<int> GetNbItemsByChampion(Champion? champion) public Task<int> GetNbItemsByChampion(Champion? champion)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<int> GetNbItemsByName(string substring) public Task<int> GetNbItemsByName(string substring)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
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);
try
{
toUpdate.Champion = parent.DbContext.Champions.Find(newItem.Champion.Name);
parent.DbContext.SaveChanges();
}
catch (DbUpdateException) { }
return newItem;
}
} }
} }
} }

Loading…
Cancel
Save