parent
8bf9e142d1
commit
dcf21afc01
@ -1,11 +1,11 @@
|
||||
using FluentFTP;
|
||||
using FluentFTP.Client.BaseClient;
|
||||
using ganjoor;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using RMuseum.DbContext;
|
||||
using RMuseum.Models.Artifact;
|
||||
using RMuseum.Models.ImportJob;
|
||||
using RMuseum.Models.PDFLibrary;
|
||||
using RMuseum.Models.PDFLibrary.ViewModels;
|
||||
using RSecurityBackend.Models.Generic;
|
||||
using RSecurityBackend.Models.Image;
|
||||
using RSecurityBackend.Services.Implementation;
|
||||
@ -20,7 +20,147 @@ namespace RMuseum.Services.Implementation
|
||||
{
|
||||
public partial class PDFLibraryService
|
||||
{
|
||||
private async Task<RServiceResult<PDFBook>> ImportLocalPDFFileAsync(RMuseumDbContext context, NewPDFBookViewModel model, string fileChecksum)
|
||||
{
|
||||
try
|
||||
{
|
||||
var pdfRes = await ImportLocalPDFFileAsync(context, model.BookId, model.MultiVolumePDFCollectionId, model.VolumeOrder, model.LocalImportingPDFFilePath, model.OriginalSourceUrl, model.SkipUpload, fileChecksum);
|
||||
if (pdfRes.Result != null)
|
||||
{
|
||||
var pdfBook = pdfRes.Result;
|
||||
pdfBook.Title = model.Title;
|
||||
pdfBook.SubTitle = model.SubTitle;
|
||||
pdfBook.AuthorsLine = model.AuthorsLine;
|
||||
pdfBook.ISBN = model.ISBN;
|
||||
pdfBook.Description = model.Description;
|
||||
pdfBook.IsTranslation = model.IsTranslation;
|
||||
pdfBook.TranslatorsLine = model.TranslatorsLine;
|
||||
pdfBook.TitleInOriginalLanguage = model.TitleInOriginalLanguage;
|
||||
pdfBook.PublisherLine = model.PublisherLine;
|
||||
pdfBook.PublishingDate = model.PublishingDate;
|
||||
pdfBook.PublishingLocation = model.PublishingLocation;
|
||||
pdfBook.PublishingNumber = model.PublishingNumber == 0 ? null : model.PublishingNumber;
|
||||
pdfBook.ClaimedPageCount = model.ClaimedPageCount == 0 ? null : model.ClaimedPageCount;
|
||||
pdfBook.OriginalSourceName = model.OriginalSourceName;
|
||||
pdfBook.OriginalFileUrl = model.OriginalFileUrl;
|
||||
pdfBook.PDFSourceId = model.PDFSourceId;
|
||||
pdfBook.BookScriptType = model.BookScriptType;
|
||||
List<AuthorRole> roles = new List<AuthorRole>();
|
||||
if (model.WriterId != null)
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.WriterId).SingleAsync(),
|
||||
Role = "نویسنده",
|
||||
});
|
||||
}
|
||||
if (model.Writer2Id != null)
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.Writer2Id).SingleAsync(),
|
||||
Role = "نویسنده",
|
||||
});
|
||||
}
|
||||
if (model.Writer3Id != null)
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.Writer3Id).SingleAsync(),
|
||||
Role = "نویسنده",
|
||||
});
|
||||
}
|
||||
if (model.Writer4Id != null)
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.Writer4Id).SingleAsync(),
|
||||
Role = "نویسنده",
|
||||
});
|
||||
}
|
||||
if (model.TranslatorId != null)
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.TranslatorId).SingleAsync(),
|
||||
Role = "مترجم",
|
||||
});
|
||||
}
|
||||
if (model.Translator2Id != null)
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.Translator2Id).SingleAsync(),
|
||||
Role = "مترجم",
|
||||
});
|
||||
}
|
||||
if (model.Translator3Id != null)
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.Translator3Id).SingleAsync(),
|
||||
Role = "مترجم",
|
||||
});
|
||||
}
|
||||
if (model.Translator4Id != null)
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.Translator4Id).SingleAsync(),
|
||||
Role = "مترجم",
|
||||
});
|
||||
}
|
||||
if (model.CollectorId != null)
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.CollectorId).SingleAsync(),
|
||||
Role = "مصحح",
|
||||
});
|
||||
}
|
||||
if (model.Collector2Id != null)
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.Collector2Id).SingleAsync(),
|
||||
Role = "مصحح",
|
||||
});
|
||||
}
|
||||
if (model.OtherContributerId != null && !string.IsNullOrEmpty(model.OtherContributerRole))
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.OtherContributerId).SingleAsync(),
|
||||
Role = model.OtherContributerRole,
|
||||
});
|
||||
}
|
||||
if (model.OtherContributer2Id != null && !string.IsNullOrEmpty(model.OtherContributer2Role))
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.OtherContributer2Id).SingleAsync(),
|
||||
Role = model.OtherContributer2Role,
|
||||
});
|
||||
}
|
||||
if (roles.Count > 0)
|
||||
{
|
||||
pdfBook.Contributers = roles;
|
||||
}
|
||||
context.Update(pdfBook);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
return new RServiceResult<PDFBook>(pdfBook);
|
||||
}
|
||||
return pdfRes;
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return new RServiceResult<PDFBook>(null, exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<RServiceResult<PDFBook>> ImportLocalPDFFileAsync(RMuseumDbContext context, int bookId, int? volumeId, int volumeOrder, string filePath, string srcUrl, bool skipUpload, string fileChecksum)
|
||||
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@ -0,0 +1,23 @@
|
||||
using FluentFTP;
|
||||
using FluentFTP.Client.BaseClient;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using RMuseum.DbContext;
|
||||
using RMuseum.Models.Artifact;
|
||||
using RMuseum.Models.ImportJob;
|
||||
using RMuseum.Models.PDFLibrary;
|
||||
using RSecurityBackend.Models.Generic;
|
||||
using RSecurityBackend.Models.Image;
|
||||
using RSecurityBackend.Services.Implementation;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
namespace RMuseum.Services.Implementation
|
||||
{
|
||||
public partial class PDFLibraryService
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -132,131 +132,7 @@ namespace RMuseum.Services.Implementation
|
||||
{
|
||||
using (RMuseumDbContext context = new RMuseumDbContext(new DbContextOptions<RMuseumDbContext>()))
|
||||
{
|
||||
var pdfRes = await ImportLocalPDFFileAsync(context, model.BookId, model.MultiVolumePDFCollectionId, model.VolumeOrder, model.LocalImportingPDFFilePath, model.OriginalSourceUrl, model.SkipUpload, fileChecksum);
|
||||
if (pdfRes.Result != null)
|
||||
{
|
||||
var pdfBook = pdfRes.Result;
|
||||
pdfBook.Title = model.Title;
|
||||
pdfBook.SubTitle = model.SubTitle;
|
||||
pdfBook.AuthorsLine = model.AuthorsLine;
|
||||
pdfBook.ISBN = model.ISBN;
|
||||
pdfBook.Description = model.Description;
|
||||
pdfBook.IsTranslation = model.IsTranslation;
|
||||
pdfBook.TranslatorsLine = model.TranslatorsLine;
|
||||
pdfBook.TitleInOriginalLanguage = model.TitleInOriginalLanguage;
|
||||
pdfBook.PublisherLine = model.PublisherLine;
|
||||
pdfBook.PublishingDate = model.PublishingDate;
|
||||
pdfBook.PublishingLocation = model.PublishingLocation;
|
||||
pdfBook.PublishingNumber = model.PublishingNumber == 0 ? null : model.PublishingNumber;
|
||||
pdfBook.ClaimedPageCount = model.ClaimedPageCount == 0 ? null : model.ClaimedPageCount;
|
||||
pdfBook.OriginalSourceName = model.OriginalSourceName;
|
||||
pdfBook.OriginalFileUrl = model.OriginalFileUrl;
|
||||
pdfBook.PDFSourceId = model.PDFSourceId;
|
||||
pdfBook.BookScriptType = model.BookScriptType;
|
||||
List<AuthorRole> roles = new List<AuthorRole>();
|
||||
if (model.WriterId != null)
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.WriterId).SingleAsync(),
|
||||
Role = "نویسنده",
|
||||
});
|
||||
}
|
||||
if (model.Writer2Id != null)
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.Writer2Id).SingleAsync(),
|
||||
Role = "نویسنده",
|
||||
});
|
||||
}
|
||||
if (model.Writer3Id != null)
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.Writer3Id).SingleAsync(),
|
||||
Role = "نویسنده",
|
||||
});
|
||||
}
|
||||
if (model.Writer4Id != null)
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.Writer4Id).SingleAsync(),
|
||||
Role = "نویسنده",
|
||||
});
|
||||
}
|
||||
if (model.TranslatorId != null)
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.TranslatorId).SingleAsync(),
|
||||
Role = "مترجم",
|
||||
});
|
||||
}
|
||||
if (model.Translator2Id != null)
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.Translator2Id).SingleAsync(),
|
||||
Role = "مترجم",
|
||||
});
|
||||
}
|
||||
if (model.Translator3Id != null)
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.Translator3Id).SingleAsync(),
|
||||
Role = "مترجم",
|
||||
});
|
||||
}
|
||||
if (model.Translator4Id != null)
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.Translator4Id).SingleAsync(),
|
||||
Role = "مترجم",
|
||||
});
|
||||
}
|
||||
if (model.CollectorId != null)
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.CollectorId).SingleAsync(),
|
||||
Role = "مصحح",
|
||||
});
|
||||
}
|
||||
if (model.Collector2Id != null)
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.Collector2Id).SingleAsync(),
|
||||
Role = "مصحح",
|
||||
});
|
||||
}
|
||||
if(model.OtherContributerId != null && !string.IsNullOrEmpty(model.OtherContributerRole))
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.OtherContributerId).SingleAsync(),
|
||||
Role = model.OtherContributerRole,
|
||||
});
|
||||
}
|
||||
if (model.OtherContributer2Id != null && !string.IsNullOrEmpty(model.OtherContributer2Role))
|
||||
{
|
||||
roles.Add(new AuthorRole()
|
||||
{
|
||||
Author = await context.Authors.Where(a => a.Id == model.OtherContributer2Id).SingleAsync(),
|
||||
Role = model.OtherContributer2Role,
|
||||
});
|
||||
}
|
||||
if (roles.Count > 0)
|
||||
{
|
||||
pdfBook.Contributers = roles;
|
||||
}
|
||||
context.Update(pdfBook);
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
await ImportLocalPDFFileAsync(context, model, fileChecksum);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user