using library_spo_utils.Enums; using library_spo_utils.Interfaces.Services; using Microsoft.Extensions.Logging; namespace library_spo_utils.Services; internal class QuotationBuildService : IQuotationBuildService { private readonly ISiteOptions siteOptions; private readonly ISharePointAuthenticationManager sharePointAuthenticationManager; private readonly ISharePointCustomOperation spc; private readonly ITenantService tenantService; private readonly IQuotationDocLibraryService quotationDocLibraryService; private readonly IQuotationDocSetService quotationDocSetService; private readonly IFieldEntryDataUpdate _fieldEntryDataUpdate; private readonly ILogger logger; public QuotationBuildService( ISiteOptions siteOptions, ISharePointAuthenticationManager sharePointAuthenticationManager, ISharePointCustomOperation spc, ITenantService tenantService, IQuotationDocLibraryService quotationDocLibraryService, IQuotationDocSetService quotationDocSetService, IFieldEntryDataUpdate fieldEntryDataUpdate, ILogger logger) { this.siteOptions = siteOptions; this.sharePointAuthenticationManager = sharePointAuthenticationManager; this.spc = spc; this.tenantService = tenantService; this.quotationDocLibraryService = quotationDocLibraryService; this.quotationDocSetService = quotationDocSetService; _fieldEntryDataUpdate = fieldEntryDataUpdate; this.logger = logger; } public void CreateIfNotExists(string quotationName) { var site = siteOptions.GetQuotationSite(); var ctx = sharePointAuthenticationManager.GetContext(site); var list = siteOptions.GetQuotationLibrary(quotationName); var tenant = siteOptions.GetQuotationTenant(); if (!spc.SiteExist(ctx)) { tenantService.CreateForQuotation(); } if (!spc.ListExist(ctx, list)) { quotationDocLibraryService.Create(list, ctx); } if (!spc.FolderExistsInsideList(ctx, list, quotationName)) { quotationDocSetService.Create(quotationName, list, tenant, ctx); } else { logger.LogInformation($"Quotation with {quotationName} already exist"); _fieldEntryDataUpdate.FieldUpdate(ctx, list, quotationName, FieldUpdateType.Quotation); } } }