public static async Task <List <IContentCommon> > RelatedContentReferencesFromOtherContent(
            this PointlessWaymarksContext toQuery, Guid toCheckFor, DateTime?generationVersion)
        {
            if (generationVersion == null)
            {
                var posts = await toQuery.PostContents.Where(x => x.BodyContent.Contains(toCheckFor.ToString()))
                            .Cast <IContentCommon>().ToListAsync();

                var notes = await toQuery.NoteContents.Where(x => x.BodyContent.Contains(toCheckFor.ToString()))
                            .Cast <IContentCommon>().ToListAsync();

                var files = await toQuery.FileContents.Where(x => x.BodyContent.Contains(toCheckFor.ToString()))
                            .Cast <IContentCommon>().ToListAsync();

                return(posts.Concat(notes).Concat(files).OrderByDescending(x => x.LastUpdatedOn ?? x.CreatedOn)
                       .ToList());
            }

            var db = await Db.Context();

            var referencesFromOtherContent = await db.GenerationRelatedContents
                                             .Where(x => x.GenerationVersion == generationVersion && x.ContentTwo == toCheckFor)
                                             .Select(x => x.ContentOne).Distinct().ToListAsync();

            var otherReferences = await db.ContentFromContentIds(referencesFromOtherContent);

            var typeFilteredReferences = new List <IContentCommon>();

            foreach (var loopContent in otherReferences)
            {
                switch (loopContent)
                {
                case FileContent content:
                {
                    typeFilteredReferences.Add(content);
                    break;
                }

                case PostContent content:
                {
                    typeFilteredReferences.Add(content);
                    break;
                }

                case NoteContent content:
                {
                    typeFilteredReferences.Add(content);
                    break;
                }
                }
            }

            return(typeFilteredReferences.OrderByDescending(x => x.LastUpdatedOn ?? x.CreatedOn).ToList());
        }
        public static async Task <List <IContentCommon> > RelatedContent(this PointlessWaymarksContext toQuery,
                                                                         Guid toCheckFor)
        {
            var posts = await toQuery.PostContents.Where(x => x.BodyContent.Contains(toCheckFor.ToString()))
                        .Cast <IContentCommon>().ToListAsync();

            var notes = await toQuery.NoteContents.Where(x => x.BodyContent.Contains(toCheckFor.ToString()))
                        .Cast <IContentCommon>().ToListAsync();

            var files = await toQuery.FileContents.Where(x => x.BodyContent.Contains(toCheckFor.ToString()))
                        .Cast <IContentCommon>().ToListAsync();

            return(posts.Concat(notes).Concat(files).OrderByDescending(x => x.LastUpdatedOn ?? x.CreatedOn).ToList());
        }
        public static async Task <bool> SlugExistsInDatabase(this PointlessWaymarksContext context, string slug,
                                                             Guid?excludedContentId)
        {
            if (string.IsNullOrWhiteSpace(slug))
            {
                return(false);
            }

            //!!Content Type List!!
            if (excludedContentId == null)
            {
                var fileCheck = await context.FileContents.AnyAsync(x => x.Slug == slug);

                var imageCheck = await context.ImageContents.AnyAsync(x => x.Slug == slug);

                var noteCheck = await context.NoteContents.AnyAsync(x => x.Slug == slug);

                var photoCheck = await context.PhotoContents.AnyAsync(x => x.Slug == slug);

                var pointCheck = await context.PointContents.AnyAsync(x => x.Slug == slug);

                var postCheck = await context.PostContents.AnyAsync(x => x.Slug == slug);

                return(photoCheck || postCheck || imageCheck || noteCheck || fileCheck || pointCheck);
            }

            var fileExcludeCheck =
                await context.FileContents.AnyAsync(x => x.Slug == slug && x.ContentId != excludedContentId);

            var imageExcludeCheck =
                await context.ImageContents.AnyAsync(x => x.Slug == slug && x.ContentId != excludedContentId);

            var noteExcludeCheck =
                await context.NoteContents.AnyAsync(x => x.Slug == slug && x.ContentId != excludedContentId);

            var photoExcludeCheck =
                await context.PhotoContents.AnyAsync(x => x.Slug == slug && x.ContentId != excludedContentId);

            var pointExcludeCheck =
                await context.PointContents.AnyAsync(x => x.Slug == slug && x.ContentId != excludedContentId);

            var postExcludeCheck =
                await context.PostContents.AnyAsync(x => x.Slug == slug && x.ContentId != excludedContentId);


            return(photoExcludeCheck || postExcludeCheck || imageExcludeCheck || noteExcludeCheck || fileExcludeCheck ||
                   pointExcludeCheck);
        }
