Merge branch 'LBPUnion:main' into main

This commit is contained in:
LumaLivy 2021-11-07 18:37:53 -05:00 committed by GitHub
commit 6be05dff82
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 8 deletions

View file

@ -5,6 +5,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Serialization; using System.Xml.Serialization;
using Kettu;
using LBPUnion.ProjectLighthouse.Serialization; using LBPUnion.ProjectLighthouse.Serialization;
using LBPUnion.ProjectLighthouse.Types; using LBPUnion.ProjectLighthouse.Types;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -40,21 +41,25 @@ namespace LBPUnion.ProjectLighthouse.Controllers
photo.CreatorId = user.UserId; photo.CreatorId = user.UserId;
photo.Creator = user; 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); subject.User = await this.database.Users.FirstOrDefaultAsync(u => u.Username == subject.Username);
if (subject.User == null) return this.BadRequest(); if (subject.User == null) continue;
subject.UserId = subject.User.UserId; subject.UserId = subject.User.UserId;
Logger.Log($"Adding PhotoSubject (userid {subject.UserId}) to db");
this.database.PhotoSubjects.Add(subject); this.database.PhotoSubjects.Add(subject);
} }
await this.database.SaveChangesAsync(); await this.database.SaveChangesAsync();
photo.PhotoSubjectCollection = photo.Subjects.Aggregate(string.Empty, (s, subject) => s + subject.PhotoSubjectId); photo.PhotoSubjectIds = photo.Subjects.Select(subject => subject.PhotoSubjectId.ToString()).ToArray();
// photo.Slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == photo.SlotId);
// 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); this.database.Photos.Add(photo);

View file

@ -39,14 +39,12 @@ namespace LBPUnion.ProjectLighthouse.Types
[NotMapped] [NotMapped]
[XmlArray("subjects")] [XmlArray("subjects")]
[XmlArrayItem("subject")] [XmlArrayItem("subject")]
public List<PhotoSubject> SubjectsXmlDontUse { public List<PhotoSubject>? SubjectsXmlDontUseLiterallyEver;
get => null!;
set => Subjects = value;
}
[NotMapped] [NotMapped]
public List<PhotoSubject> Subjects { public List<PhotoSubject> Subjects {
get { get {
if (this.SubjectsXmlDontUseLiterallyEver != null) return this.SubjectsXmlDontUseLiterallyEver;
if (this.subjects != null) return this.subjects; if (this.subjects != null) return this.subjects;
List<PhotoSubject> response = new(); List<PhotoSubject> response = new();