Пример #1
0
        /// <summary>
        /// Gets all forum data with section name in a typedlist. Sorted on Section.OrderNo, Section.SectionName, Forum.OrderNo, Forum.ForumName.
        /// </summary>
        /// <returns>Filled typedlist with all forum names / forumIDs and their containing section's name, sorted on Sectionname, and then forumname</returns>
        public static ForumsWithSectionNameTypedList GetAllForumsWithSectionNames()
        {
            ForumsWithSectionNameTypedList toReturn = new ForumsWithSectionNameTypedList();
            SortExpression sorter = new SortExpression(SectionFields.OrderNo.Ascending());

            sorter.Add(SectionFields.SectionName.Ascending());
            sorter.Add(ForumFields.OrderNo.Ascending());
            sorter.Add(ForumFields.ForumName.Ascending());
            toReturn.Fill(0, sorter);
            return(toReturn);
        }
Пример #2
0
        /// <summary>
        /// Gets the customer with the most orders and also the customers' number of orders.
        /// </summary>
        /// <param name="numberOfOrders">The number of orders.</param>
        /// <returns>the CustomerEntity with the most orders and also the number of orders of this customer</returns>
        /// <remarks>No error checking is applied to this routine, it's for illustrating the framework functionality.</remarks>
        public CustomerEntity GetCustomerWithMostOrdersAndNumberOfOrders(out int numberOfOrders)
        {
            Console.WriteLine("GetCustomerWithMostOrdersAndNumberOfOrders called");
            CustomerEntity toReturn = null;

            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                // create a list to obtain the customerid + # of orders. We'll just fetch the 1st row, ordering on the # of orders.
                ResultsetFields orderCustomerFields = new ResultsetFields(2);
                orderCustomerFields.DefineField(OrderFields.CustomerId, 0, "CustomerId");
                orderCustomerFields.DefineField(OrderFields.OrderId, 1, "NumberOfOrders", "", AggregateFunction.Count);
                GroupByCollection groupBy = new GroupByCollection();
                groupBy.Add(orderCustomerFields[0]);
                SortExpression sorter = new SortExpression();
                sorter.Add(new SortClause(orderCustomerFields[1], null, SortOperator.Descending));

                // now fetch the list, specify to fetch just 1 row, ordered descending on amount
                DataTable orderCustomer = new DataTable();
                adapter.FetchTypedList(orderCustomerFields, orderCustomer, null, 1, sorter, true, groupBy);
                numberOfOrders = (int)orderCustomer.Rows[0]["NumberOfOrders"];

                // we'll assume the data was there, so there is a row.
                toReturn = new CustomerEntity(orderCustomer.Rows[0]["CustomerId"].ToString());
                adapter.FetchEntity(toReturn);
            }
            return(toReturn);
        }
Пример #3
0
        private static SortExpression ConvertStringToSortExpression(string sortStr, Func <string, IEntityField2> fieldGetter)
        {
            var sortExpression = new SortExpression();

            if (!string.IsNullOrEmpty(sortStr))
            {
                var sortClauses = sortStr.Split(new[] { ';', ',' }, StringSplitOptions.None);
                foreach (var sortClause in sortClauses)
                {
                    var sortClauseElements = sortClause.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                    var sortField          = fieldGetter(sortClauseElements[0]);
                    if (sortField == null)
                    {
                        continue;
                    }

                    sortExpression.Add(new SortClause(
                                           sortField, null,
                                           sortClauseElements.Length > 1 &&
                                           sortClauseElements[1].Equals("desc",
                                                                        StringComparison.OrdinalIgnoreCase)
                                               ? SortOperator.Descending
                                               : SortOperator.Ascending
                                           ));
                }
            }
            return(sortExpression);
        }