示例#4
0
        public static async Task ExtractAndWriteRelatedContentDbReferencesFromString(Guid sourceGuid, string toSearch,
                                                                                     PointlessWaymarksContext db, IProgress <string> progress)
        {
            if (string.IsNullOrWhiteSpace(toSearch))
            {
                return;
            }

            var toAdd = BracketCodeCommon.BracketCodeContentIds(toSearch);

            if (!toAdd.Any())
            {
                return;
            }

            var dbEntries = toAdd.Select(x => new GenerationRelatedContent {
                ContentOne = sourceGuid, ContentTwo = x
            });

            await db.GenerationRelatedContents.AddRangeAsync(dbEntries);
        }
        public static async Task <bool> PhotoFilenameExistsInDatabase(this PointlessWaymarksContext context,
                                                                      string filename, Guid?exceptInThisContent)
        {
            if (string.IsNullOrWhiteSpace(filename))
            {
                return(false);
            }

            bool photoCheck;

            if (exceptInThisContent == null)
            {
                photoCheck = await context.PhotoContents.AnyAsync(x =>
                                                                  x.OriginalFileName.ToLower() == filename.ToLower());
            }
            else
            {
                photoCheck = await context.PhotoContents.AnyAsync(x =>
                                                                  x.OriginalFileName.ToLower() == filename.ToLower() && x.ContentId != exceptInThisContent.Value);
            }

            return(photoCheck);
        }
示例#6
0
        public static async Task ExtractAndWriteRelatedContentDbReferences(DateTime generationVersion,
                                                                           IContentCommon content, PointlessWaymarksContext db, IProgress <string> progress)
        {
            var toAdd = new List <Guid>();

            if (content.MainPicture != null && content.MainPicture != content.ContentId)
            {
                toAdd.Add(content.MainPicture.Value);
            }

            var toSearch = string.Empty;

            toSearch += content.BodyContent + content.Summary;

            if (content is IUpdateNotes updateContent)
            {
                toSearch += updateContent.UpdateNotes;
            }

            if (string.IsNullOrWhiteSpace(toSearch) && !toAdd.Any())
            {
                return;
            }

            toAdd.AddRange(BracketCodeCommon.BracketCodeContentIds(toSearch));

            if (!toAdd.Any())
            {
                return;
            }

            var dbEntries = toAdd.Distinct().Select(x => new GenerationRelatedContent
            {
                ContentOne = content.ContentId, ContentTwo = x, GenerationVersion = generationVersion
            });

            await db.GenerationRelatedContents.AddRangeAsync(dbEntries);

            await db.SaveChangesAsync();
        }
示例#7
0
        public static async Task ExtractAndWriteRelatedContentDbReferences(DateTime generationVersion,
                                                                           List <IContentCommon> content, PointlessWaymarksContext db, IProgress <string> progress)
        {
            if (content == null || !content.Any())
            {
                return;
            }

            foreach (var loopContent in content)
            {
                await ExtractAndWriteRelatedContentDbReferences(generationVersion, loopContent, db, progress);
            }
        }
示例#8
0
        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"));
        }
示例#9
0
        public static async Task <List <GenerationReturn> > CheckForBadContentReferences(List <IContentCommon> content,
                                                                                         PointlessWaymarksContext db, IProgress <string> progress)
        {
            var returnList = new List <GenerationReturn>();

            if (content == null || !content.Any())
            {
                return(returnList);
            }

            foreach (var loopContent in content)
            {
                returnList.Add(await CheckForBadContentReferences(loopContent, db, progress));
            }

            return(returnList);
        }
示例#10
0
        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"));
        }