Beispiel #1
0
 public IList <Models.ProductCM> GetProductList(ProductSearchField productSearchField, string productSearchText,
                                                Decimal?priceLow, Decimal?priceHigh, DateTime?dateFrom, DateTime?dateTo, int?statusCode,
                                                PaginationRequest paging, out int totalCount, out int newPageIndex)
 {
     return(this._productRepository.GetProductList(productSearchField, productSearchText,
                                                   priceLow, priceHigh, dateFrom, dateTo, statusCode, paging, out totalCount, out newPageIndex));
 }
        private void AddProductToOrderLineByID(string ProductId_ManualSelection)
        {
            Element.ScrolTo(AddProductBtn);
            AddProductBtn.Click();
            Wait.UntilAllToastMessageHide();
            Wait.UntilDisply(By.Id("productSearchForm"));
            ProductSearchByDropDown.Click();
            Wait.MLSeconds(200);
            BYProductIdMenuItem.Click();
            ProductSearchField.SendKeys(ProductId_ManualSelection);
            Wait.MLSeconds(200);
            ProductSearchBtn.Click();
            By DispledElement = Wait.UntilDisply(new List <By>()
            {
                By.ClassName("toast-message"), By.ClassName("product-results")
            });

            Wait.MLSeconds(500);
            if (DispledElement.ToString() == "By.ClassName[Contains]: product-results")
            {
                IList <IWebElement> pList      = ProductsearchResult.FindElements(By.CssSelector("div[ng-click='addProductSelection(product)']"));
                IWebElement         Productele = pList.FirstOrDefault(e => e.Text.Contains(ProductId_ManualSelection));
                Productele.Click();
                Wait.MLSeconds(500);
            }
            else
            {
                Logger.Log(LogingType.NoResult, string.Format("Serch product by Id : {0}", ProductId_ManualSelection));
            }

            ProductsearchModelCancelbtn.Click();
            Wait.MLSeconds(500);
        }
 public IList<Models.ProductCM> GetProductList(ProductSearchField productSearchField, string productSearchText,
                     Decimal? priceLow, Decimal? priceHigh, DateTime? dateFrom, DateTime? dateTo, int? statusCode,
                     PaginationRequest paging, out int totalCount, out int newPageIndex)
 {
     return this._productRepository.GetProductList(productSearchField, productSearchText,
            priceLow, priceHigh, dateFrom, dateTo, statusCode, paging, out totalCount, out newPageIndex);
 }
