Service update, import changes from web_portal
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using System.Runtime.CompilerServices;
|
||||
using library_spo_utils.Enums;
|
||||
using library_spo_utils.Interfaces.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace library_spo_utils.Services;
|
||||
|
||||
internal class PurchasingOrderBuildService : IPurchasingOrderBuildService
|
||||
{
|
||||
private readonly ISiteOptions _siteOptions;
|
||||
private readonly ISharePointAuthenticationManager _sharePointAuthenticationManager;
|
||||
private readonly ISharePointCustomOperation _spc;
|
||||
private readonly IPurchasingOrderDocLibraryService _purchasingOrderDocLibraryService;
|
||||
private readonly IPurchasingOrderDocSetService _purchasingOrderDocSetService;
|
||||
private readonly IFieldEntryDataUpdate _fieldEntryDataUpdate;
|
||||
private readonly ILogger<PurchasingOrderBuildService> _logger;
|
||||
|
||||
public PurchasingOrderBuildService(ISiteOptions siteOptions,
|
||||
ISharePointAuthenticationManager sharePointAuthenticationManager,
|
||||
ISharePointCustomOperation spc,
|
||||
IPurchasingOrderDocLibraryService purchasingOrderDocLibraryService,
|
||||
IPurchasingOrderDocSetService purchasingOrderDocSetService,
|
||||
IFieldEntryDataUpdate fieldEntryDataUpdate,
|
||||
ILogger<PurchasingOrderBuildService> logger)
|
||||
{
|
||||
_siteOptions = siteOptions;
|
||||
_sharePointAuthenticationManager = sharePointAuthenticationManager;
|
||||
_spc = spc;
|
||||
_purchasingOrderDocLibraryService = purchasingOrderDocLibraryService;
|
||||
_purchasingOrderDocSetService = purchasingOrderDocSetService;
|
||||
_fieldEntryDataUpdate = fieldEntryDataUpdate;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateIfNotExists(string purchasingOrder)
|
||||
{
|
||||
var site = _siteOptions.GetPurchasingOrderSite();
|
||||
var ctx = _sharePointAuthenticationManager.GetContext(site);
|
||||
var list = _siteOptions.GetPurchasingOrderLibrary(purchasingOrder);
|
||||
var tenant = _siteOptions.GetPurchasingOrderTenat();
|
||||
|
||||
if (!_spc.SiteExist(ctx))
|
||||
{
|
||||
throw new Exception($"Impossibile to build site it don't exist");
|
||||
}
|
||||
|
||||
if (!_spc.ListExist(ctx, list))
|
||||
{
|
||||
_purchasingOrderDocLibraryService.Create(list, ctx);
|
||||
}
|
||||
|
||||
if (!_spc.FolderExistsInsideList(ctx, list, purchasingOrder))
|
||||
{
|
||||
_purchasingOrderDocSetService.Create(purchasingOrder, list, tenant, ctx);
|
||||
}
|
||||
else
|
||||
{
|
||||
_fieldEntryDataUpdate.FieldUpdate(ctx, list, purchasingOrder, FieldUpdateType.PurchasingOrder);
|
||||
_logger.LogInformation($"Quotation with {purchasingOrder} already exist");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user