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

58 lines
2.2 KiB
C#

using console_spo_utils.Interfaces.Services;
using Microsoft.Extensions.Logging;
namespace console_spo_utils.Services;
internal class NonComplianceBuildService : INonComplianceBuildService
{
private readonly ISiteOptions siteOptions;
private readonly ISharePointAuthenticationManager sharePointAuthenticationManager;
private readonly ISharePointCustomOperation spc;
private readonly ITenantService tenantService;
private readonly INonComplianceDocLibraryService nonComplianceDocLibraryService;
private readonly INonComplianceDocSetService nonComplianceDocSetService;
private readonly ILogger<NonComplianceBuildService> logger;
public NonComplianceBuildService(
ISiteOptions siteOptions,
ISharePointAuthenticationManager sharePointAuthenticationManager,
ISharePointCustomOperation spc,
ITenantService tenantService,
INonComplianceDocLibraryService nonComplianceDocLibraryService,
INonComplianceDocSetService nonComplianceDocSetService,
ILogger<NonComplianceBuildService> logger)
{
this.siteOptions = siteOptions;
this.sharePointAuthenticationManager = sharePointAuthenticationManager;
this.spc = spc;
this.tenantService = tenantService;
this.nonComplianceDocLibraryService = nonComplianceDocLibraryService;
this.nonComplianceDocSetService = nonComplianceDocSetService;
this.logger = logger;
}
public void CreateIfNotExists(string nonComplianceName)
{
var site = siteOptions.GetNonComplianceSite();
var ctx = sharePointAuthenticationManager.GetContext(site);
var list = siteOptions.GetNonComplianceLibrary();
var tenant = siteOptions.GetNonComplianceTenant();
if (!spc.SiteExist(ctx))
{
tenantService.CreateForNonCompliance();
}
else if (!spc.ListExist(ctx, list))
{
nonComplianceDocLibraryService.Create(list, ctx);
}
else if (!spc.FolderExistsInsideList(ctx, list, nonComplianceName))
{
nonComplianceDocSetService.Create(nonComplianceName, list, tenant, ctx);
}
else
{
logger.LogInformation($"Quotation with {nonComplianceName} already exist");
}
}
}