Beispiel #1
0
        ///<summary>
        /// Method Invocation of wrapper classes
        ///<summary>
        protected static FR_L3ABDA_GAPfSC_1435 Invoke(DbConnection Connection, DbTransaction Transaction, string ConnectionString, P_L3ABDA_GAPfSC_1435 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            bool cleanupConnection  = Connection == null;
            bool cleanupTransaction = Transaction == null;

            FR_L3ABDA_GAPfSC_1435 functionReturn = new FR_L3ABDA_GAPfSC_1435();

            try
            {
                if (cleanupConnection == true)
                {
                    Connection = CSV2Core_MySQL.Support.DBSQLSupport.CreateConnection(ConnectionString);
                    Connection.Open();
                }
                if (cleanupTransaction == true)
                {
                    Transaction = Connection.BeginTransaction();
                }

                functionReturn = Execute(Connection, Transaction, Parameter, securityTicket);

                #region Cleanup Connection/Transaction
                //Commit the transaction
                if (cleanupTransaction == true)
                {
                    Transaction.Commit();
                }
                //Close the connection
                if (cleanupConnection == true)
                {
                    Connection.Close();
                }
                #endregion
            }
            catch (Exception ex)
            {
                try
                {
                    if (cleanupTransaction == true && Transaction != null)
                    {
                        Transaction.Rollback();
                    }
                }
                catch { }

                try
                {
                    if (cleanupConnection == true && Connection != null)
                    {
                        Connection.Close();
                    }
                }
                catch { }

                throw new Exception("Exception occured in method cls_Get_ABDA_Products_For_SearchConditions", ex);
            }
            return(functionReturn);
        }
