Files
2023-06-21 10:38:57 +02:00

65 lines
2.6 KiB
C#

using library_spo_utils.Enums;
using library_spo_utils.Interfaces.Services;
using Microsoft.Extensions.Logging;
namespace library_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 IFieldEntryDataUpdate _fieldEntryDataUpdate;
private readonly ILogger<NonComplianceBuildService> logger;
public NonComplianceBuildService(
ISiteOptions siteOptions,
ISharePointAuthenticationManager sharePointAuthenticationManager,
ISharePointCustomOperation spc,
ITenantService tenantService,
INonComplianceDocLibraryService nonComplianceDocLibraryService,
INonComplianceDocSetService nonComplianceDocSetService,
IFieldEntryDataUpdate fieldEntryDataUpdate,
ILogger<NonComplianceBuildService> logger)
{
this.siteOptions = siteOptions;
this.sharePointAuthenticationManager = sharePointAuthenticationManager;
this.spc = spc;
this.tenantService = tenantService;
this.nonComplianceDocLibraryService = nonComplianceDocLibraryService;
this.nonComplianceDocSetService = nonComplianceDocSetService;
_fieldEntryDataUpdate = fieldEntryDataUpdate;
this.logger = logger;
}
public void CreateIfNotExists(string nonComplianceName)
{
var site = siteOptions.GetNonComplianceSite();
var ctx = sharePointAuthenticationManager.GetContext(site);
var list = siteOptions.GetNonComplianceLibrary(nonComplianceName);
var tenant = siteOptions.GetNonComplianceTenant();
if (!spc.SiteExist(ctx))
{
tenantService.CreateForNonCompliance();
}
if (!spc.ListExist(ctx, list))
{
nonComplianceDocLibraryService.Create(list, ctx);
}
if (!spc.FolderExistsInsideList(ctx, list, nonComplianceName))
{
nonComplianceDocSetService.Create(nonComplianceName, list, tenant, ctx);
}
else
{
logger.LogInformation($"Quotation with {nonComplianceName} already exist");
_fieldEntryDataUpdate.FieldUpdate(ctx, list, nonComplianceName, FieldUpdateType.NonCompliance);
}
}
}