Пример #4
0
        public AdminSitesCollection GetAdminSites(int siteUserGuid)
        {
            MCB.MasterPiece.Data.CollectionClasses.AdminSitesCollection adminSites = new AdminSitesCollection();

            IRelationCollection relations = new RelationCollection();

            relations.Add(AdminSitesEntity.Relations.AdminSiteModuleEntityUsingSiteGuid);
            relations.Add(AdminSiteModuleEntity.Relations.AdminUserAccessEntityUsingSiteModuleGuid);
            relations.Add(AdminUserAccessEntity.Relations.AdminUserEntityUsingUserGuid);

            IPredicateExpression filter = new PredicateExpression();

            filter.Add(AdminUserAccessFields.UserGuid == siteUserGuid);
            filter.AddWithAnd(AdminSitesFields.AccountingMarkAsInactive != 1);

            IPredicateExpression sensitiveDataFilter = new PredicateExpression();

            sensitiveDataFilter.Add(AdminUserFields.HasAccessToSitesWithSensitiveData == 1);
            sensitiveDataFilter.AddWithOr(AdminSitesFields.SiteContainsSensitiveData == 0);
            filter.AddWithAnd(sensitiveDataFilter);

            ISortExpression sort = new SortExpression();

            sort.Add(AdminSitesFields.CostumerFullname | SortOperator.Ascending);

            adminSites.GetMulti(filter, 0, sort, relations);

            return(adminSites);
        }
        // __LLBLGENPRO_USER_CODE_REGION_START CustomEntityCode
        public static CountryRegionCollection GetCountryRegionCollection()
        {
            ISortExpression Sort = new SortExpression();

            Sort.Add(CountryRegionFields.Name | SortOperator.Ascending);
            CountryRegionCollection Countries = new CountryRegionCollection();

            Countries.GetMulti(null, 0, Sort);
            return(Countries);
        }
        // __LLBLGENPRO_USER_CODE_REGION_START CustomEntityCode
        public static ShipMethodCollection GetShipMethodCollection()
        {
            ISortExpression Sort = new SortExpression();

            Sort.Add(ShipMethodFields.ShipRate | SortOperator.Ascending);
            ShipMethodCollection Methods = new ShipMethodCollection();

            Methods.GetMulti(null, 0, Sort);
            return(Methods);
        }
Пример #7
0
        // __LLBLGENPRO_USER_CODE_REGION_START CustomEntityCode
        public static StateProvinceCollection GetStateProvinceCollection()
        {
            ISortExpression Sort = new SortExpression();

            Sort.Add(StateProvinceFields.Name | SortOperator.Ascending);
            StateProvinceCollection States = new StateProvinceCollection();

            States.GetMulti(null, 0, Sort);
            return(States);
        }
Пример #8
0
        public ProductCollection GetLast10AddedProducts()
        {
            ProductCollection products = new ProductCollection();

            SortExpression sorter = new SortExpression();

            sorter.Add(ProductFields.AddedDate | SortOperator.Descending);
            products.GetMulti(null, 10, sorter);

            return(products);
        }
Пример #9
0
        public object GetLastAddedProducts(int topSelect)
        {
            ProductCollection productList = new ProductCollection();
            SortExpression    sorter      = new SortExpression();

            sorter.Add(ProductFields.AddedDate | SortOperator.Descending);
            PredicateExpression filter = new PredicateExpression();

            filter.Add(ProductFields.Status == true);
            productList.GetMulti(filter, topSelect, sorter);

            return(productList);
        }
Пример #10
0
        public ProductCollection GetSpeacialProducts()
        {
            ProductCollection   specialProducts = new ProductCollection();
            PredicateExpression filter          = new PredicateExpression(ProductFields.IsSpeacialProduct == true);

            filter.Add(ProductFields.Status == true);
            SortExpression sorter = new SortExpression();

            sorter.Add(ProductFields.AddedDate | SortOperator.Descending);

            specialProducts.GetMulti(filter, 6, sorter);

            return(specialProducts);
        }
        /// <summary>
        /// This function is used to query the data source for records.
        /// </summary>
        /// <param name="guid">The TemplateGUID of the requested entity.</param>
        /// <returns>EntityCollection<TemplateChunksEntity></returns>
        public static EntityCollection <TemplateChunksEntity> Select(Guid templateGUID, bool preParsed)
        {
            RelationPredicateBucket filter = new RelationPredicateBucket();

            filter.PredicateExpression.Add(TemplateChunksFields.TemplateGUID == templateGUID);
            filter.PredicateExpression.AddWithAnd(TemplateChunksFields.IsPreParsed == preParsed);

            ISortExpression sorter = new SortExpression();

            sorter.Add(TemplateChunksFields.ChunkID | SortOperator.Ascending);

            EntityCollection <TemplateChunksEntity> templatechunks = new EntityCollection <TemplateChunksEntity>();
            DataAccessAdapter ds = new DataAccessAdapter();

            ds.FetchEntityCollection(templatechunks, filter, 0, sorter);
            return(templatechunks);
        }
