public static async Task <GenerationReturn> CheckStringForBadContentReferences(string toSearch, PointlessWaymarksContext db, IProgress <string> progress) { var extracted = new List <Guid>(); if (string.IsNullOrWhiteSpace(toSearch)) { return(await GenerationReturn.Success("No Content Ids Found")); } extracted.AddRange(BracketCodeCommon.BracketCodeContentIds(toSearch)); if (!extracted.Any()) { return(await GenerationReturn.Success("No Content Ids Found")); } progress?.Report($"Found {extracted.Count} ContentIds to check for"); var notFoundList = new List <Guid>(); foreach (var loopExtracted in extracted) { var contentLookup = await db.ContentFromContentId(loopExtracted); if (contentLookup == null) { progress?.Report($"ContentId {loopExtracted} Not Found in Db..."); notFoundList.Add(loopExtracted); } } if (notFoundList.Any()) { return(await GenerationReturn.Error( $"Invalid ContentIds in Bracket Codes - {string.Join(", ", notFoundList)}")); } return(await GenerationReturn.Success("No Invalid Content Ids Found")); }
public static async Task <GenerationReturn> CheckForBadContentReferences(IContentCommon content, PointlessWaymarksContext db, IProgress <string> progress) { progress?.Report($"Checking ContentIds for {content.Title}"); var extracted = new List <Guid>(); if (content.MainPicture != null && content.MainPicture != content.ContentId) { extracted.Add(content.MainPicture.Value); } var toSearch = string.Empty; toSearch += content.BodyContent + content.Summary; if (content is IUpdateNotes updateContent) { toSearch += updateContent.UpdateNotes; } if (content is PointContentDto pointDto) { pointDto.PointDetails.ForEach(x => toSearch += x.StructuredDataAsJson); } if (content is PointContent point) { (await Db.PointDetailsForPoint(point.ContentId, db)).ForEach(x => toSearch += x.StructuredDataAsJson); } if (string.IsNullOrWhiteSpace(toSearch) && !extracted.Any()) { return(await GenerationReturn.Success( $"{Db.ContentTypeString(content)} {content.Title} - No Content Ids Found", content.ContentId)); } extracted.AddRange(BracketCodeCommon.BracketCodeContentIds(toSearch)); if (!extracted.Any()) { return(await GenerationReturn.Success( $"{Db.ContentTypeString(content)} {content.Title} - No Content Ids Found", content.ContentId)); } progress?.Report($"Found {extracted.Count} ContentIds to check for {content.Title}"); var notFoundList = new List <Guid>(); foreach (var loopExtracted in extracted) { var contentLookup = await db.ContentFromContentId(loopExtracted); if (contentLookup != null) { continue; } if (await db.MapComponents.AnyAsync(x => x.ContentId == loopExtracted)) { continue; } progress?.Report($"ContentId {loopExtracted} Not Found in Db..."); notFoundList.Add(loopExtracted); } if (notFoundList.Any()) { return(await GenerationReturn.Error( $"{Db.ContentTypeString(content)} {content.Title} has " + $"Invalid ContentIds in Bracket Codes - {string.Join(", ", notFoundList)}", content.ContentId)); } return(await GenerationReturn.Success( $"{Db.ContentTypeString(content)} {content.Title} - No Invalid Content Ids Found")); }