Service update, import changes from web_portal
This commit is contained in:
@@ -0,0 +1,254 @@
|
||||
using Microsoft.SharePoint.Client;
|
||||
using System;
|
||||
using library_spo_utils.Enums;
|
||||
using library_spo_utils.Interfaces.Repositories;
|
||||
using AngleSharp.Dom;
|
||||
using library_spo_utils.Interfaces.Services;
|
||||
using PnP.Framework.Extensions;
|
||||
|
||||
namespace library_spo_utils.Services;
|
||||
|
||||
internal class FieldEntryDataUpdate : IFieldEntryDataUpdate
|
||||
{
|
||||
private readonly ISiteOptions _siteOptions;
|
||||
private readonly IProjectRepository _projectRepository;
|
||||
private readonly ISubProjectRepository _subProjectRepository;
|
||||
private readonly IQuotationRepository _quotationRepository;
|
||||
private readonly INonComplianceRepository _nonComplianceRepository;
|
||||
private readonly IPurchasingOrderRepository _purchasingOrderRepository;
|
||||
private readonly IPurchasingPackingSlipRepository _purchasingPackingSlipRepository;
|
||||
private readonly IPurchasingRequestRepository _purchasingRequestRepository;
|
||||
|
||||
public FieldEntryDataUpdate(
|
||||
ISiteOptions siteOptions,
|
||||
IProjectRepository projectRepository,
|
||||
ISubProjectRepository subProjectRepository,
|
||||
IQuotationRepository quotationRepository,
|
||||
INonComplianceRepository nonComplianceRepository,
|
||||
IPurchasingOrderRepository purchasingOrderRepository,
|
||||
IPurchasingPackingSlipRepository purchasingPackingSlipRepository,
|
||||
IPurchasingRequestRepository purchasingRequestRepository
|
||||
)
|
||||
{
|
||||
_siteOptions = siteOptions;
|
||||
_projectRepository = projectRepository;
|
||||
_subProjectRepository = subProjectRepository;
|
||||
_quotationRepository = quotationRepository;
|
||||
_nonComplianceRepository = nonComplianceRepository;
|
||||
_purchasingOrderRepository = purchasingOrderRepository;
|
||||
_purchasingPackingSlipRepository = purchasingPackingSlipRepository;
|
||||
_purchasingRequestRepository = purchasingRequestRepository;
|
||||
}
|
||||
|
||||
public void FieldUpdate(ClientContext ctx, string listName, string element, FieldUpdateType type)
|
||||
{
|
||||
List oList = ctx.Web.Lists.GetByTitle(listName);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case FieldUpdateType.Project:
|
||||
Project(ctx, oList, element);
|
||||
break;
|
||||
|
||||
case FieldUpdateType.SubProject:
|
||||
SubProject(ctx, oList, element);
|
||||
break;
|
||||
|
||||
case FieldUpdateType.Quotation:
|
||||
Quotation(ctx, oList, element);
|
||||
break;
|
||||
|
||||
case FieldUpdateType.NonCompliance:
|
||||
NonCompliance(ctx, oList, element);
|
||||
break;
|
||||
|
||||
case FieldUpdateType.PurchasingOrder:
|
||||
PurchasingOrder(ctx, oList, element);
|
||||
break;
|
||||
|
||||
case FieldUpdateType.PurchasingPackingSlip:
|
||||
PurchasingPackingSlip(ctx, oList, element);
|
||||
break;
|
||||
|
||||
case FieldUpdateType.PurchasingRequest:
|
||||
PurchasingRequest(ctx, oList, element);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void Project(ClientContext ctx, List oList, string element)
|
||||
{
|
||||
var url = $"/sites/{_siteOptions.GetProjYearTenant(element).Replace(" ", string.Empty)}/{element}";
|
||||
|
||||
CamlQuery cQuery = new CamlQuery()
|
||||
{
|
||||
ViewXml = $"<View><Query><Where><Eq><FieldRef Name='PAL_ID_Project'/><Value Type='URL'>{url}</Value></Eq></Where></Query></View>"
|
||||
};
|
||||
|
||||
var collection = oList.GetItems(cQuery);
|
||||
|
||||
ctx.Load(collection);
|
||||
ctx.ExecuteQuery();
|
||||
|
||||
foreach (var oListItem in collection)
|
||||
{
|
||||
oListItem["PAL_Description"] = _projectRepository.DefaultDescription(element);
|
||||
oListItem["PAL_Customer"] = _projectRepository.DefaultCostumer(element);
|
||||
oListItem["PAL_DlvReason"] = _projectRepository.DefaultDlvReason(element);
|
||||
oListItem["PAL_Status"] = _projectRepository.DefaultState(element);
|
||||
oListItem.Update();
|
||||
}
|
||||
|
||||
ctx.ExecuteQuery();
|
||||
}
|
||||
|
||||
private void SubProject(ClientContext ctx, List oList, string element)
|
||||
{
|
||||
CamlQuery cQuery = new CamlQuery()
|
||||
{
|
||||
ViewXml = $"<View><Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>{element}</Value></Eq></Where></Query></View>"
|
||||
};
|
||||
|
||||
var collection = oList.GetItems(cQuery);
|
||||
|
||||
ctx.Load(collection);
|
||||
ctx.ExecuteQuery();
|
||||
|
||||
foreach (var oListItem in collection)
|
||||
{
|
||||
oListItem["_ExtendedDescription"] = _subProjectRepository.DefaultDescription(element);
|
||||
oListItem["PAL_Item"] = _subProjectRepository.DefaultItem(element);
|
||||
oListItem["PAL_ItemCode"] = _subProjectRepository.DefaultItemCode(element);
|
||||
oListItem["PAL_ItemDescription"] = _subProjectRepository.DefaultItemDescription(element);
|
||||
oListItem["PAL_SerialNumber"] = _subProjectRepository.DefaultSerialNumber(element);
|
||||
oListItem["PAL_Status"] = _subProjectRepository.DefaultState(element);
|
||||
oListItem.Update();
|
||||
}
|
||||
|
||||
ctx.ExecuteQuery();
|
||||
}
|
||||
|
||||
private void Quotation(ClientContext ctx, List oList, string element)
|
||||
{
|
||||
CamlQuery cQuery = new CamlQuery()
|
||||
{
|
||||
ViewXml = $"<View><Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>{element}</Value></Eq></Where></Query></View>"
|
||||
};
|
||||
|
||||
var collection = oList.GetItems(cQuery);
|
||||
|
||||
ctx.Load(collection);
|
||||
ctx.ExecuteQuery();
|
||||
|
||||
foreach (var oListItem in collection)
|
||||
{
|
||||
oListItem["PAL_ID_Quotation"] = _quotationRepository.DefaultIdQuotation(element);
|
||||
oListItem["PAL_Quotation_Name"] = _quotationRepository.DefaultQuotationName(element);
|
||||
oListItem["PAL_Description"] = _quotationRepository.DefaultDescription(element);
|
||||
oListItem["PAL_Quotation_Reason"] = _quotationRepository.DefaultQuotationReason(element);
|
||||
oListItem["PAL_Authors"] = _quotationRepository.DefaultAuthors(element);
|
||||
oListItem["PAL_Status"] = _quotationRepository.DefaultQuotationState(element);
|
||||
oListItem.Update();
|
||||
}
|
||||
|
||||
ctx.ExecuteQuery();
|
||||
}
|
||||
|
||||
private void NonCompliance(ClientContext ctx, List oList, string element)
|
||||
{
|
||||
CamlQuery cQuery = new CamlQuery()
|
||||
{
|
||||
ViewXml = $"<View><Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>{element}</Value></Eq></Where></Query></View>"
|
||||
};
|
||||
|
||||
var collection = oList.GetItems(cQuery);
|
||||
|
||||
ctx.Load(collection);
|
||||
ctx.ExecuteQuery();
|
||||
|
||||
foreach (var oListItem in collection)
|
||||
{
|
||||
oListItem["PAL_NC_Source"] = _nonComplianceRepository.DefaultNonComplianceSource(element);
|
||||
oListItem["PAL_NC_Reference"] = _nonComplianceRepository.DefaultNonComplianceReference(element);
|
||||
oListItem["PAL_NC_Nominative"] = _nonComplianceRepository.DefaultNonComplianceNominative(element);
|
||||
oListItem["PAL_NC_DateOfDetection"] = _nonComplianceRepository.DefaultNonComplianceDateOfDetection(element);
|
||||
oListItem["PAL_NC_Project"] = _nonComplianceRepository.DefaultNonComplianceProject(element);
|
||||
oListItem["PAL_NC_ItemCode"] = _nonComplianceRepository.DefaultNonComplianceItemCode(element);
|
||||
oListItem["PAL_NC_PortalUrl"] = _nonComplianceRepository.DefaultNonCompliancePortalUrl(element);
|
||||
oListItem["PAL_Status"] = _nonComplianceRepository.DefaultNonComplianceState(element);
|
||||
oListItem.Update();
|
||||
}
|
||||
|
||||
ctx.ExecuteQuery();
|
||||
}
|
||||
|
||||
private void PurchasingOrder(ClientContext ctx, List oList, string element)
|
||||
{
|
||||
|
||||
CamlQuery cQuery = new CamlQuery()
|
||||
{
|
||||
ViewXml = $"<View><Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>{element}</Value></Eq></Where></Query></View>"
|
||||
};
|
||||
|
||||
var collection = oList.GetItems(cQuery);
|
||||
|
||||
ctx.Load(collection);
|
||||
ctx.ExecuteQuery();
|
||||
|
||||
foreach (var oListItem in collection)
|
||||
{
|
||||
oListItem["PAL_PO_Supplier"] = _purchasingOrderRepository.DefaultPurchasingOrderSupplier(element);
|
||||
oListItem["PAL_Status"] = _purchasingOrderRepository.DefaultPurchasingOrderState(element);
|
||||
oListItem.Update();
|
||||
}
|
||||
|
||||
ctx.ExecuteQuery();
|
||||
}
|
||||
|
||||
private void PurchasingPackingSlip(ClientContext ctx, List oList, string element)
|
||||
{
|
||||
|
||||
CamlQuery cQuery = new CamlQuery()
|
||||
{
|
||||
ViewXml = $"<View><Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>{element}</Value></Eq></Where></Query></View>"
|
||||
};
|
||||
|
||||
var collection = oList.GetItems(cQuery);
|
||||
|
||||
ctx.Load(collection);
|
||||
ctx.ExecuteQuery();
|
||||
|
||||
foreach (var oListItem in collection)
|
||||
{
|
||||
oListItem["PAL_PO_Supplier"] = _purchasingPackingSlipRepository.DefaultPurchasingPackingSlipSupplier(element);
|
||||
oListItem["PAL_Status"] = _purchasingPackingSlipRepository.DefaultPurchasingPackingSlipState(element);
|
||||
oListItem.Update();
|
||||
}
|
||||
|
||||
ctx.ExecuteQuery();
|
||||
}
|
||||
|
||||
private void PurchasingRequest(ClientContext ctx, List oList, string element)
|
||||
{
|
||||
|
||||
CamlQuery cQuery = new CamlQuery()
|
||||
{
|
||||
ViewXml = $"<View><Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>{element}</Value></Eq></Where></Query></View>"
|
||||
};
|
||||
|
||||
var collection = oList.GetItems(cQuery);
|
||||
|
||||
ctx.Load(collection);
|
||||
ctx.ExecuteQuery();
|
||||
|
||||
foreach (var oListItem in collection)
|
||||
{
|
||||
oListItem["PAL_PO_Supplier"] = _purchasingRequestRepository.DefaultPurchasingRequestSupplier(element);
|
||||
oListItem["PAL_Status"] = _purchasingRequestRepository.DefaultPurchasingRequestState(element);
|
||||
oListItem.Update();
|
||||
}
|
||||
|
||||
ctx.ExecuteQuery();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user