diff options
Diffstat (limited to 'Services/MediaService.cs')
| -rw-r--r-- | Services/MediaService.cs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Services/MediaService.cs b/Services/MediaService.cs new file mode 100644 index 0000000..be2657a --- /dev/null +++ b/Services/MediaService.cs @@ -0,0 +1,28 @@ +using Microsoft.EntityFrameworkCore; + +namespace HyperBooru.Services; + +public interface IMediaService { + public void SetIngest(Media media, bool ingest); +} + +public class MediaService : IMediaService { + private IDbContextFactory<HBContext> dbFactory; + + public MediaService(IDbContextFactory<HBContext> dbFactory) => + this.dbFactory = dbFactory; + + public void SetIngest(Media media, bool ingest) { + using var db = dbFactory.CreateDbContext(); + var ingestTag = db.TagDefinitions + .First(td => td.Source == TagSource.Internal && td.Name == "ingest"); + + if(ingest) + media.Tags.Add(new() { TagDefinition = ingestTag }); + else + media.Tags.Remove( + media.Tags.First(t => t.TagDefinition.Guid == ingestTag.Guid)); + + db.SaveChanges(); + } +} |
