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

@ -7,6 +7,8 @@ using System.Threading.Tasks;
namespace EFManager
{
public partial class ManagerData
{
public class ManagerRune : IRunesManager
{
public Task<Model.Rune?> AddItem(Model.Rune? item)
@ -54,4 +56,5 @@ namespace EFManager
throw new NotImplementedException();
}
}
}
}

@ -7,6 +7,8 @@ using System.Threading.Tasks;
namespace EFManager
{
public partial class ManagerData
{
public class ManagerRunePage : IRunePagesManager
{
public Task<RunePage?> AddItem(RunePage? item)
@ -64,4 +66,5 @@ namespace EFManager
throw new NotImplementedException();
}
}
}
}

@ -1,4 +1,7 @@
using Model;
using EFlib;
using EFMapping;
using Microsoft.EntityFrameworkCore;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
@ -7,24 +10,61 @@ using System.Threading.Tasks;
namespace EFManager
{
public partial class ManagerData
{
public class ManagerSkin : ISkinsManager
{
private readonly ManagerData parent;
public ManagerSkin(ManagerData parent)
=> this.parent = parent;
public Task<Skin?> AddItem(Skin? item)
public async Task<Skin?> AddItem(Skin? item)
{
throw new NotImplementedException();
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)
@ -37,9 +77,9 @@ namespace EFManager
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)
@ -52,9 +92,18 @@ namespace EFManager
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