Пример #12
0
        public CustomersEntity GetByName(string CustomerName)
        {
            EntityCollection<CustomersEntity> cus = new EntityCollection<CustomersEntity>();

            IPredicateExpression predicate = new PredicateExpression();
            predicate.Add(CustomersFields.UserName == CustomerName);
            //predicate.AddWithAnd(CustomersFields.Telphone == "");

            RelationPredicateBucket filter = new RelationPredicateBucket();
            filter.PredicateExpression.Add(predicate);

            SortExpression sort = new SortExpression();
            sort.Add(CustomersFields.UserName | SortOperator.Ascending);

            using (DataAccessAdapterBase adapter = new DataAccessAdapterFactory().CreateAdapter())
            {
                adapter.FetchEntityCollection(cus, filter, 0, sort);
            }

            if (cus != null && cus.Count > 0)
                return cus[0];
            return null;
        }
Пример #13
0
        public LastViewedProductCollection GetLast5ViewedProducts(int storeId)
        {
            LastViewedProductCollection lastViewedProducts = new LastViewedProductCollection();
            RelationCollection          relationsToUse     = new RelationCollection();

            relationsToUse.Add(LastViewedProductEntity.Relations.ProductEntityUsingProductId);
            relationsToUse.Add(ProductEntity.Relations.StoreEntityUsingStoreId);
            PrefetchPath prefetchPath = new PrefetchPath((int)EntityType.LastViewedProductEntity);

            prefetchPath.Add(LastViewedProductEntity.PrefetchPathProduct).SubPath.Add(ProductEntity.PrefetchPathStore);

            PredicateExpression filter = new PredicateExpression();

            filter.Add(StoreFields.Id == storeId);
            SortExpression sorter = new SortExpression();

            sorter.Add(LastViewedProductFields.ViewedTime | SortOperator.Descending);


            lastViewedProducts.GetMulti(filter, 5, sorter, relationsToUse, prefetchPath);

            return(lastViewedProducts);
        }
Пример #14
0
        //public ProductCollection SortProductsByRate(ProductCollection productList, bool isAscending)
        //{

        //}

        public ProductCollection GetLast5AddedProducts(object m)
        {
            MembershipEntity   member    = new MembershipEntity(3);
            ProductCollection  products  = new ProductCollection();
            RelationCollection relations = new RelationCollection();

            relations.Add(ProductEntity.Relations.StoreEntityUsingStoreId);
            relations.Add(StoreEntity.Relations.MembershipEntityUsingMembershipId);

            IPrefetchPath prefatchPath = new PrefetchPath((int)EntityType.ProductEntity);

            prefatchPath.Add(ProductEntity.PrefetchPathStore).SubPath.Add(StoreEntity.PrefetchPathMembership);

            PredicateExpression filter = new PredicateExpression();

            filter.Add(MembershipFields.Id == member.Id);

            SortExpression sorter = new SortExpression();

            sorter.Add(ProductFields.AddedDate | SortOperator.Descending);
            products.GetMulti(filter, 5, sorter, relations, prefatchPath);

            return(products);
        }
        private static SortExpression ConvertStringToSortExpression(string sortStr, Func<string, IEntityField2> fieldGetter)
        {
            var sortExpression = new SortExpression();
            if (!string.IsNullOrEmpty(sortStr))
            {
                var sortClauses = sortStr.Split(new[] { ';', ',' }, StringSplitOptions.None);
                foreach (var sortClause in sortClauses)
                {
                    var sortClauseElements = sortClause.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                    var sortField = fieldGetter(sortClauseElements[0]);
                    if (sortField == null)
                        continue;

                    sortExpression.Add(new SortClause(
                                           sortField, null,
                                           sortClauseElements.Length > 1 &&
                                           sortClauseElements[1].Equals("desc",
                                                                        StringComparison.OrdinalIgnoreCase)
                                               ? SortOperator.Descending
                                               : SortOperator.Ascending
                                           ));
                }
            }
            return sortExpression;
        }
