115 lines
3.6 KiB
C#
115 lines
3.6 KiB
C#
using library_spo_utils.Constants;
|
|
using library_spo_utils.Interfaces.Services;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.SharePoint.Client;
|
|
|
|
namespace library_spo_utils.Services;
|
|
|
|
internal class PurchasingPackingSlipDocLibraryService : IPurchasingPackingSlipDocLibraryService
|
|
{
|
|
private readonly ILogger<PurchasingPackingSlipDocLibraryService> _logger;
|
|
|
|
public PurchasingPackingSlipDocLibraryService(ILogger<PurchasingPackingSlipDocLibraryService> logger)
|
|
{
|
|
_logger = logger;
|
|
}
|
|
public void Create(string libName, ClientContext ctx)
|
|
{
|
|
try
|
|
{
|
|
#region New DocLib
|
|
|
|
Console.WriteLine($"> Inizializzata la fase di creazione '{libName}'.");
|
|
|
|
Web web = ctx.Web;
|
|
ctx.Load(web, w => w.RootFolder.WelcomePage, w => w.Url);
|
|
|
|
ListCreationInformation lci = new ListCreationInformation();
|
|
lci.Title = libName;
|
|
lci.TemplateType = (int)ListTemplateType.DocumentLibrary;
|
|
web.Lists.Add(lci);
|
|
|
|
ctx.ExecuteQuery();
|
|
Console.WriteLine($"> Completata la fase di creazione '{libName}'.");
|
|
|
|
#endregion
|
|
|
|
#region Field
|
|
|
|
Console.WriteLine($"> Inizializzata la fase di importazione dei campi '{libName}'.");
|
|
|
|
List list = ctx.Web.Lists.GetByTitle(libName);
|
|
var siteField = ctx.Site.RootWeb;
|
|
ctx.Load(list, l => l.Fields);
|
|
ctx.Load(siteField, s => s.Fields);
|
|
|
|
ctx.ExecuteQuery();
|
|
|
|
string[] fieldName = { "Fornitore", "Stato" };
|
|
|
|
foreach (var fn in fieldName)
|
|
{
|
|
var Fields = siteField.Fields.GetByTitle(fn);
|
|
list.Fields.Add(Fields);
|
|
}
|
|
|
|
ctx.ExecuteQuery();
|
|
|
|
Console.WriteLine($"> Completata la fase di importazione dei campi '{libName}'.");
|
|
|
|
#endregion
|
|
|
|
#region View
|
|
|
|
Console.WriteLine($"> Inizializzata la fase di creazione della ListView '{libName}'.");
|
|
|
|
var views = list.Views;
|
|
|
|
ViewCreationInformation viewCreation = new ViewCreationInformation();
|
|
|
|
viewCreation.SetAsDefaultView = true;
|
|
viewCreation.Title = libName;
|
|
viewCreation.ViewTypeKind = ViewType.None;
|
|
viewCreation.ColumnWidth = "350";
|
|
viewCreation.ViewFields = Fields.PurchasingView;
|
|
|
|
var view = views.Add(viewCreation);
|
|
|
|
ctx.Load(view);
|
|
ctx.ExecuteQuery();
|
|
|
|
Console.WriteLine($"> Completata la fase di creazione della ListView '{viewCreation.Title}'.");
|
|
|
|
var customView = views.GetByTitle(viewCreation.Title);
|
|
customView.MobileView = true;
|
|
customView.MobileDefaultView = true;
|
|
|
|
customView.Update();
|
|
ctx.ExecuteQuery();
|
|
|
|
Console.WriteLine($"> Abilitata la visualizzazione su mobile '{viewCreation.Title}'.");
|
|
|
|
#endregion
|
|
|
|
#region Shortcut on Quickmenu
|
|
|
|
NavigationNodeCollection spNavNodeColl = web.Navigation.QuickLaunch;
|
|
NavigationNodeCreationInformation newNavNode = new NavigationNodeCreationInformation();
|
|
|
|
newNavNode.Title = $"{libName}";
|
|
newNavNode.Url = $"{web.Url}/{libName.Replace(" ", "%20")}";
|
|
newNavNode.AsLastNode = true;
|
|
spNavNodeColl.Add(newNavNode);
|
|
|
|
ctx.ExecuteQuery();
|
|
|
|
Console.WriteLine($"> Il menu rapido è stato aggiornato, il collegamento a {libName} è ora disponibile.");
|
|
|
|
#endregion
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "NonComplianceDocLibraryService");
|
|
}
|
|
}
|
|
} |