From 591814bee9f9acac1f701936f2ba7c8c5f3da4ed Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Thu, 27 Jul 2023 15:41:13 +0330 Subject: [PATCH] #402 bug fix --- .../PDFLibraryService-SohaLibrary.cs | 110 +++++++++--------- 1 file changed, 56 insertions(+), 54 deletions(-) diff --git a/RMuseum/Services/Implementation/PDFLibraryService-Partials/PDFLibraryService-SohaLibrary.cs b/RMuseum/Services/Implementation/PDFLibraryService-Partials/PDFLibraryService-SohaLibrary.cs index fb7fc068..33a1744b 100644 --- a/RMuseum/Services/Implementation/PDFLibraryService-Partials/PDFLibraryService-SohaLibrary.cs +++ b/RMuseum/Services/Implementation/PDFLibraryService-Partials/PDFLibraryService-SohaLibrary.cs @@ -181,61 +181,7 @@ namespace RMuseum.Services.Implementation } } - string bookTitle = model.Title; - int volumeNumber = 0; - if (bookTitle.Contains("ـ ج")) - { - bookTitle = bookTitle.Substring(0, model.Title.IndexOf("ـ ج") - 1); - int.TryParse(model.Title.Substring(model.Title.IndexOf("ـ ج") + "ـ ج".Length).Trim(), out volumeNumber); - } - bookTitle = bookTitle.ToPersianNumbers().ApplyCorrectYeKe().Trim(); - model.Title = model.Title.ToPersianNumbers().ApplyCorrectYeKe().Trim(); - - var book = await context.Books.AsNoTracking().Where(b => b.Name == bookTitle).FirstOrDefaultAsync(); - if (book != null) - { - model.BookId = book.Id; - } - else - { - Book newBook = new Book() - { - Name = bookTitle, - Description = "", - LastModified = DateTime.Now, - }; - context.Books.Add(newBook); - await context.SaveChangesAsync(); - model.BookId = newBook.Id; - } - - if (volumeNumber != 0) - { - MultiVolumePDFCollection collection = await context.MultiVolumePDFCollections.Where(v => v.Name == bookTitle && v.BookId == model.BookId).SingleOrDefaultAsync(); - if (collection != null) - { - model.MultiVolumePDFCollectionId = collection.Id; - - collection.VolumeCount += 1; - context.Update(collection); - await context.SaveChangesAsync(); - - } - else - { - MultiVolumePDFCollection newCollection = new MultiVolumePDFCollection() - { - Name = bookTitle, - BookId = model.BookId, - Description = "", - VolumeCount = 1, - }; - context.MultiVolumePDFCollections.Add(newCollection); - await context.SaveChangesAsync(); - model.MultiVolumePDFCollectionId = newCollection.Id; - } - } idxStart = html.IndexOf("width-150"); while (idxStart != -1) @@ -388,6 +334,62 @@ namespace RMuseum.Services.Implementation } + string bookTitle = model.Title; + int volumeNumber = 0; + if (bookTitle.Contains("ـ ج")) + { + bookTitle = bookTitle.Substring(0, model.Title.IndexOf("ـ ج") - 1); + int.TryParse(model.Title.Substring(model.Title.IndexOf("ـ ج") + "ـ ج".Length).Trim(), out volumeNumber); + } + + bookTitle = bookTitle.ToPersianNumbers().ApplyCorrectYeKe().Trim(); + model.Title = model.Title.ToPersianNumbers().ApplyCorrectYeKe().Trim(); + + var book = await context.Books.AsNoTracking().Where(b => b.Name == bookTitle).FirstOrDefaultAsync(); + if (book != null) + { + model.BookId = book.Id; + } + else + { + Book newBook = new Book() + { + Name = bookTitle, + Description = "", + LastModified = DateTime.Now, + }; + context.Books.Add(newBook); + await context.SaveChangesAsync(); + model.BookId = newBook.Id; + } + + if (volumeNumber != 0) + { + MultiVolumePDFCollection collection = await context.MultiVolumePDFCollections.Where(v => v.Name == bookTitle && v.BookId == model.BookId).SingleOrDefaultAsync(); + if (collection != null) + { + model.MultiVolumePDFCollectionId = collection.Id; + + collection.VolumeCount += 1; + context.Update(collection); + await context.SaveChangesAsync(); + + } + else + { + MultiVolumePDFCollection newCollection = new MultiVolumePDFCollection() + { + Name = bookTitle, + BookId = model.BookId, + Description = "", + VolumeCount = 1, + }; + context.MultiVolumePDFCollections.Add(newCollection); + await context.SaveChangesAsync(); + model.MultiVolumePDFCollectionId = newCollection.Id; + } + } + idx = html.IndexOf("/item/download/"); int idxQuote = html.IndexOf('"', idx); string downloadUrl = html.Substring(idx, idxQuote - idx);