Beispiel #2
0
        protected static FR_L3ABDA_GAPfSC_1435 Execute(DbConnection Connection, DbTransaction Transaction, P_L3ABDA_GAPfSC_1435 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L3ABDA_GAPfSC_1435();
            returnValue.Result                 = new L3ABDA_GAPfSC_1435();
            returnValue.Result.Result          = new ABDASearchResult();
            returnValue.Result.Result.Products = new List <ABDAProduct>();

            string catalogITL = EnumUtils.GetEnumDescription(EPublicCatalogs.ABDA);

            var sbsCatalog = ORM_CMN_PRO_SubscribedCatalog.Query.Search(Connection, Transaction, new ORM_CMN_PRO_SubscribedCatalog.Query()
            {
                CatalogCodeITL = catalogITL,
                Tenant_RefID   = securityTicket.TenantID,
                IsDeleted      = false
            }).FirstOrDefault();

            if (sbsCatalog == null)
            {
                return(returnValue);
            }

            string query = new QueryBuilder <Product>()
                           .From(Parameter.pageIndex * Parameter.pageSize)
                           .Size(Parameter.pageSize)
                           .Query(q => q
                                  .Bool(b => b
                                        .Must(m => m
                                              .QueryString(qs => qs.Fields(new string[] { SearchCondition.GetFiledName(ProductField.NAME), SearchCondition.GetFiledName(ProductField.CODE) })
                                                           .Query(SearchCondition.GetQueryForField(Parameter.Conditions, ProductField.NAME)))
                                              .QueryString(qs => qs.Fields(SearchCondition.GetFiledName(ProductField.CODE)).Query(SearchCondition.GetQueryForField(Parameter.Conditions, ProductField.CODE)))
                                              .QueryString(qs => qs.Fields(SearchCondition.GetFiledName(ProductField.UNIT)).Query(SearchCondition.GetQueryForField(Parameter.Conditions, ProductField.UNIT)))
                                              .QueryString(qs => qs.Fields(SearchCondition.GetFiledName(ProductField.DOSAGE_FORM)).Query(SearchCondition.GetQueryForField(Parameter.Conditions, ProductField.DOSAGE_FORM)))
                                              .QueryString(qs => qs.Fields(SearchCondition.GetFiledName(ProductField.SUBSTANCE)).Query(SearchCondition.GetQueryForField(Parameter.Conditions, ProductField.SUBSTANCE)))
                                              .QueryString(qs => qs.Fields(SearchCondition.GetFiledName(ProductField.DISTRIBUTION_STATUS)).Query(SearchCondition.GetQueryForField(Parameter.Conditions, ProductField.DISTRIBUTION_STATUS)))
                                              .QueryString(qs => qs.Fields(SearchCondition.GetFiledName(ProductField.PRODUCER)).Query(SearchCondition.GetQueryForField(Parameter.Conditions, ProductField.PRODUCER)))
                                              .Prefix(p => p.Field(SearchCondition.GetFiledName(ProductField.NAME_TOKEN)).Prefix(SearchCondition.GetPrefixForField(Parameter.Conditions, ProductField.NAME_TOKEN)))
                                              )
                                        )
                                  )
                           .Sort(s => s
                                 .Field(SearchCondition.GetFiledName(Parameter.Order.field), (Parameter.Order.order == SortingOrder.ASC) ? PlainElastic.Net.SortDirection.asc : PlainElastic.Net.SortDirection.desc))
                           .BuildBeautified();

            var ProductService = CatalogServiceFactory.GetProductService();

            List <Product> retrievedProducts = new List <Product>();

            int hitsTotal;

            bool IsPartOFDefaultStock = Parameter.Conditions.Any(x => x.field == ProductField.IS_PART_OF_DEFAULT_STOCK && x.query == "true");


            if (IsPartOFDefaultStock)
            {
                List <string> ITLs = new List <string>();
                ITLs = cls_Get_ITLS_for_Products_HaveFlag_IsProductPartOfDefaultStock.Invoke(Connection, Transaction, securityTicket).Result.Select(x => x.ProductITL).ToList();
                ProductDetailsRequest requestWithITLS = new ProductDetailsRequest {
                    CatalogCode = catalogITL, ProductIDs = ITLs
                };

                var resWithITLS = ProductService.GetProductDetails(requestWithITLS);

                retrievedProducts = resWithITLS.ProductDetails.
                                    Where(x => !Parameter.Conditions.Any(y => y.field == ProductField.PRODUCER && !string.IsNullOrEmpty(y.query)) ||
                                          x.Producer.ToLower().Contains(Parameter.Conditions.SingleOrDefault(y => y.field == ProductField.PRODUCER).query.ToLower()))

                                    .Where(x => !(Parameter.Conditions.Any(y => y.field == ProductField.DOSAGE_FORM && !string.IsNullOrEmpty(y.query))) ||
                                           (x.Healthcare.DosageForm != null && x.Healthcare.DosageForm.ToLower().Contains(Parameter.Conditions.SingleOrDefault(y => y.field == ProductField.DOSAGE_FORM).query.ToLower())))

                                    .Where(x => !Parameter.Conditions.Any(y => y.field == ProductField.NAME && !string.IsNullOrEmpty(y.query)) ||
                                           x.Name.ToLower().Contains(Parameter.Conditions.SingleOrDefault(y => y.field == ProductField.NAME).query.ToLower()))

                                    .Where(x => !Parameter.Conditions.Any(y => y.field == ProductField.CODE && !string.IsNullOrEmpty(y.query)) ||
                                           x.Code.ToLower().Contains(Parameter.Conditions.SingleOrDefault(y => y.field == ProductField.CODE).query.ToLower()))

                                    .Where(x => !Parameter.Conditions.Any(y => y.field == ProductField.UNIT && !string.IsNullOrEmpty(y.query)) ||
                                           x.Packaging.Unit.ToLower().Contains(Parameter.Conditions.SingleOrDefault(y => y.field == ProductField.UNIT).query.ToLower()))
                                    .ToList();

                hitsTotal = retrievedProducts.Count();
            }
            else
            {
                ProductQueryRequest request = new ProductQueryRequest()
                {
                    CatalogCode = catalogITL
                };
                var res = ProductService.QueryProducts(request, query);
                hitsTotal         = res.hits.total;
                retrievedProducts = res.Documents.ToList();
            }


            var catalogInfoRequest = new CatalogInfoRequest()
            {
                CatalogCode = catalogITL
            };
            var catalogService = CatalogServiceFactory.GetCatalogService();
            var catalogInfo    = catalogService.GetCatalogInfo(catalogInfoRequest);

            // Find currency symbol
            var currencySymbol = string.Empty;
            if (catalogInfo != null && catalogInfo.CatalogInfo != null)
            {
                var currency = CL1_CMN.ORM_CMN_Currency.Query.Search(Connection, Transaction,
                                                                     new CL1_CMN.ORM_CMN_Currency.Query
                {
                    ISO4127      = catalogInfo.CatalogInfo.Currency,
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).SingleOrDefault();

                if (currency != null)
                {
                    currencySymbol = currency.Symbol;
                }
            }



            #region GetStandartPrices

            L3PR_GSPfPITLL_1258 standardPrices = new L3PR_GSPfPITLL_1258();
            if (retrievedProducts.Count() != 0)
            {
                var spParam = new P_L3PR_GSPfPITLL_1258()
                {
                    ProductITLList = retrievedProducts.Select(i => i.ProductITL).ToArray()
                };

                standardPrices = cls_Get_StandardPrices_for_ProductITLList.Invoke(Connection, Transaction, spParam, securityTicket).Result;
            }

            #endregion


            // Set ABDA products from Catalog Products
            var abdaProducts = new List <ABDAProduct>();
            foreach (var product in retrievedProducts)
            {
                var abdaProduct = new ABDAProduct();
                abdaProduct.Product        = product;
                abdaProduct.ABDAPrice      = product.GetDefaultPrice();
                abdaProduct.Prices         = standardPrices.Prices.Where(i => i.ProductITL == product.ProductITL).SingleOrDefault();
                abdaProduct.CurrencySymbol = currencySymbol;
                abdaProduct.Producer       = product.Producer;
                abdaProducts.Add(abdaProduct);
            }

            // Set ABDA results
            returnValue.Result.Result = new ABDASearchResult()
            {
                hitCount = hitsTotal,
                Products = abdaProducts
            };

            return(returnValue);

            #endregion UserCode
        }