Adding includes
continuous-integration/drone/push Build is failing Details

Arthur_More
Arthur VALIN 2 years ago
parent 0668f2f44f
commit 0dc5acc2f0

@ -17,13 +17,8 @@ namespace Business
public async Task<Champion?> AddItem(Champion? item) public async Task<Champion?> AddItem(Champion? item)
{ {
try await parent.DbContext.champions.AddAsync(item.ToEntity(parent.DbContext));
{ parent.DbContext.SaveChanges();
await parent.DbContext.champions.AddAsync(item.ToEntity(parent.DbContext));
parent.DbContext.SaveChanges();
}
catch(OperationCanceledException){}
catch(DbUpdateException) {}
return item; return item;
} }
@ -40,16 +35,12 @@ namespace Business
} }
return false; return false;
} }
catch (DbUpdateException)
{
return false;
}
} }
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)
{ {
Console.WriteLine("GET"); Console.WriteLine("GET");
return parent.DbContext.champions.GetItemsWithFilterAndOrdering( return parent.DbContext.champions.Include("Skills").Include("Characteristics").GetItemsWithFilterAndOrdering(
c => true, c => true,
index, count, index, count,
orderingPropertyName, descending).Select(c => c.ToModel()); orderingPropertyName, descending).Select(c => c.ToModel());
@ -58,7 +49,7 @@ namespace Business
public async Task<IEnumerable<Champion?>> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false) public async Task<IEnumerable<Champion?>> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false)
{ {
return parent.DbContext.champions.Include("Characteristics").GetItemsWithFilterAndOrdering( return parent.DbContext.champions.Include("Skills").Include("Characteristics").GetItemsWithFilterAndOrdering(
c => c.Characteristics.Any(ch => ch.Name.Equals(charName)), c => c.Characteristics.Any(ch => ch.Name.Equals(charName)),
index, count, index, count,
orderingPropertyName, descending).Select(c => c.ToModel()); orderingPropertyName, descending).Select(c => c.ToModel());
@ -66,7 +57,7 @@ namespace Business
public async Task<IEnumerable<Champion?>> GetItemsByClass(ChampionClass championClass, int index, int count, string? orderingPropertyName = null, bool descending = false) public async Task<IEnumerable<Champion?>> GetItemsByClass(ChampionClass championClass, int index, int count, string? orderingPropertyName = null, bool descending = false)
{ {
return parent.DbContext.champions.GetItemsWithFilterAndOrdering( return parent.DbContext.champions.Include("Skills").Include("Characteristics").GetItemsWithFilterAndOrdering(
c => c.Class.Equals(championClass), c => c.Class.Equals(championClass),
index, count, index, count,
orderingPropertyName, descending).Select(c => c.ToModel()); orderingPropertyName, descending).Select(c => c.ToModel());
@ -74,7 +65,7 @@ namespace Business
public async 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)
{ {
return parent.DbContext.champions.GetItemsWithFilterAndOrdering( return parent.DbContext.champions.Include("Skills").Include("Characteristics").GetItemsWithFilterAndOrdering(
c => c.Name.Contains(substring), c => c.Name.Contains(substring),
index, count, index, count,
orderingPropertyName, descending).Select(c => c.ToModel()); orderingPropertyName, descending).Select(c => c.ToModel());
@ -83,7 +74,7 @@ namespace Business
public async Task<IEnumerable<Champion?>> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false) public async Task<IEnumerable<Champion?>> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false)
{ {
return parent.DbContext.champions.Include("runepages").GetItemsWithFilterAndOrdering( return parent.DbContext.champions.Include("Skills").Include("Characteristics").Include("runepages").GetItemsWithFilterAndOrdering(
c => c.runepages.Any(rp => rp.Equals(runePage.ToEntity(parent.DbContext))), c => c.runepages.Any(rp => rp.Equals(runePage.ToEntity(parent.DbContext))),
index, count, index, count,
orderingPropertyName, descending).Select(c => c.ToModel()); orderingPropertyName, descending).Select(c => c.ToModel());
@ -92,7 +83,7 @@ namespace Business
public async Task<IEnumerable<Champion?>> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool descending = false) public async Task<IEnumerable<Champion?>> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
{ {
return parent.DbContext.champions.GetItemsWithFilterAndOrdering( return parent.DbContext.champions.Include("Skills").Include("Characteristics").GetItemsWithFilterAndOrdering(
c => skill != null && c.Skills.Any(s => s.Name.Equals(skill.Name)), c => skill != null && c.Skills.Any(s => s.Name.Equals(skill.Name)),
index, count, index, count,
orderingPropertyName, descending).Select(c => c.ToModel()); orderingPropertyName, descending).Select(c => c.ToModel());
@ -100,7 +91,7 @@ namespace Business
public async Task<IEnumerable<Champion?>> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool descending = false) public async Task<IEnumerable<Champion?>> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
{ {
return parent.DbContext.champions.Include("Skills").GetItemsWithFilterAndOrdering( return parent.DbContext.champions.Include("Skills").Include("Characteristics").Include("Skills").GetItemsWithFilterAndOrdering(
c => skill != null && c.Skills.Any(s => s.Name.Equals(skill)), c => skill != null && c.Skills.Any(s => s.Name.Equals(skill)),
index, count, index, count,
orderingPropertyName, descending).Select(c => c.ToModel()); orderingPropertyName, descending).Select(c => c.ToModel());
@ -149,12 +140,8 @@ namespace Business
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.ToEntity(parent.DbContext);
{ parent.DbContext.SaveChanges();
toUpdate = newItem.ToEntity(parent.DbContext);
parent.DbContext.SaveChanges();
}catch (DbUpdateException){}
return newItem; return newItem;
} }
} }

@ -16,39 +16,26 @@ namespace Business
public async Task<RunePage?> AddItem(RunePage? item) public async Task<RunePage?> AddItem(RunePage? item)
{ {
try await parent.DbContext.runepages.AddAsync(item.ToEntity(parent.DbContext));
{ parent.DbContext.SaveChanges();
await parent.DbContext.runepages.AddAsync(item.ToEntity(parent.DbContext));
parent.DbContext.SaveChanges();
}
catch (OperationCanceledException) { }
catch (DbUpdateException) { }
return item; return item;
} }
public async Task<bool> DeleteItem(RunePage? item) public async Task<bool> DeleteItem(RunePage? item)
{ {
var toDelete = parent.DbContext.runepages.Find(item.Name);
try if (toDelete != null)
{
var toDelete = parent.DbContext.runepages.Find(item.Name);
if (toDelete != null)
{
parent.DbContext.runepages.Remove(toDelete);
parent.DbContext.SaveChanges();
return true;
}
return false;
}
catch (DbUpdateException)
{ {
return false; parent.DbContext.runepages.Remove(toDelete);
parent.DbContext.SaveChanges();
return true;
} }
return false;
} }
public async Task<IEnumerable<RunePage?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) public async Task<IEnumerable<RunePage?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
{ {
return parent.DbContext.runepages.GetItemsWithFilterAndOrdering( return parent.DbContext.runepages.Include("entries").GetItemsWithFilterAndOrdering(
rp => true, rp => true,
index, count, index, count,
orderingPropertyName, descending).Select(rp => rp.ToModel(parent.DbContext)); orderingPropertyName, descending).Select(rp => rp.ToModel(parent.DbContext));
@ -64,7 +51,7 @@ namespace Business
public async Task<IEnumerable<RunePage?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false) public async Task<IEnumerable<RunePage?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
{ {
return parent.DbContext.runepages.GetItemsWithFilterAndOrdering( return parent.DbContext.runepages.Include("entries").GetItemsWithFilterAndOrdering(
rp => rp.Name.Contains(substring), rp => rp.Name.Contains(substring),
index, count, index, count,
orderingPropertyName, descending).Select(rp => rp.ToModel(parent.DbContext)); orderingPropertyName, descending).Select(rp => rp.ToModel(parent.DbContext));
@ -104,8 +91,6 @@ namespace Business
{ {
var toUpdate = parent.DbContext.runepages.Include("entries") var toUpdate = parent.DbContext.runepages.Include("entries")
.Where(x => x.Name.Equals(newItem.Name)).First(); .Where(x => x.Name.Equals(newItem.Name)).First();
try
{
toUpdate.entries = newItem.Runes.Select(r => new RunePageRuneEntity() toUpdate.entries = newItem.Runes.Select(r => new RunePageRuneEntity()
{ {
category = r.Key, category = r.Key,
@ -114,8 +99,6 @@ namespace Business
parent.DbContext.SaveChanges(); parent.DbContext.SaveChanges();
}
catch (DbUpdateException) { }
return newItem; return newItem;
} }

@ -15,33 +15,21 @@ namespace Business
=> this.parent = parent; => this.parent = parent;
public async Task<Rune?> AddItem(Rune? item) public async Task<Rune?> AddItem(Rune? item)
{ {
try await parent.DbContext.runes.AddAsync(item.ToEntity(parent.DbContext));
{ parent.DbContext.SaveChanges();
await parent.DbContext.runes.AddAsync(item.ToEntity(parent.DbContext));
parent.DbContext.SaveChanges();
}
catch (OperationCanceledException) {}
catch (DbUpdateException) { }
return item; return item;
} }
public async Task<bool> DeleteItem(Rune? item) public async Task<bool> DeleteItem(Rune? item)
{ {
try var toDelete = parent.DbContext.runes.Find(item?.Name);
{ if (toDelete != null)
var toDelete = parent.DbContext.runes.Find(item?.Name);
if (toDelete != null)
{
parent.DbContext.runes.Remove(item?.ToEntity(parent.DbContext));
parent.DbContext.SaveChanges();
return true;
}
return false;
}
catch (DbUpdateException)
{ {
return false; parent.DbContext.runes.Remove(item?.ToEntity(parent.DbContext));
parent.DbContext.SaveChanges();
return true;
} }
return false;
} }
public async Task<IEnumerable<Rune?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) public async Task<IEnumerable<Rune?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
@ -86,14 +74,10 @@ namespace Business
public async Task<Rune?> UpdateItem(Rune? oldItem, Rune? newItem) public async Task<Rune?> UpdateItem(Rune? oldItem, Rune? newItem)
{ {
var toUpdate = parent.DbContext.runes.Find(oldItem.Name); var toUpdate = parent.DbContext.runes.Find(oldItem.Name);
try
{
toUpdate.Description = newItem.Description; toUpdate.Description = newItem.Description;
toUpdate.RuneFamily = newItem.Family; toUpdate.RuneFamily = newItem.Family;
parent.DbContext.SaveChanges(); parent.DbContext.SaveChanges();
}
catch (DbUpdateException) {}
return newItem; return newItem;
} }
} }

@ -15,26 +15,17 @@ namespace Business
public async Task<Skin?> AddItem(Skin? item) public async Task<Skin?> AddItem(Skin? item)
{ {
try { await parent.DbContext.skins.AddAsync(item.ToEntity(parent.DbContext));
await parent.DbContext.skins.AddAsync(item.ToEntity(parent.DbContext)); parent.DbContext.SaveChanges();
parent.DbContext.SaveChanges();
}
catch(OperationCanceledException){}
catch(DbUpdateException) {}
return item; return item;
} }
public async Task<bool> DeleteItem(Skin? item) public async Task<bool> DeleteItem(Skin? item)
{ {
try { var toDelete = parent.DbContext.skins.Find(item.Name);
var toDelete = parent.DbContext.skins.Find(item.Name); parent.DbContext.skins.Remove(toDelete);
parent.DbContext.skins.Remove(toDelete); parent.DbContext.SaveChanges();
parent.DbContext.SaveChanges(); return true;
return true;
}
catch(DbUpdateException) {
return false;
}
} }
public async 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)
@ -85,12 +76,7 @@ namespace Business
public async Task<Skin?> UpdateItem(Skin? oldItem, Skin? newItem) public async Task<Skin?> UpdateItem(Skin? oldItem, Skin? newItem)
{ {
var toUpdate = parent.DbContext.skins.Find(oldItem.Name); var toUpdate = parent.DbContext.skins.Find(oldItem.Name);
try toUpdate.Champion = parent.DbContext.champions.Find(newItem.Champion.Name);
{
toUpdate.Champion = parent.DbContext.champions.Find(newItem.Champion.Name);
}
catch (DbUpdateException) { }
return newItem; return newItem;
} }
} }

@ -0,0 +1,37 @@
using Shared;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Entities
{
public class SkinEntity
{
[Key]
[MaxLength(256)]
public string Name { get; set; }
[Required]
[MaxLength(500)]
public string Description { get; set; }
[Required]
public string Icon { get; set; }
[Required]
public float Price { get; set; }
[Required]
public string ChampionForeignKey { get; set; }
[ForeignKey("ChampionForeignKey")]
public ChampionEntity Champion { get; set; }
public Guid? ImageId { get; set; }
[ForeignKey("ImageId")]
public LargeImageEntity? Image { get; set; }
}
}
Loading…
Cancel
Save