Пример #16
0
        /// <summary>
        /// Calculates the statistics for the Northwind database and shows them in the form, illustrating the
        /// direct database power LLBLGen Pro offers you through scalar functions, aggregates, group by and expressions.
        /// </summary>
        /// <remarks>No error checking is applied to this routine, it's for illustrating the framework functionality.</remarks>
        private void CalculateStatistics()
        {
            // get amount customers
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                int amountCustomers = (int)adapter.GetScalar(CustomerFields.CustomerId, AggregateFunction.CountRow);
                _amountCustomersTextBox.Text = amountCustomers.ToString();

                // get all order prices
                ResultsetFields orderPricesFields = new ResultsetFields(2);
                orderPricesFields.DefineField(OrderDetailFields.OrderId, 0, "OrderId");
                orderPricesFields.DefineField(OrderDetailFields.ProductId, 1, "OrderPrice", "", AggregateFunction.Sum);
                orderPricesFields[1].ExpressionToApply = (OrderDetailFields.Quantity * OrderDetailFields.UnitPrice);
                IGroupByCollection groupBy = new GroupByCollection();
                groupBy.Add(orderPricesFields[0]);

                // fetch in a datatable, orderid + the order price.
                DataTable orderPrices = new DataTable();
                adapter.FetchTypedList(orderPricesFields, orderPrices, null, 0, null, true, groupBy);

                // calculate average order price and which customer has the most expensive order
                decimal averageOrderPrice       = 0.0M;
                decimal highestOrderPrice       = 0.0M;
                int     orderIdWithHighestPrice = 0;
                for (int i = 0; i < orderPrices.Rows.Count; i++)
                {
                    decimal currentOrderPrice = (decimal)orderPrices.Rows[i]["OrderPrice"];
                    if (currentOrderPrice > highestOrderPrice)
                    {
                        highestOrderPrice       = currentOrderPrice;
                        orderIdWithHighestPrice = (int)orderPrices.Rows[i]["OrderId"];
                    }
                    averageOrderPrice += currentOrderPrice;
                }
                averageOrderPrice = averageOrderPrice / orderPrices.Rows.Count;
                _highestOrderPriceTextBox.Text = highestOrderPrice.ToString("C");
                _averageOrderPriceTextBox.Text = averageOrderPrice.ToString("C");

                // get order with highest price. Pull customer also in 1 go
                IPrefetchPath2 prefetchPathCustomer = new PrefetchPath2((int)EntityType.OrderEntity);
                prefetchPathCustomer.Add(OrderEntity.PrefetchPathCustomer);
                OrderEntity highestOrder = new OrderEntity(orderIdWithHighestPrice);
                adapter.FetchEntity(highestOrder, prefetchPathCustomer);
                _customerWithHighestOrder         = highestOrder.Customer;              // already loaded through prefetch path.
                _highestOrderCustomerTextBox.Text = _customerWithHighestOrder.CompanyName;

                // get customer with most orders.
                ResultsetFields orderCustomerFields = new ResultsetFields(2);
                orderCustomerFields.DefineField(OrderFields.CustomerId, 0, "CustomerId");
                orderCustomerFields.DefineField(OrderFields.OrderId, 1, "AmountOrders", "", AggregateFunction.Count);
                groupBy = new GroupByCollection();
                groupBy.Add(orderCustomerFields[0]);
                SortExpression sorter = new SortExpression();
                sorter.Add(new SortClause(orderCustomerFields[1], null, SortOperator.Descending));
                // now fetch the list, just 1 row, ordered descending on amount
                DataTable orderCustomer = new DataTable();
                adapter.FetchTypedList(orderCustomerFields, orderCustomer, null, 1, sorter, true, groupBy);
                _mostOrdersPerCustomerTextBox.Text = orderCustomer.Rows[0]["AmountOrders"].ToString();

                // we'll assume the data was there, so there is a row.
                _customerWithMostOrders = new CustomerEntity(orderCustomer.Rows[0]["CustomerId"].ToString());
                adapter.FetchEntity(_customerWithMostOrders);

                _mostOrdersCustomerTextBox.Text = _customerWithMostOrders.CompanyName;
            }
        }
        public ProductCollection GetSpeacialProducts()
        {
            ProductCollection specialProducts = new ProductCollection();
            PredicateExpression filter = new PredicateExpression(ProductFields.IsSpeacialProduct == true);
            filter.Add(ProductFields.Status == true);
            SortExpression sorter = new SortExpression();
            sorter.Add(ProductFields.AddedDate | SortOperator.Descending);

            specialProducts.GetMulti(filter,6,sorter);

            return specialProducts;
        }
        public object GetLastAddedProducts(int topSelect)
        {
            ProductCollection productList = new ProductCollection();
            SortExpression sorter = new SortExpression();
            sorter.Add(ProductFields.AddedDate | SortOperator.Descending);
            PredicateExpression filter = new PredicateExpression();

            filter.Add(ProductFields.Status == true);
            productList.GetMulti(filter, topSelect, sorter);

            return productList;
        }
        public LastViewedProductCollection GetLast5ViewedProducts(int storeId)
        {
            LastViewedProductCollection lastViewedProducts = new LastViewedProductCollection();
            RelationCollection relationsToUse = new RelationCollection();
            relationsToUse.Add(LastViewedProductEntity.Relations.ProductEntityUsingProductId);
            relationsToUse.Add(ProductEntity.Relations.StoreEntityUsingStoreId);
            PrefetchPath prefetchPath = new PrefetchPath((int)EntityType.LastViewedProductEntity);
            prefetchPath.Add(LastViewedProductEntity.PrefetchPathProduct).SubPath.Add(ProductEntity.PrefetchPathStore);

            PredicateExpression filter = new PredicateExpression();
            filter.Add(StoreFields.Id == storeId);
            SortExpression sorter = new SortExpression();
            sorter.Add( LastViewedProductFields.ViewedTime | SortOperator.Descending);

            lastViewedProducts.GetMulti(filter, 5, sorter, relationsToUse, prefetchPath);

            return lastViewedProducts;
        }
