From eb744d46a103da002e30cd1dee02adeafd0af56c Mon Sep 17 00:00:00 2001 From: jvyden Date: Sun, 7 Nov 2021 18:06:49 -0500 Subject: [PATCH] Fix PhotoSubjects not being added and parsed properly --- ProjectLighthouse/Controllers/PhotosController.cs | 11 ++++++++--- ProjectLighthouse/Types/Photo.cs | 6 ++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/ProjectLighthouse/Controllers/PhotosController.cs b/ProjectLighthouse/Controllers/PhotosController.cs index 89c96849..3a4ac80b 100644 --- a/ProjectLighthouse/Controllers/PhotosController.cs +++ b/ProjectLighthouse/Controllers/PhotosController.cs @@ -5,6 +5,7 @@ using System.IO; using System.Linq; using System.Threading.Tasks; using System.Xml.Serialization; +using Kettu; using LBPUnion.ProjectLighthouse.Serialization; using LBPUnion.ProjectLighthouse.Types; using Microsoft.AspNetCore.Mvc; @@ -40,21 +41,25 @@ namespace LBPUnion.ProjectLighthouse.Controllers photo.CreatorId = user.UserId; photo.Creator = user; - foreach (PhotoSubject subject in photo.SubjectsXmlDontUse) // fine for here + foreach (PhotoSubject subject in photo.Subjects) { subject.User = await this.database.Users.FirstOrDefaultAsync(u => u.Username == subject.Username); if (subject.User == null) return this.BadRequest(); subject.UserId = subject.User.UserId; + Logger.Log($"Adding PhotoSubject (userid {subject.UserId}) to db"); this.database.PhotoSubjects.Add(subject); } await this.database.SaveChangesAsync(); - photo.PhotoSubjectCollection = photo.Subjects.Aggregate(string.Empty, (s, subject) => s + subject.PhotoSubjectId); -// photo.Slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == photo.SlotId); + photo.PhotoSubjectIds = photo.Subjects.Select(subject => subject.PhotoSubjectId.ToString()).ToArray(); + + // photo.Slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == photo.SlotId); + + Logger.Log($"Adding PhotoSubjectCollection ({photo.PhotoSubjectCollection}) to photo"); this.database.Photos.Add(photo); diff --git a/ProjectLighthouse/Types/Photo.cs b/ProjectLighthouse/Types/Photo.cs index 48346c7d..2bafa2bb 100644 --- a/ProjectLighthouse/Types/Photo.cs +++ b/ProjectLighthouse/Types/Photo.cs @@ -39,14 +39,12 @@ namespace LBPUnion.ProjectLighthouse.Types [NotMapped] [XmlArray("subjects")] [XmlArrayItem("subject")] - public List SubjectsXmlDontUse { - get => null!; - set => Subjects = value; - } + public List? SubjectsXmlDontUseLiterallyEver; [NotMapped] public List Subjects { get { + if (this.SubjectsXmlDontUseLiterallyEver != null) return this.SubjectsXmlDontUseLiterallyEver; if (this.subjects != null) return this.subjects; List response = new();