Files
console_spo_utils/library_spo_utils/Services/QuotationBuildService.cs
T
2022-09-29 08:33:32 +02:00

58 lines
2.1 KiB
C#

using console_spo_utils.Interfaces.Services;
using Microsoft.Extensions.Logging;
namespace console_spo_utils.Services;
internal class QuotationBuildService : IQuotationBuildService
{
private readonly ISiteOptions siteOptions;
private readonly ISharePointAuthenticationManager sharePointAuthenticationManager;
private readonly ISharePointCustomOperation spc;
private readonly ITenantService tenantService;
private readonly IQuotationDocLibraryService quotationDocLibraryService;
private readonly IQuotationDocSetService quotationDocSetService;
private readonly ILogger<QuotationBuildService> logger;
public QuotationBuildService(
ISiteOptions siteOptions,
ISharePointAuthenticationManager sharePointAuthenticationManager,
ISharePointCustomOperation spc,
ITenantService tenantService,
IQuotationDocLibraryService quotationDocLibraryService,
IQuotationDocSetService quotationDocSetService,
ILogger<QuotationBuildService> logger)
{
this.siteOptions = siteOptions;
this.sharePointAuthenticationManager = sharePointAuthenticationManager;
this.spc = spc;
this.tenantService = tenantService;
this.quotationDocLibraryService = quotationDocLibraryService;
this.quotationDocSetService = quotationDocSetService;
this.logger = logger;
}
public void CreateIfNotExists(string quotationName)
{
var site = siteOptions.GetQuotationSite();
var ctx = sharePointAuthenticationManager.GetContext(site);
var list = siteOptions.GetQuotationLibrary();
var tenant = siteOptions.GetQuotationTenant();
if (!spc.SiteExist(ctx))
{
tenantService.CreateForQuotation();
}
else if (!spc.ListExist(ctx, list))
{
quotationDocLibraryService.Create(list, ctx);
}
else if (!spc.FolderExistsInsideList(ctx, list, quotationName))
{
quotationDocSetService.Create(quotationName, list, tenant, ctx);
}
else
{
logger.LogInformation($"Quotation with {quotationName} already exist");
}
}
}