Пример #20
0
        public VideosEntity GetVideoByCatTextId(string TextId)
        {
            VideoCatalogEntity c = VideoCatalogManager.CreateInstant().GetByTextId(TextId);
            if (c != null)
            {
                EntityCollection<VideosEntity> items = new EntityCollection<VideosEntity>();
                IPredicateExpression pre = new PredicateExpression();
                pre.Add(VideosFields.CatalogId == c.Id);
                SortExpression sort = new SortExpression();
                sort.Add(VideosFields.Views | SortOperator.Descending);

                RelationPredicateBucket filter = new RelationPredicateBucket();
                filter.PredicateExpression.Add(pre);

                using (DataAccessAdapterBase adapter = new DataAccessAdapterFactory().CreateAdapter())
                {
                    adapter.FetchEntityCollection(items, filter, 1, sort);
                }

                if (items != null && items.Count > 0)
                    return items[0];
            }
            return null;
        }
        public ProductCollection GetLast10AddedProducts()
        {
            ProductCollection products = new ProductCollection();

            SortExpression sorter = new SortExpression();

            sorter.Add(ProductFields.AddedDate | SortOperator.Descending);
            products.GetMulti(null, 10,sorter);

            return products;
        }
Пример #22
0
        /// <summary>
        /// Does the search using MS Full text search
        /// </summary>
        /// <param name="searchString">Search string.</param>
        /// <param name="forumIDs">Forum Ids of forums to search into.</param>
        /// <param name="orderFirstElement">Order first element setting.</param>
        /// <param name="orderSecondElement">Order second element setting.</param>
        /// <param name="forumsWithThreadsFromOthers">The forums with threads from others.</param>
        /// <param name="userID">The userid of the calling user.</param>
        /// <param name="targetToSearch">The target to search.</param>
        /// <returns>
        /// TypedList filled with threads matching the query.
        /// </returns>
        public static SearchResultTypedList DoSearch(string searchString, List<int> forumIDs, SearchResultsOrderSetting orderFirstElement,
            SearchResultsOrderSetting orderSecondElement, List<int> forumsWithThreadsFromOthers, int userID, SearchTarget targetToSearch)
        {
            // the search utilizes full text search. It performs a CONTAINS upon the MessageText field of the Message entity.
            string searchTerms = PrepareSearchTerms(searchString);
            bool searchMessageText = (targetToSearch == SearchTarget.MessageText) || (targetToSearch == SearchTarget.MessageTextAndThreadSubject);
            bool searchSubject = (targetToSearch == SearchTarget.ThreadSubject) || (targetToSearch == SearchTarget.MessageTextAndThreadSubject);
            if(!(searchSubject || searchMessageText))
            {
                // no target specified, select message
                searchMessageText = true;
            }

            PredicateExpression searchTermFilter = new PredicateExpression();
            if(searchMessageText)
            {
                // Message contents filter
                searchTermFilter.Add(new FieldCompareSetPredicate(ThreadFields.ThreadID, MessageFields.ThreadID,
                                    SetOperator.In, new FieldFullTextSearchPredicate(MessageFields.MessageText, FullTextSearchOperator.Contains, searchTerms)));
            }
            if(searchSubject)
            {
                // Thread subject filter
                if(searchMessageText)
                {
                    searchTermFilter.AddWithOr(new FieldFullTextSearchPredicate(ThreadFields.Subject, FullTextSearchOperator.Contains, searchTerms));
                }
                else
                {
                    searchTermFilter.Add(new FieldFullTextSearchPredicate(ThreadFields.Subject, FullTextSearchOperator.Contains, searchTerms));
                }
            }
            IPredicateExpression mainFilter = searchTermFilter
                                                    .And(ForumFields.ForumID == forumIDs)
                                                    .And(ThreadGuiHelper.CreateThreadFilter(forumsWithThreadsFromOthers, userID));

            ISortExpression sorter = new SortExpression();
            // add first element
            sorter.Add(CreateSearchSortClause(orderFirstElement));
            if(orderSecondElement != orderFirstElement)
            {
                sorter.Add(CreateSearchSortClause(orderSecondElement));
            }

            SearchResultTypedList results = new SearchResultTypedList(false);

            try
            {
                // get the data from the db.
                results.Fill(500, sorter, false, mainFilter);
            }
            catch
            {
                // probably an error with the search words / user error. Swallow for now, which will result in an empty resultset.
            }

            return results;
        }
