update directory name and access visibility
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
using console_spo_utils.Constants;
|
||||
using console_spo_utils.Interfaces.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.SharePoint.Client;
|
||||
using Microsoft.SharePoint.Navigation;
|
||||
|
||||
namespace console_spo_utils.Services;
|
||||
|
||||
internal class ProjectQuickMenuService : IProjectQuickMenuService
|
||||
{
|
||||
private readonly ILogger<ProjectQuickMenuService> logger;
|
||||
private readonly ISiteOptions siteOptions;
|
||||
|
||||
public ProjectQuickMenuService(ILogger<ProjectQuickMenuService> logger
|
||||
, ISiteOptions siteOptions)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.siteOptions = siteOptions;
|
||||
}
|
||||
|
||||
|
||||
public void CreateForProject(string projName, ClientContext ctx)
|
||||
{
|
||||
try
|
||||
{
|
||||
ClearQuickMenu(ctx);
|
||||
|
||||
var subSiteUrl = siteOptions.GetSubProjSite(projName).ToString();
|
||||
var itemQuickMenu = Folders.GetProjectQuickMenu(projName, subSiteUrl);
|
||||
|
||||
var spNavNodeColl = ctx.Web.Navigation.QuickLaunch;
|
||||
var newNavNode = new NavigationNodeCreationInformation();
|
||||
|
||||
ctx.Load(ctx.Web, w => w.RootFolder.WelcomePage);
|
||||
|
||||
foreach (var (name, path) in itemQuickMenu)
|
||||
{
|
||||
|
||||
newNavNode.Title = name;
|
||||
newNavNode.Url = path;
|
||||
newNavNode.AsLastNode = true;
|
||||
spNavNodeColl.Add(newNavNode);
|
||||
|
||||
ctx.ExecuteQuery();
|
||||
|
||||
logger.LogInformation($"> Il menu rapido è stato aggiornato in {projName}");
|
||||
|
||||
if (name != $"SottoCommesse {projName}")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ctx.Web.RootFolder.WelcomePage = $"SottoCommesse%20{projName}/Forms/SottoCommesse%20{projName}.aspx";
|
||||
|
||||
ctx.Web.RootFolder.Update();
|
||||
ctx.ExecuteQuery();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "CreateForProject");
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearQuickMenu(ClientContext ctx)
|
||||
{
|
||||
try
|
||||
{
|
||||
NavigationNodeCollection navBar = ctx.Web.Navigation.QuickLaunch;
|
||||
ctx.Load(navBar);
|
||||
ctx.ExecuteQueryRetry();
|
||||
|
||||
int[] element = new[] { 1, 1, 1 };
|
||||
|
||||
foreach (var e in element)
|
||||
{
|
||||
navBar[e].DeleteObject();
|
||||
ctx.ExecuteQuery();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "ClearQuickMenu");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user