Beispiel #4
0
        public IList <Models.ProductCM> GetProductList(ProductSearchField productSearchField, string productSearchText,
                                                       Decimal?priceLow, Decimal?priceHigh, DateTime?dateFrom, DateTime?dateTo, int?statusCode,
                                                       PaginationRequest paging, out int totalCount, out int newPageIndex)
        {
            //Query to join parent and child entities and return custom model
            //IQueryable<Models.ProductCM> query = this.UnitOfWork.Context.Products
            //      .Join(this.UnitOfWork.Context.Categories, p => p.CategoryID, c => c.CategoryID,
            //            (p, c) => new { p, c })
            //      .Join(this.UnitOfWork.Context.ProductStatusTypes, p2 => p2.p.StatusCode, ps => ps.StatusCode,
            //            (p2, ps) => new Models.ProductCM
            //            {
            //                ProductID = p2.p.ProductID,
            //                ProductName = p2.p.ProductName,
            //                CategoryID = p2.p.CategoryID,
            //                CategoryName = p2.c.CategoryName,
            //                UnitPrice = p2.p.UnitPrice,
            //                StatusCode = p2.p.StatusCode,
            //                StatusDescription = ps.Description,
            //                AvailableSince = p2.p.AvailableSince
            //            });

            //Test
            //var rtnList = this.UnitOfWork.Context.Database.SqlQuery<Entities.Category>("GetAllCategorisAndProducts").ToList();

            //var blogs = ((IObjectContextAdapter)this.UnitOfWork.Context)
            //.ObjectContext
            //.Translate<Entities.Category>((reader, "Blogs", MergeOption.AppendOnly);


            IQueryable <Models.ProductCM> query = this.UnitOfWork.Context.Products
                                                  .GroupJoin(this.UnitOfWork.Context.Categories,
                                                             p => p.CategoryID, c => c.CategoryID,
                                                             (p, c) => new { p, c })
                                                  .GroupJoin(this.UnitOfWork.Context.ProductStatusTypes,
                                                             p1 => p1.p.StatusCode, s => s.StatusCode,
                                                             (p1, s) => new { p1, s })
                                                  .SelectMany(p2 => p2.s.DefaultIfEmpty(), (p2, s2) => new { p2 = p2.p1, s2 = s2 })
                                                  .Select(f => new Models.ProductCM
            {
                ProductID         = f.p2.p.ProductID,
                ProductName       = f.p2.p.ProductName,
                CategoryID        = f.p2.p.CategoryID,
                CategoryName      = f.p2.p.Category.CategoryName,
                UnitPrice         = f.p2.p.UnitPrice,
                StatusCode        = f.p2.p.StatusCode,
                StatusDescription = f.s2.Description,
                AvailableSince    = f.p2.p.AvailableSince
            });

            //var query =
            //    from pr in this.UnitOfWork.Context.Products
            //    join ca in this.UnitOfWork.Context.Categories
            //        on pr.CategoryID equals ca.CategoryID
            //    join ps in this.UnitOfWork.Context.ProductStatusTypes
            //        on pr.StatusCode equals ps.StatusCode into tempJoin
            //    from t2 in tempJoin.DefaultIfEmpty()
            //    select new Models.ProductCM
            //    {
            //        ProductID = pr.ProductID,
            //        ProductName = pr.ProductName,
            //        CategoryID = pr.CategoryID,
            //        CategoryName = ca.CategoryName,
            //        UnitPrice = pr.UnitPrice,
            //        StatusCode = pr.StatusCode,
            //        StatusDescription = t2.Description,
            //        AvailableSince = pr.AvailableSince
            //    };

            //More readable code:
            //var query =
            //    from pr in this.UnitOfWork.Context.Products
            //    from ca in this.UnitOfWork.Context.Categories
            //       .Where(ca => ca.CategoryID == pr.CategoryID)
            //    from ps in this.UnitOfWork.Context.ProductStatusTypes
            //       .Where(ps => ps.StatusCode == pr.StatusCode).DefaultIfEmpty()
            //    select new Models.ProductCM
            //            {
            //                ProductID = pr.ProductID,
            //                ProductName = pr.ProductName,
            //                CategoryID = pr.CategoryID,
            //                CategoryName = ca.CategoryName,
            //                UnitPrice = pr.UnitPrice,
            //                StatusCode = pr.StatusCode,
            //                StatusDescription = ps.Description,
            //                AvailableSince = pr.AvailableSince
            //            };

            var predicate = PredicateBuilder.True <Models.ProductCM>();

            if (!string.IsNullOrEmpty(productSearchText))
            {
                if (productSearchField == ProductSearchField.CategoryId && Util.IsNumeric(productSearchText))
                {
                    int categoryId = Convert.ToInt32(productSearchText);
                    predicate = predicate.And(p => p.CategoryID == categoryId);
                }
                if (productSearchField == ProductSearchField.CategoryName)
                {
                    predicate = predicate.And(p => p.CategoryName.ToLower().Contains(productSearchText.ToLower()));
                }
                if (productSearchField == ProductSearchField.ProductId && Util.IsNumeric(productSearchText))
                {
                    int productId = Convert.ToInt32(productSearchText);
                    predicate = predicate.And(p => p.ProductID == productId);
                }
                if (productSearchField == ProductSearchField.ProductName)
                {
                    predicate = predicate.And(p => p.ProductName.ToLower().Contains(productSearchText.ToLower()));
                }
            }
            if (priceLow != null)
            {
                predicate = predicate.And(p => p.UnitPrice >= priceLow.Value);
            }
            if (priceHigh != null)
            {
                predicate = predicate.And(p => p.UnitPrice <= priceHigh.Value);
            }
            if (dateFrom != null)
            {
                predicate = predicate.And(p => p.AvailableSince >= dateFrom.Value);
            }
            if (dateTo != null)
            {
                predicate = predicate.And(p => p.AvailableSince <= dateTo.Value);
            }
            if (statusCode != null)
            {
                predicate = predicate.And(p => p.StatusCode == statusCode.Value);
            }
            query = query.Where(predicate);

            //IList<Models.ProductCM> resultList1 = query.ToList();
            IList <Models.ProductCM> resultList =
                GenericSorterPager.GetSortedPagedList <Models.ProductCM>(query, paging, out totalCount);

            //For issue when refreshing data after CRUD causes no row in the current page.
            newPageIndex = -1;
            while (paging.PageIndex > 0 && resultList.Count < 1)
            {
                paging.PageIndex -= 1;
                newPageIndex      = paging.PageIndex;
                resultList        =
                    GenericSorterPager.GetSortedPagedList <Models.ProductCM>(query, paging, out totalCount);
            }
            return(resultList);
        }