924cdd3d4b
Defined structure of project
122 lines
3.6 KiB
C#
122 lines
3.6 KiB
C#
using console_spo_utils.Interfaces.Services;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.SharePoint.Client;
|
|
|
|
namespace console_spo_utils.Services;
|
|
|
|
public class ProjectYearService:IProjectYearService
|
|
{
|
|
private readonly ILogger<ProjectYearService> logger;
|
|
|
|
public ProjectYearService(
|
|
ILogger<ProjectYearService> logger)
|
|
{
|
|
this.logger = logger;
|
|
}
|
|
|
|
public void ProjectsYList(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();
|
|
|
|
string[] fieldName = { "ID Progetto", "Cliente", "Causale" };
|
|
|
|
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 '{listTitle}'.");
|
|
|
|
#endregion
|
|
|
|
#region View
|
|
|
|
Console.WriteLine($"> Inizializzata la fase di creazione della ListView '{listTitle}'.");
|
|
|
|
var views = list.Views;
|
|
|
|
|
|
ViewCreationInformation viewCreation = new ViewCreationInformation();
|
|
|
|
viewCreation.SetAsDefaultView = true;
|
|
viewCreation.Title = listTitle;
|
|
viewCreation.ViewTypeKind = ViewType.None;
|
|
viewCreation.ColumnWidth = "350";
|
|
viewCreation.ViewFields = new string[] { "ID Progetto", "Cliente", "Causale" };
|
|
|
|
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();
|
|
|
|
Console.WriteLine($"> Impostata come HomePage di '{viewCreation.Title}'");
|
|
|
|
#endregion
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.LogError(ex,"Project Years");
|
|
}
|
|
}
|
|
} |