update directory name and access visibility
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
using console_spo_utils.Constants;
|
||||
using console_spo_utils.Interfaces.Repositories;
|
||||
using console_spo_utils.Interfaces.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.SharePoint.Client;
|
||||
using Microsoft.SharePoint.Client.DocumentSet;
|
||||
|
||||
namespace console_spo_utils.Services;
|
||||
|
||||
internal class QuotationDocSetService : IQuotationDocSetService
|
||||
{
|
||||
private readonly ISharePointCustomOperation cpt;
|
||||
private readonly ILogger<QuotationDocSetService> logger;
|
||||
private readonly IOneNoteService oneNoteService;
|
||||
private readonly IQuotationRepository quotationRepository;
|
||||
|
||||
public QuotationDocSetService(ISharePointCustomOperation cpt,
|
||||
ILogger<QuotationDocSetService> logger,
|
||||
IOneNoteService oneNoteService,
|
||||
IQuotationRepository quotationRepository)
|
||||
{
|
||||
this.cpt = cpt;
|
||||
this.logger = logger;
|
||||
this.oneNoteService = oneNoteService;
|
||||
this.quotationRepository = quotationRepository;
|
||||
}
|
||||
|
||||
public void Create(string quotationName, string docLibraryName, string tenantName, ClientContext ctx)
|
||||
{
|
||||
try
|
||||
{
|
||||
#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 {quotationName}.");
|
||||
|
||||
#region DocSet Field Entry
|
||||
|
||||
DocumentSet.Create(ctx, list.RootFolder, quotationName, contentType.Id);
|
||||
ctx.ExecuteQuery();
|
||||
|
||||
Console.WriteLine($"> DocumentSet {quotationName} creata.");
|
||||
|
||||
var dsItem = list.RootFolder.Folders.GetByUrl(quotationName).ListItemAllFields;
|
||||
|
||||
dsItem["PAL_ID_Quotation"] = quotationRepository.DefaultIdQuotation(quotationName);
|
||||
dsItem["PAL_Quotation_Name"] = quotationRepository.DefaultQuotationName(quotationName);
|
||||
dsItem["PAL_Quotation_Reason"] = quotationRepository.DefaultQuotationReason(quotationName);
|
||||
dsItem["PAL_Authors"] = quotationRepository.DefaultAuthors(quotationName);
|
||||
|
||||
dsItem.Update();
|
||||
ctx.ExecuteQuery();
|
||||
|
||||
Console.WriteLine($"> Field value update.");
|
||||
|
||||
#endregion
|
||||
|
||||
#region Quotation Folder
|
||||
|
||||
foreach (var name in Folders.OfferDocSet)
|
||||
{
|
||||
Console.WriteLine($"La sotto cartella {name} verrà creata in {quotationName}");
|
||||
var rPath = ResourcePath.FromDecodedUrl($"{quotationName}/{name}");
|
||||
list.RootFolder.AddSubFolderUsingPath(rPath);
|
||||
}
|
||||
|
||||
ctx.ExecuteQuery();
|
||||
|
||||
oneNoteService.CreateFolderInsideQuotation(quotationName, ctx);
|
||||
|
||||
Console.WriteLine($"Le sotto cartelle sono state create con successo in {quotationName}");
|
||||
|
||||
#endregion
|
||||
|
||||
Console.WriteLine($"> {quotationName} creato con successo in Offerte/{docLibraryName}.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user