Пример #23
0
 /// <summary>
 /// Gets all forum data with section name in a typedlist. Sorted on Section.OrderNo, Section.SectionName, Forum.OrderNo, Forum.ForumName.
 /// </summary>
 /// <returns>Filled typedlist with all forum names / forumIDs and their containing section's name, sorted on Sectionname, and then forumname</returns>
 public static ForumsWithSectionNameTypedList GetAllForumsWithSectionNames()
 {
     ForumsWithSectionNameTypedList toReturn = new ForumsWithSectionNameTypedList();
     SortExpression sorter = new SortExpression(SectionFields.OrderNo.Ascending());
     sorter.Add(SectionFields.SectionName.Ascending());
     sorter.Add(ForumFields.OrderNo.Ascending());
     sorter.Add(ForumFields.ForumName.Ascending());
     toReturn.Fill(0, sorter);
     return toReturn;
 }
Пример #24
0
        public EntityCollection<EventsEntity> GetEvents(string EventType)
        {
            EntityCollection<EventsEntity> items = new EntityCollection<EventsEntity>();

            IPredicateExpression predicate = new PredicateExpression();
            predicate.Add(EventsFields.EventType == EventType);
            predicate.AddWithAnd(EventsFields.Approved == false);

            RelationPredicateBucket filter = new RelationPredicateBucket();
            filter.PredicateExpression.Add(predicate);

            SortExpression sort = new SortExpression();
            sort.Add(EventsFields.CreatedDate | SortOperator.Descending);

            using (DataAccessAdapterBase adapter = new DataAccessAdapterFactory().CreateAdapter())
            {
                adapter.FetchEntityCollection(items, filter);
            }

            return items;
        }
