Exemple #1
0
        public IEnumerable <HadithViewModel> Create(IEnumerable <Hadith> hadiths)
        {
            var result = new List <HadithViewModel>();

            foreach (Hadith hadith in hadiths)
            {
                string           collectionCode = hadith.References[0].CollectionCode;
                HadithCollection collection     = HadithCollectionRepository.Get(collectionCode);
                var references = new List <HadithReferenceViewModel>();
                foreach (HadithReference reference in hadith.References)
                {
                    HadithReferenceDefinition referenceDefinition =
                        collection.GetReferenceDefinition(reference.ReferenceCode);
                    var referenceViewModel = new HadithReferenceViewModel(
                        collectionCode: collection.Code,
                        collectionName: collection.Name,
                        indexCode: referenceDefinition.Code,
                        indexName: referenceDefinition.Name,
                        partNamesAndValues: reference.ToNameValuePairs(referenceDefinition));
                    references.Add(referenceViewModel);
                }
                var viewModel = new HadithViewModel(
                    collectionName: collection.Name,
                    hadith: hadith,
                    references: references);
                result.Add(viewModel);
            }
            return(result);
        }
        public HadithCollection Create(string hadithFilePath, string additionalHadithXRefsDirectory)
        {
            var doc            = XDocument.Load(File.OpenText(hadithFilePath));
            var collectionNode = doc.Document.Root;

            string code      = collectionNode.Element("code").Value;
            string name      = collectionNode.Element("name").Value;
            string copyright = collectionNode.Element("copyright").Value;

            string[] referencePartNames = ReadRefeferenceDefinition(collectionNode);

            CreateAdditionalHadithXRefs(
                tafsirCode: code,
                xrefsDirectory: additionalHadithXRefsDirectory
                );

            Collection = new HadithCollection(
                code: code,
                name: name,
                copyRight: copyright,
                referencePartNames: referencePartNames
                );
            ReadHadiths(collectionNode);
            return(Collection);
        }
        public void Write(HadithCollection collection)
        {
            var document = new Document();

            document.AddObject(collection);

            IndexWriter indexWriter = IndexWriterProvider.GetIndexWriter();

            indexWriter.AddDocument(document);
        }
Exemple #4
0
 public HadithIndexHeaderViewModel(
     string selectedReferenceCode,
     string urlSoFar,
     HadithCollection collection,
     IEnumerable <string> referencePartNamesAndValues)
 {
     SelectedReferenceCode = selectedReferenceCode;
     UrlSoFar   = urlSoFar;
     Collection = collection;
     ReferencePartNamesAndValues = referencePartNamesAndValues;
 }
        private void GetHadithUrl(Document document, out string url, out string caption)
        {
            string collectionCode       = document.GetStoredValue <Hadith>(x => x.CollectionCode);
            string primaryReferenceCode = document.GetStoredValue <Hadith>(x => x.PrimaryReferenceCode);
            string primaryReferencePath = document.GetStoredValue <Hadith>(x => x.PrimaryReferencePath);

            HadithCollection collection = HadithCollectionRepository.Get(collectionCode);

            url     = $"/Hadith/{collectionCode}/{primaryReferenceCode}/{primaryReferencePath}";
            caption = $"{collection.Name} {primaryReferencePath.Replace("/", ", ").Replace("-", " ")}";
        }
 public HadithCollectionXmlWriter(HadithCollection collection)
 {
     this.Collection = collection;
 }
