using library_spo_utils.Interfaces.Repositories; using library_spo_utils.Interfaces.Services; namespace library_spo_utils.Services; internal class SharePointStructureBuilderService : ISharePointStructureBuilder { private readonly ISiteOptions siteOptions; private readonly ISiteService siteService; private readonly ISubProjectRepository subProjectRepository; private readonly ISubProjectBuilderService subProjectBuilderService; private readonly IQuotationBuildService quotationBuildService; private readonly INonComplianceBuildService nonComplianceBuildService; private readonly IPurchasingOrderBuildService purchasingOrderBuildService; private readonly IPurchasingPackingSlipBuildService purchasingPackingSlipBuildService; private readonly IPurchasingRequestBuildService purchasingRequestBuildService; private readonly IWebpartService webpartService; public SharePointStructureBuilderService( ISiteOptions siteOptions, ISiteService siteService, ISubProjectRepository subProjectRepository, ISubProjectBuilderService subProjectBuilderService, IQuotationBuildService quotationBuildService, INonComplianceBuildService nonComplianceBuildService, IPurchasingOrderBuildService purchasingOrderBuildService, IPurchasingPackingSlipBuildService purchasingPackingSlipBuildService, IPurchasingRequestBuildService purchasingRequestBuildService, IWebpartService webpartService) { this.siteOptions = siteOptions; this.siteService = siteService; this.subProjectRepository = subProjectRepository; this.subProjectBuilderService = subProjectBuilderService; this.quotationBuildService = quotationBuildService; this.nonComplianceBuildService = nonComplianceBuildService; this.purchasingOrderBuildService = purchasingOrderBuildService; this.purchasingPackingSlipBuildService = purchasingPackingSlipBuildService; this.purchasingRequestBuildService = purchasingRequestBuildService; this.webpartService = webpartService; } public bool BuildProject(string projName) { if (!siteOptions.IsValidDate(projName)) { throw new Exception(projName + " is not valid, return year " + siteOptions.GetYear(projName)); } var siteBuilderResult = siteService.CreateProjectSiteIfNotExists(projName); if (!siteBuilderResult) { throw new Exception($"Impossibile to build site"); } var subSiteBuilderResult = siteService.CreateSubSiteIfNotExists(projName); if (!subSiteBuilderResult) { throw new Exception($"Impossibile to build subSite for {projName} "); } var subProjects = subProjectRepository.GetFromProject(projName); var subProjectBuilderResult = subProjectBuilderService.SubProjectDocSet(projName, subProjects); if (!subProjectBuilderResult) { throw new Exception($"Impossibile to build subSite for {projName} "); } return true; } public bool BuildQuotation(string quotationName) { if (!siteOptions.IsValidDate(quotationName)) { throw new Exception(quotationName + " is not valid, return year " + siteOptions.GetYear(quotationName)); } var siteBuildResult = siteService.CreateQuotationSiteIfNotExists(quotationName); if (!siteBuildResult) { throw new Exception($"Impossibile to build site"); } quotationBuildService.CreateIfNotExists(quotationName); return true; } public bool BuildNonCompliance(string nonComplianceName) { if (!siteOptions.IsValidDate(nonComplianceName)) { throw new Exception(nonComplianceName + " is not valid, return year " + siteOptions.GetYear(nonComplianceName)); } var siteBuildResult = siteService.CreateNonComplianceSiteIfNotExists(nonComplianceName); if (!siteBuildResult) { throw new Exception($"Impossibile to build site"); } nonComplianceBuildService.CreateIfNotExists(nonComplianceName); return true; } public bool BuildPurchasingOrder(string purchasingOrderName) { if (!siteOptions.IsValidDate(purchasingOrderName)) { throw new Exception(purchasingOrderName + " is not valid, return year " + siteOptions.GetYear(purchasingOrderName)); } purchasingOrderBuildService.CreateIfNotExists(purchasingOrderName); return true; } public bool BuildPurchasingPackingSlip(string purchasingPackingSlipName) { if (!siteOptions.IsValidDate(purchasingPackingSlipName)) { throw new Exception(purchasingPackingSlipName + " is not valid, return year " + siteOptions.GetYear(purchasingPackingSlipName)); } purchasingPackingSlipBuildService.CreateIfNotExists(purchasingPackingSlipName); return true; } public bool BuildPurchasingRequest(string purchasingRequestName) { if (!siteOptions.IsValidDate(purchasingRequestName)) { throw new Exception(purchasingRequestName + " is not valid, return year " + siteOptions.GetYear(purchasingRequestName)); } purchasingRequestBuildService.CreateIfNotExists(purchasingRequestName); return true; } }