Пример #25
0
        /// <summary>
        /// Does the search using MS Full text search
        /// </summary>
        /// <param name="searchString">Search string.</param>
        /// <param name="forumIDs">Forum Ids of forums to search into.</param>
        /// <param name="orderFirstElement">Order first element setting.</param>
        /// <param name="orderSecondElement">Order second element setting.</param>
        /// <param name="forumsWithThreadsFromOthers">The forums with threads from others.</param>
        /// <param name="userID">The userid of the calling user.</param>
        /// <param name="targetToSearch">The target to search.</param>
        /// <returns>
        /// TypedList filled with threads matching the query.
        /// </returns>
        public static SearchResultTypedList DoSearch(string searchString, List <int> forumIDs, SearchResultsOrderSetting orderFirstElement,
                                                     SearchResultsOrderSetting orderSecondElement, List <int> forumsWithThreadsFromOthers, int userID, SearchTarget targetToSearch)
        {
            // the search utilizes full text search. It performs a CONTAINS upon the MessageText field of the Message entity.
            string searchTerms       = PrepareSearchTerms(searchString);
            bool   searchMessageText = (targetToSearch == SearchTarget.MessageText) || (targetToSearch == SearchTarget.MessageTextAndThreadSubject);
            bool   searchSubject     = (targetToSearch == SearchTarget.ThreadSubject) || (targetToSearch == SearchTarget.MessageTextAndThreadSubject);

            if (!(searchSubject || searchMessageText))
            {
                // no target specified, select message
                searchMessageText = true;
            }

            PredicateExpression searchTermFilter = new PredicateExpression();

            if (searchMessageText)
            {
                // Message contents filter
                searchTermFilter.Add(new FieldCompareSetPredicate(ThreadFields.ThreadID, MessageFields.ThreadID,
                                                                  SetOperator.In, new FieldFullTextSearchPredicate(MessageFields.MessageText, FullTextSearchOperator.Contains, searchTerms)));
            }
            if (searchSubject)
            {
                // Thread subject filter
                if (searchMessageText)
                {
                    searchTermFilter.AddWithOr(new FieldFullTextSearchPredicate(ThreadFields.Subject, FullTextSearchOperator.Contains, searchTerms));
                }
                else
                {
                    searchTermFilter.Add(new FieldFullTextSearchPredicate(ThreadFields.Subject, FullTextSearchOperator.Contains, searchTerms));
                }
            }
            IPredicateExpression mainFilter = searchTermFilter
                                              .And(ForumFields.ForumID == forumIDs)
                                              .And(ThreadGuiHelper.CreateThreadFilter(forumsWithThreadsFromOthers, userID));

            ISortExpression sorter = new SortExpression();

            // add first element
            sorter.Add(CreateSearchSortClause(orderFirstElement));
            if (orderSecondElement != orderFirstElement)
            {
                sorter.Add(CreateSearchSortClause(orderSecondElement));
            }

            SearchResultTypedList results = new SearchResultTypedList(false);

            try
            {
                // get the data from the db.
                results.Fill(500, sorter, false, mainFilter);
            }
            catch
            {
                // probably an error with the search words / user error. Swallow for now, which will result in an empty resultset.
            }

            return(results);
        }
        //public ProductCollection SortProductsByRate(ProductCollection productList, bool isAscending)
        //{
        //}
        public ProductCollection GetLast5AddedProducts(object m)
        {
            MembershipEntity member = new MembershipEntity(3);
            ProductCollection products = new ProductCollection();
            RelationCollection relations = new RelationCollection();
            relations.Add(ProductEntity.Relations.StoreEntityUsingStoreId);
            relations.Add(StoreEntity.Relations.MembershipEntityUsingMembershipId);

            IPrefetchPath prefatchPath = new PrefetchPath((int)EntityType.ProductEntity);
            prefatchPath.Add(ProductEntity.PrefetchPathStore).SubPath.Add(StoreEntity.PrefetchPathMembership);

            PredicateExpression filter = new PredicateExpression();

            filter.Add(MembershipFields.Id == member.Id);

            SortExpression sorter = new SortExpression();

            sorter.Add(ProductFields.AddedDate | SortOperator.Descending);
            products.GetMulti(filter, 5, sorter, relations, prefatchPath);

            return products;
        }
        private static EntityCollection LoadProductsForSection(IRelationPredicateBucket filter)
        {
            EntityCollection products = new EntityCollection(new ProductEntityFactory());
            ISortExpression sorter  = new SortExpression();
            sorter.Add(SortClauseFactory.Create(ProductFieldIndex.SortIndex, SortOperator.Ascending));

            IPrefetchPath2 pfVariations = new PrefetchPath2((int)EntityType.ProductEntity);
            pfVariations.Add(ProductEntity.PrefetchPathProductVariation);

            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.FetchEntityCollection(products, filter, 0, sorter, pfVariations);
            }

            return products;
        }
Пример #28
0
        public EntityCollection<CatalogsEntity> GetByParentIdNotId(int Id, int ParentId)
        {
            EntityCollection<CatalogsEntity> cats = new EntityCollection<CatalogsEntity>();

            SortExpression _sort = new SortExpression();
            _sort.Add(CatalogsFields.CatalogName | SortOperator.Ascending);

            IPredicateExpression predicate = new PredicateExpression();
            predicate.Add(CatalogsFields.ParentId == ParentId);
            predicate.AddWithAnd(CatalogsFields.Id != Id);

            RelationPredicateBucket filter = new RelationPredicateBucket();
            filter.PredicateExpression.Add(predicate);

            using (DataAccessAdapterBase adapter = new DataAccessAdapterFactory().CreateAdapter())
            {
                adapter.FetchEntityCollection(cats, filter, 0, _sort);
            }

            return cats;
        }