protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5CA_ACER_1055 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); ORM_CMN_BPT_CTM_CatalogProductExtensionRequests request = new ORM_CMN_BPT_CTM_CatalogProductExtensionRequests(); var fetched = request.Load(Connection, Transaction, Parameter.RequestID); if (fetched.Status != FR_Status.Success || request.CMN_BPT_CTM_CatalogProductExtensionRequestID == Parameter.RequestID) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } ORM_USR_Account account = new ORM_USR_Account(); account.Load(Connection, Transaction, securityTicket.AccountID); request.IsAnswerSent = true; request.IfAnswerSent_By_BusinessParticipant_RefID = account.BusinessParticipant_RefID; request.IfAnswerSent_Date = DateTime.Now; request.Request_Answer = Parameter.RequestAnswer; request.Save(Connection, Transaction); ArticleRequestAnswerCreation answer = new ArticleRequestAnswerCreation(); answer.IntendedFor_TenantID = DBCrossTenantReader.Instance.GetPracticeTenantID(); answer.CreatedBy_TenantID = securityTicket.TenantID; answer.ArticleRequestITL = Guid.Parse(request.CatalogProductExtensionRequestITL); #region Add products ORM_CMN_BPT_CTM_CatalogProductExtensionRequest_Product product = null; if (Parameter.Products != null) { foreach (P_L5CA_ACER_1055a item in Parameter.Products) { product = new ORM_CMN_BPT_CTM_CatalogProductExtensionRequest_Product(); product.CMN_BPT_CTM_CatalogProductExtensionRequest_ProductID = Guid.NewGuid(); product.CMN_PRO_Product_RefID = item.ProductID; product.Creation_Timestamp = DateTime.Now; product.Tenant_RefID = securityTicket.TenantID; product.CatalogProductExtensionRequest_RefID = request.CMN_BPT_CTM_CatalogProductExtensionRequestID; product.Comment = ""; product.Save(Connection, Transaction); var cmnProProduct = ORM_CMN_PRO_Product.Query.Search(Connection, Transaction, new ORM_CMN_PRO_Product.Query() { CMN_PRO_ProductID = item.ProductID, Tenant_RefID = securityTicket.TenantID, IsDeleted = false }).Single(); Product prod = new Product(); prod.Product_ITL = cmnProProduct.ProductITL; answer.Products.Add(prod); } } #endregion returnValue.Result = request.CMN_BPT_CTM_CatalogProductExtensionRequestID; return(returnValue); #endregion UserCode }
protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5CA_SCER_0931 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); ORM_CMN_BPT_CTM_CatalogProductExtensionRequests request = new ORM_CMN_BPT_CTM_CatalogProductExtensionRequests(); request.Load(Connection, Transaction, Parameter.RequestID); if (Parameter.SendAnswer) { ORM_USR_Account account = new ORM_USR_Account(); account.Load(Connection, Transaction, securityTicket.AccountID); request.IfAnswerSent_By_BusinessParticipant_RefID = account.BusinessParticipant_RefID; request.IfAnswerSent_Date = DateTime.Now; } request.IsAnswerSent = Parameter.SendAnswer; request.Request_Answer = Parameter.RequestAnswer; request.Save(Connection, Transaction); #region Add products ORM_CMN_BPT_CTM_CatalogProductExtensionRequest_Product product = null; if (Parameter.Products != null) { foreach (P_L5CA_SCER_0931a item in Parameter.Products) { ORM_CMN_PRO_Product.Query prodQuery = new ORM_CMN_PRO_Product.Query() { CMN_PRO_ProductID = item.ProductID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }; var prod = ORM_CMN_PRO_Product.Query.Search(Connection, Transaction, prodQuery).Single(); if (String.IsNullOrEmpty(prod.ProductITL)) { prod.ProductITL = prod.CMN_PRO_ProductID.ToString(); prod.Save(Connection, Transaction); } if (item.IsDeleted) { ORM_CMN_BPT_CTM_CatalogProductExtensionRequest_Product.Query query = new ORM_CMN_BPT_CTM_CatalogProductExtensionRequest_Product.Query(); query.CatalogProductExtensionRequest_RefID = request.CMN_BPT_CTM_CatalogProductExtensionRequestID; query.CMN_BPT_CTM_CatalogProductExtensionRequest_ProductID = item.Request_ProductID; //query.Tenant_RefID = securityTicket.TenantID; //ORM_CMN_BPT_CTM_CatalogProductExtensionRequest_Product.Query.SoftDelete(Connection, Transaction, query); var itemToDelete = ORM_CMN_BPT_CTM_CatalogProductExtensionRequest_Product.Query.Search(Connection, Transaction, query).SingleOrDefault(); if (itemToDelete != default(ORM_CMN_BPT_CTM_CatalogProductExtensionRequest_Product)) { itemToDelete.IsDeleted = true; itemToDelete.Save(Connection, Transaction); } continue; } product = new ORM_CMN_BPT_CTM_CatalogProductExtensionRequest_Product(); product.CMN_BPT_CTM_CatalogProductExtensionRequest_ProductID = Guid.NewGuid(); product.CatalogProductExtensionRequest_RefID = request.CMN_BPT_CTM_CatalogProductExtensionRequestID; product.CMN_PRO_Product_RefID = prod.CMN_PRO_ProductID; product.Creation_Timestamp = DateTime.Now; product.Tenant_RefID = securityTicket.TenantID; product.Comment = ""; product.Save(Connection, Transaction); } } #endregion #region Save products in Catalog Products for Catalog Revision if (Parameter.Products != null) { // Find catalog revision var catalogRevision = ORM_CMN_PRO_Catalog_Revision.Query.Search(Connection, Transaction, new ORM_CMN_PRO_Catalog_Revision.Query { PublishedBy_BusinessParticipant_RefID = Guid.Empty, CMN_PRO_Catalog_RefID = request.RequestedFor_Catalog_RefID, Tenant_RefID = securityTicket.TenantID, IsDeleted = false }).OrderByDescending(x => x.PublishedOn_Date).FirstOrDefault(); if (catalogRevision != null) { foreach (P_L5CA_SCER_0931a item in Parameter.Products) { // Find product var p = ORM_CMN_PRO_Product.Query.Search(Connection, Transaction, new ORM_CMN_PRO_Product.Query() { CMN_PRO_ProductID = item.ProductID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }).Single(); // Find catalog product for product var catalogProduct = ORM_CMN_PRO_Catalog_Product.Query.Search(Connection, Transaction, new ORM_CMN_PRO_Catalog_Product.Query { CMN_PRO_Catalog_Revision_RefID = catalogRevision.CMN_PRO_Catalog_RevisionID, CMN_PRO_Product_RefID = p.CMN_PRO_ProductID, Tenant_RefID = p.Tenant_RefID, IsDeleted = false }).SingleOrDefault(); // If product not exist then add product to catalog products if (catalogProduct == null) { // Find product variant for product ORM_CMN_PRO_Product_Variant productVariant = null; if (p.HasProductVariants) { productVariant = ORM_CMN_PRO_Product_Variant.Query.Search(Connection, Transaction, new ORM_CMN_PRO_Product_Variant.Query { CMN_PRO_Product_RefID = p.CMN_PRO_ProductID, Tenant_RefID = p.Tenant_RefID, IsStandardProductVariant = true, IsDeleted = false }).OrderByDescending(x => x.Creation_Timestamp).FirstOrDefault(); } // Create catalog product for product catalogProduct = new ORM_CMN_PRO_Catalog_Product(); catalogProduct.CMN_PRO_Catalog_Revision_RefID = catalogRevision.CMN_PRO_Catalog_RevisionID; catalogProduct.CMN_PRO_Product_RefID = p.CMN_PRO_ProductID; catalogProduct.CMN_PRO_Product_Variant_RefID = p.HasProductVariants ? productVariant.CMN_PRO_Product_VariantID : Guid.Empty; catalogProduct.Tenant_RefID = securityTicket.TenantID; catalogProduct.Save(Connection, Transaction); } else { if (item.IsDeleted) { catalogProduct.IsDeleted = true; catalogProduct.Save(Connection, Transaction); } } } } } #endregion returnValue.Result = request.CMN_BPT_CTM_CatalogProductExtensionRequestID; return(returnValue); #endregion UserCode }