Handlink genre link deletion

This commit is contained in:
Zoe Roux 2020-06-19 19:29:34 +02:00
parent 40c3fcbb91
commit 25274548c4
2 changed files with 16 additions and 4 deletions

View File

@ -1,4 +1,7 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq;
using Kyoo.Models.Attributes;
using Newtonsoft.Json;
namespace Kyoo.Models
{
@ -8,7 +11,13 @@ namespace Kyoo.Models
public string Slug { get; set; }
public string Name { get; set; }
// public IEnumerable<Show> Shows { get; set; }
[NotMergable] [JsonIgnore] public IEnumerable<GenreLink> Links { get; set; }
[NotMergable] [JsonIgnore] public IEnumerable<Show> Shows
{
get => Links.Select(x => x.Show);
set => Links = value?.Select(x => new GenreLink(x, this));
}
public Genre() {}

View File

@ -115,8 +115,11 @@ namespace Kyoo.Controllers
{
if (obj == null)
throw new ArgumentNullException(nameof(obj));
_database.Genres.Remove(obj);
_database.Entry(obj).State = EntityState.Deleted;
if (obj.Links != null)
foreach (GenreLink link in obj.Links)
_database.Entry(link).State = EntityState.Deleted;
await _database.SaveChangesAsync();
}
}