Service update, import changes from web_portal
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
using library_spo_utils.Constants;
|
||||
using library_spo_utils.Enums;
|
||||
using library_spo_utils.Interfaces.Repositories;
|
||||
using library_spo_utils.Interfaces.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.SharePoint.Client;
|
||||
using Microsoft.SharePoint.Client.DocumentSet;
|
||||
|
||||
namespace library_spo_utils.Services;
|
||||
|
||||
internal class PurchasingOrderDocSetService : IPurchasingOrderDocSetService
|
||||
{
|
||||
private readonly IPurchasingOrderRepository _purchasingOrderRepository;
|
||||
private readonly ISharePointCustomOperation _cpt;
|
||||
private readonly IOneNoteService _oneNoteService;
|
||||
private readonly ISiteOptions _siteOptions;
|
||||
private readonly IFieldEntryDataUpdate _fieldEntryDataUpdate;
|
||||
private readonly ISharePointAuthenticationManager _sharePointAuthenticationManager;
|
||||
private readonly ILogger<PurchasingOrderBuildService> _logger;
|
||||
|
||||
public PurchasingOrderDocSetService(
|
||||
IPurchasingOrderRepository purchasingOrderRepository,
|
||||
ISharePointCustomOperation cpt,
|
||||
IOneNoteService oneNoteService,
|
||||
ISiteOptions siteOptions,
|
||||
IFieldEntryDataUpdate fieldEntryDataUpdate,
|
||||
ISharePointAuthenticationManager sharePointAuthenticationManager,
|
||||
ILogger<PurchasingOrderBuildService> logger)
|
||||
{
|
||||
_purchasingOrderRepository = purchasingOrderRepository;
|
||||
_cpt = cpt;
|
||||
_oneNoteService = oneNoteService;
|
||||
_siteOptions = siteOptions;
|
||||
_fieldEntryDataUpdate = fieldEntryDataUpdate;
|
||||
_sharePointAuthenticationManager = sharePointAuthenticationManager;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void Create(string purchasingOrderName, string docLibraryName, string tenantName, ClientContext ctx)
|
||||
{
|
||||
#region Context
|
||||
|
||||
var web = ctx.Web;
|
||||
ctx.Load(web, w => w.Url);
|
||||
List list = web.Lists.GetByTitle(docLibraryName);
|
||||
ctx.Load(list, l => l.RootFolder, l => l.ContentTypes, l => l.Fields, l => l.ContentTypesEnabled);
|
||||
ctx.ExecuteQuery();
|
||||
list.ContentTypesEnabled = true;
|
||||
list.Update();
|
||||
|
||||
if (!_cpt.ListContentTypeExist(ctx, docLibraryName, "Set di documenti"))
|
||||
{
|
||||
var documentCT = ctx.Site.RootWeb.AvailableContentTypes.GetById("0x0120D5");
|
||||
ctx.Load(documentCT);
|
||||
ctx.ExecuteQuery();
|
||||
|
||||
var ctDocSet = new ContentTypeCreationInformation()
|
||||
{
|
||||
Name = "Set di documenti",
|
||||
ParentContentType = documentCT
|
||||
};
|
||||
list.ContentTypes.Add(ctDocSet);
|
||||
|
||||
list.Update();
|
||||
ctx.ExecuteQuery();
|
||||
}
|
||||
|
||||
var ctData = list.ContentTypes.Where(c => c.Name == "Set di documenti");
|
||||
var contentType = ctData.FirstOrDefault();
|
||||
ctx.Load(contentType);
|
||||
ctx.ExecuteQuery();
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
Console.WriteLine($"> Inizializzata la fase di creazione per {purchasingOrderName}.");
|
||||
|
||||
#region DocSet Field Entry
|
||||
|
||||
DocumentSet.Create(ctx, list.RootFolder, purchasingOrderName, contentType.Id);
|
||||
ctx.ExecuteQuery();
|
||||
|
||||
Console.WriteLine($"> DocumentSet {purchasingOrderName} creata.");
|
||||
|
||||
_fieldEntryDataUpdate.FieldUpdate(ctx, docLibraryName, purchasingOrderName, FieldUpdateType.PurchasingOrder);
|
||||
|
||||
Console.WriteLine($"> Field value update.");
|
||||
|
||||
#endregion
|
||||
|
||||
#region Folder
|
||||
|
||||
foreach (var name in Folders.PurchasingOrder)
|
||||
{
|
||||
Console.WriteLine($"La sotto cartella {name} verrà creata in {purchasingOrderName}");
|
||||
var rPath = ResourcePath.FromDecodedUrl($"{purchasingOrderName}/{name}");
|
||||
list.RootFolder.AddSubFolderUsingPath(rPath);
|
||||
}
|
||||
|
||||
ctx.ExecuteQuery();
|
||||
|
||||
var purchCtx = _sharePointAuthenticationManager.GetContext(_siteOptions.GetPurchasingSite());
|
||||
|
||||
_oneNoteService.CreateFolderInsidePurchasing(purchasingOrderName, purchCtx, PurchType.Order);
|
||||
|
||||
Console.WriteLine($"Le sotto cartelle sono state create con successo in {purchasingOrderName}");
|
||||
|
||||
#endregion
|
||||
|
||||
Console.WriteLine($"> {purchasingOrderName} creato con successo.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user