update directory name and access visibility
This commit is contained in:
@@ -0,0 +1,169 @@
|
||||
using console_spo_utils.Constants;
|
||||
using console_spo_utils.Interfaces.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.SharePoint.Client;
|
||||
|
||||
namespace console_spo_utils.Services;
|
||||
|
||||
internal class ProjectYearService : IProjectYearService
|
||||
{
|
||||
private readonly ILogger<ProjectYearService> logger;
|
||||
private readonly IProjectService projectService;
|
||||
|
||||
public ProjectYearService(
|
||||
ILogger<ProjectYearService> logger,
|
||||
IProjectService projectService)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.projectService = projectService;
|
||||
}
|
||||
|
||||
public void CreateList(string listTitle, ClientContext ctx)
|
||||
{
|
||||
try
|
||||
{
|
||||
#region New List
|
||||
|
||||
Console.WriteLine($"> Inizializzata la fase di creazione della lista '{listTitle}'.");
|
||||
|
||||
Web web = ctx.Web;
|
||||
ListCreationInformation creationInfo = new ListCreationInformation();
|
||||
|
||||
creationInfo.Title = listTitle;
|
||||
creationInfo.TemplateType = (int)ListTemplateType.GenericList;
|
||||
List oList = web.Lists.Add(creationInfo);
|
||||
|
||||
ctx.ExecuteQuery();
|
||||
|
||||
ctx.Load(oList, l => l.Fields);
|
||||
|
||||
var fld = oList.Fields.GetByInternalNameOrTitle("Title");
|
||||
if (fld != null)
|
||||
{
|
||||
fld.Required = false;
|
||||
fld.SetShowInDisplayForm(false);
|
||||
fld.SetShowInEditForm(false);
|
||||
fld.SetShowInNewForm(false);
|
||||
|
||||
oList.Update();
|
||||
ctx.ExecuteQuery();
|
||||
}
|
||||
|
||||
Console.WriteLine($"> La lista '{listTitle}' è stato creato con successo.");
|
||||
|
||||
#endregion
|
||||
|
||||
#region Field
|
||||
|
||||
Console.WriteLine($"> Inizializzata la fase di importazione dei campi '{listTitle}'.");
|
||||
|
||||
List list = ctx.Web.Lists.GetByTitle(listTitle);
|
||||
var siteField = ctx.Site.RootWeb;
|
||||
ctx.Load(list, l => l.Fields);
|
||||
ctx.Load(siteField, s => s.Fields);
|
||||
|
||||
ctx.ExecuteQuery();
|
||||
|
||||
foreach (var fn in Fields.SiteFields)
|
||||
{
|
||||
var Fields = siteField.Fields.GetByTitle(fn);
|
||||
list.Fields.Add(Fields);
|
||||
}
|
||||
|
||||
ctx.ExecuteQuery();
|
||||
|
||||
Console.WriteLine($"> Completata la fase di importazione dei campi '{listTitle}'.");
|
||||
|
||||
#endregion
|
||||
|
||||
#region View
|
||||
|
||||
Console.WriteLine($"> Inizializzata la fase di creazione della ListView '{listTitle}'.");
|
||||
|
||||
var views = list.Views;
|
||||
|
||||
ViewCreationInformation viewCreation = new ViewCreationInformation();
|
||||
|
||||
viewCreation.Title = listTitle;
|
||||
viewCreation.ViewTypeKind = ViewType.Html;
|
||||
viewCreation.ColumnWidth = "350";
|
||||
viewCreation.ViewFields = Fields.SiteFields;
|
||||
viewCreation.SetAsDefaultView = true;
|
||||
|
||||
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}'.");
|
||||
|
||||
|
||||
ctx.Web.RootFolder.WelcomePage = $"Lists/{listTitle}/{listTitle}.aspx";
|
||||
|
||||
ctx.Web.RootFolder.Update();
|
||||
ctx.ExecuteQuery();
|
||||
|
||||
CreateViewList(list, ctx);
|
||||
|
||||
projectService.BuildWebParts();
|
||||
|
||||
|
||||
Console.WriteLine($"> Impostata come HomePage di '{viewCreation.Title}'");
|
||||
#endregion
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Project Years");
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateViewList(List list, ClientContext ctx)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (KeyValuePair<string, string> listTitle in Fields.SyntheticProjList)
|
||||
{
|
||||
Console.WriteLine($"> Inizializzata la fase di creazione della ListView '{listTitle}'.");
|
||||
|
||||
var views = list.Views;
|
||||
|
||||
ViewCreationInformation viewCreation = new ViewCreationInformation();
|
||||
|
||||
viewCreation.Title = listTitle.Key;
|
||||
viewCreation.ViewTypeKind = ViewType.Html;
|
||||
viewCreation.ColumnWidth = "350";
|
||||
viewCreation.ViewFields = Fields.SiteFields;
|
||||
viewCreation.Query = $"<Where>{listTitle.Value}</Where>";
|
||||
|
||||
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.Update();
|
||||
ctx.ExecuteQuery();
|
||||
|
||||
Console.WriteLine($"> Abilitata la visualizzazione su mobile '{viewCreation.Title}'.");
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Project Years");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user