Exemple #7
0
        public ActionResult Index(string collectionCode, string referenceCode,
                                  string referenceValue1, string referenceValue2, string referenceValue3)
        {
            HadithCollection collection = HadithCollectionRepository.Get(collectionCode);

            if (collection == null)
            {
                return(HttpNotFound());
            }

            var referencePartNamesAndValues = new List <(string referencePartName, int value, string suffix)>();

            if (!string.IsNullOrWhiteSpace(referenceValue1))
            {
                referencePartNamesAndValues.Add(HadithReference.SplitNameAndValue(referenceValue1));
            }
            if (!string.IsNullOrWhiteSpace(referenceValue2))
            {
                referencePartNamesAndValues.Add(HadithReference.SplitNameAndValue(referenceValue2));
            }
            if (!string.IsNullOrWhiteSpace(referenceValue3))
            {
                referencePartNamesAndValues.Add(HadithReference.SplitNameAndValue(referenceValue3));
            }

            IEnumerable <string> referencePartNames = referencePartNamesAndValues
                                                      .Select(x => x.referencePartName);
            HadithReferenceDefinition referenceDefinition = collection.GetReferenceDefinition(referenceCode);

            if (referenceDefinition == null && referenceCode.Contains("-"))
            {
                return(RedirectForMissingIndexCode(collectionCode, referenceCode, collection, referencePartNamesAndValues, referencePartNames, ref referenceDefinition));
            }

            if (referenceDefinition == null || !referenceDefinition.PatternMatch(referencePartNames))
            {
                return(HttpNotFound());
            }

            IEnumerable <(int value, string suffix)> referenceValues =
                referencePartNamesAndValues.Select(x => (x.value, x.suffix));
            IEnumerable <HadithReference> hadithReferences =
                HadithRepository.GetReferences(
                    collectionCode: collectionCode,
                    referenceCode: referenceCode,
                    values: referenceValues);

            IEnumerable <string> urlReferenceParts = referencePartNamesAndValues
                                                     .Select(x => x.value + x.suffix)
                                                     .Select((value, i) => referenceDefinition.PartNames[i] + "-" + value);
            string partsAsUrl = string.Join("/", urlReferenceParts);
            string urlSoFar   = $"/hadith/{collectionCode}/{referenceCode}/{partsAsUrl}";

            if (urlSoFar.EndsWith("/"))
            {
                urlSoFar = urlSoFar.Substring(0, urlSoFar.Length - 1);
            }
            var headerViewModel = new HadithIndexHeaderViewModel(
                selectedReferenceCode: referenceCode,
                urlSoFar: urlSoFar,
                collection: collection,
                referencePartNamesAndValues: urlReferenceParts);

            if (referencePartNames.Count() == referenceDefinition.PartNames.Count)
            {
                IEnumerable <int>             hadithIds        = hadithReferences.Select(x => x.HadithId);
                IEnumerable <Hadith>          hadiths          = HadithRepository.GetHadiths(hadithIds);
                IEnumerable <HadithViewModel> hadithViewModels = HadithViewModelFactory.Create(hadiths);
                var viewModel = new HadithsViewModel(headerViewModel, hadithViewModels);
                return(View("Hadiths", viewModel));
            }
            else
            {
                string nextReferencePartName = referenceDefinition.PartNames[referencePartNames.Count()];
                Func <HadithReference, string> getNextValue;
                switch (referencePartNames.Count())
                {
                case 0:
                    getNextValue = x => x.ReferenceValue1 + x.ReferenceValue1Suffix;
                    break;

                case 1:
                    getNextValue = x => x.ReferenceValue2 + x.ReferenceValue2Suffix;
                    break;

                case 2:
                    getNextValue = x => x.ReferenceValue3 + x.ReferenceValue3Suffix;
                    break;

                default:
                    throw new NotImplementedException();
                }
                // If the next level is the final level (the hadith itself) then remove the suffix
                // from the final part so that all hadiths with the same reference but different
                // suffixes are shown on screen at once.
                hadithReferences = hadithReferences
                                   .Select(x => x.ExcludingFinalSuffix())
                                   .Distinct()
                                   .OrderBy(x => x);
                // Get the next available values
                IEnumerable <string> nextReferencePartValues = hadithReferences
                                                               .Select(getNextValue)
                                                               .Distinct();
                var viewModel = new BrowseHadithIndexViewModel(
                    hadithIndexHeaderViewModel: headerViewModel,
                    nextReferencePartName: nextReferencePartName,
                    nextReferencePartValueSelection: nextReferencePartValues);
                return(View("BrowseHadithIndex", viewModel));
            }
        }
Exemple #8
0
 private ActionResult RedirectForMissingIndexCode(string collectionCode, string referenceCode, HadithCollection collection, List <(string referencePartName, int value, string suffix)> referencePartNamesAndValues, IEnumerable <string> referencePartNames, ref HadithReferenceDefinition referenceDefinition)