169 lines
4.3 KiB
C#
169 lines
4.3 KiB
C#
using System.Net;
|
|
using System.Security;
|
|
using System.Text.RegularExpressions;
|
|
using library_spo_utils.Interfaces.Services;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Graph;
|
|
|
|
namespace library_spo_utils.Services;
|
|
|
|
public class SiteOptions : ISiteOptions
|
|
{
|
|
private readonly IConfiguration _configuration;
|
|
|
|
public SiteOptions(IConfiguration configuration)
|
|
{
|
|
_configuration = configuration;
|
|
}
|
|
|
|
private const string SiteCollection = "https://italsortbuttrio.sharepoint.com";
|
|
public string TokenEndpoint { get; } = "https://login.microsoftonline.com/common/oauth2/token";
|
|
public string DefaultAadAppId { get; } = "46e6296e-176f-4ebb-a14b-bdd5678c16e6";
|
|
public int ZeroDate { get; } = 2022;
|
|
|
|
public Uri GetProjectYearSite(string code)
|
|
{
|
|
return new Uri($"{SiteCollection}/sites/{GetProjYearTenant(code).Replace(" ","")}");
|
|
}
|
|
|
|
public string GetYear(string code)
|
|
{
|
|
var codeHeader = code.Split("-")[0];
|
|
var codeYears = Regex.Replace(codeHeader, @"\D", "");
|
|
var currentCent = DateTime.Today.Year.ToString().Substring(0, 2);
|
|
|
|
return currentCent + codeYears;
|
|
}
|
|
|
|
public bool IsValidDate(string code)
|
|
{
|
|
int zeroDate = ZeroDate;
|
|
int retDate = int.Parse(GetYear(code));
|
|
int curDate = int.Parse(DateTime.Now.Year.ToString());
|
|
|
|
if (zeroDate <= retDate && retDate <= curDate)
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
public string GetProjYearTenant(string code)
|
|
{
|
|
return $"Commesse {GetYear(code)}";
|
|
}
|
|
|
|
public string GetUser()
|
|
{
|
|
return "svcItsSharePointAdmin@italsort.com";
|
|
}
|
|
|
|
public SecureString GetPassword()
|
|
{
|
|
return new NetworkCredential("", "$O,D1XBp1O5.OdjZt86#a=").SecurePassword;
|
|
}
|
|
|
|
public string GetProjListTitle(string code)
|
|
{
|
|
return $"Lista {GetProjYearTenant(code)}";
|
|
}
|
|
|
|
public Uri GetSubProjSite(string projName)
|
|
{
|
|
return new Uri($"{GetProjectYearSite(projName)}/{projName}");
|
|
}
|
|
|
|
public string GetQuotationTenant()
|
|
{
|
|
return "Offerte";
|
|
}
|
|
|
|
public string GetQuotationLibrary(string code)
|
|
{
|
|
return $"{GetQuotationTenant()} {GetYear(code)}";
|
|
}
|
|
|
|
public Uri GetQuotationSite()
|
|
{
|
|
return new Uri($"{SiteCollection}/sites/{GetQuotationTenant()}");
|
|
}
|
|
|
|
public string GetSubProjList(string projName)
|
|
{
|
|
return $"SottoCommesse {projName}";
|
|
}
|
|
|
|
private string GetProjectTenant()
|
|
{
|
|
return "Commesse";
|
|
}
|
|
|
|
public Uri GetProjectSite()
|
|
{
|
|
return new Uri($"{SiteCollection}/sites/{GetProjectTenant()}");
|
|
}
|
|
|
|
public string GetNonComplianceTenant()
|
|
{
|
|
return "Non Conformità";
|
|
}
|
|
|
|
public string GetNonComplianceLibrary(string code)
|
|
{
|
|
return $"{GetNonComplianceTenant()} {GetYear(code)}";
|
|
}
|
|
|
|
public Uri GetNonComplianceSite()
|
|
{
|
|
return new Uri($"{SiteCollection}/sites/{GetNonComplianceTenant().Replace(" ", string.Empty)}");
|
|
}
|
|
|
|
public Uri GetPurchasingSite()
|
|
{
|
|
return new Uri($"{SiteCollection}/teams/purchasing/");
|
|
}
|
|
|
|
public string GetPurchasingOrderTenat()
|
|
{
|
|
return "Ordini di Acquisto";
|
|
}
|
|
|
|
public string GetPurchasingOrderLibrary(string code)
|
|
{
|
|
return $"{GetPurchasingOrderTenat()} {GetYear(code)}";
|
|
}
|
|
|
|
public Uri GetPurchasingOrderSite()
|
|
{
|
|
return new Uri($"{SiteCollection}/teams/purchasing/{GetPurchasingOrderTenat().Replace(" ", string.Empty)}");
|
|
}
|
|
|
|
public string GetPurchasingPackingSlipTenat()
|
|
{
|
|
return "DDT di Acquisto";
|
|
}
|
|
|
|
public string GetPurchasingPackingSlipLibrary(string code)
|
|
{
|
|
return $"{GetPurchasingPackingSlipTenat()} {GetYear(code)}";
|
|
}
|
|
|
|
public Uri GetPurchasingPackingSlipSite()
|
|
{
|
|
return new Uri($"{SiteCollection}/teams/purchasing/{GetPurchasingPackingSlipTenat().Replace(" ", string.Empty)}");
|
|
}
|
|
|
|
public string GetPurchasingRequestTenat()
|
|
{
|
|
return "Richieste di Acquisto";
|
|
}
|
|
|
|
public string GetPurchasingRequestLibrary(string code)
|
|
{
|
|
return $"{GetPurchasingRequestTenat()} {GetYear(code)}";
|
|
}
|
|
|
|
public Uri GetPurchasingRequestSite()
|
|
{
|
|
return new Uri($"{SiteCollection}/teams/purchasing/{GetPurchasingRequestTenat().Replace(" ", string.Empty)}");
|
|
}
|
|
} |