Exemplo n.º 1
0
        IQueryable <Message> FindAnywhere(string searchString)
        {
            var messages = FindByMessage(searchString)
                           .Union(FindBySeries(searchString));

            if (BibleReferenceValidation.Validate(searchString) == ValidationResult.Success)
            {
                messages = messages.Union(FindByBibleReference(searchString));
            }
            return(messages);
        }
Exemplo n.º 2
0
        IQueryable <Message> FindByBibleReference(string searchString)
        {
            var validationResult = BibleReferenceValidation.Validate(searchString);
            var messages         = GetNoMessages();

            if (validationResult != ValidationResult.Success)
            {
                ViewData["SearchErrorMessage"] = validationResult.ErrorMessage;
                return(messages);
            }

            var bibleReferences = Parser.TryParse(searchString);

            if (bibleReferences != null && bibleReferences.Count == 1)
            {
                // x1 <= y2 && y1 <= x2
                var x = BibleReferenceRange.From(bibleReferences[0].GetExplicitRange());
                var matchingReferences = from y in _context.BibleReferences
                                         where (
                    (x.StartBook < y.EndBook) ||
                    (x.StartBook == y.EndBook && x.StartChapter < y.EndChapter) ||
                    (x.StartBook == y.EndBook && x.StartChapter == y.EndChapter && x.StartVerse <= y.EndVerse)
                    ) &&
                                         (
                    (y.StartBook < x.EndBook) ||
                    (y.StartBook == x.EndBook && y.StartChapter < x.EndChapter) ||
                    (y.StartBook == x.EndBook && y.StartChapter == x.EndChapter && y.StartVerse <= x.EndVerse)
                                         )
                                         select y;

                messages = GetAllMessages()
                           .Join(matchingReferences,
                                 m => m.Id,
                                 r => r.MessageId,
                                 (m, r) => m);
                foreach (var reference in matchingReferences)
                {
                    MatchingBibleReferences.Add(reference.ToFriendlyString());
                }
            }
            return(messages);
        }