Service update, import changes from web_portal

This commit is contained in:
Claudio Boggian
2023-06-21 10:38:57 +02:00
parent 39fa4dedf3
commit bb99cef33c
101 changed files with 4266 additions and 3044 deletions
@@ -0,0 +1,61 @@
using library_spo_utils.Enums;
using library_spo_utils.Interfaces.Services;
using Microsoft.Extensions.Logging;
namespace library_spo_utils.Services;
internal class PurchasingRequestBuildService : IPurchasingRequestBuildService
{
private readonly ISiteOptions _siteOptions;
private readonly ISharePointAuthenticationManager _sharePointAuthenticationManager;
private readonly ISharePointCustomOperation _spc;
private readonly IPurchasingRequestDocLibraryService _purchasingRequestDocLibraryService;
private readonly IPurchasingRequestDocSetService _purchasingRequestDocSetService;
private readonly IFieldEntryDataUpdate _fieldEntryDataUpdate;
private readonly ILogger<PurchasingRequestBuildService> _logger;
public PurchasingRequestBuildService(ISiteOptions siteOptions,
ISharePointAuthenticationManager sharePointAuthenticationManager,
ISharePointCustomOperation spc,
IPurchasingRequestDocLibraryService purchasingRequestDocLibraryService,
IPurchasingRequestDocSetService purchasingRequestDocSetService,
IFieldEntryDataUpdate fieldEntryDataUpdate,
ILogger<PurchasingRequestBuildService> logger)
{
_siteOptions = siteOptions;
_sharePointAuthenticationManager = sharePointAuthenticationManager;
_spc = spc;
_purchasingRequestDocLibraryService = purchasingRequestDocLibraryService;
_purchasingRequestDocSetService = purchasingRequestDocSetService;
_fieldEntryDataUpdate = fieldEntryDataUpdate;
_logger = logger;
}
public void CreateIfNotExists(string purchasingRequestName)
{
var site = _siteOptions.GetPurchasingRequestSite();
var ctx = _sharePointAuthenticationManager.GetContext(site);
var list = _siteOptions.GetPurchasingRequestLibrary(purchasingRequestName);
var tenant = _siteOptions.GetPurchasingRequestTenat();
if (!_spc.SiteExist(ctx))
{
throw new Exception($"Impossibile to build site it don't exist");
}
if (!_spc.ListExist(ctx, list))
{
_purchasingRequestDocLibraryService.Create(list, ctx);
}
if (!_spc.FolderExistsInsideList(ctx, list, purchasingRequestName))
{
_purchasingRequestDocSetService.Create(purchasingRequestName, list, tenant, ctx);
}
else
{
_logger.LogInformation($"Quotation with {purchasingRequestName} already exist");
_fieldEntryDataUpdate.FieldUpdate(ctx, list, purchasingRequestName, FieldUpdateType.PurchasingRequest);
}
}
}