Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static List <ProductDTO> GetAllProducts(int?page, int?limit, string sortBy, string direction, string searchString, out int total)
        {
            using (var db = new ShopContext())
            {
                //total = db.Products.Count();
                var records = (from u in db.Products
                               select new ProductDTO
                {
                    ProductId = u.ProductId,
                    ProductName = u.ProductName,
                    ProductSEOName = u.ProductSEOName,
                    Category = u.Category,
                    ProductPrice = u.ProductPrice,
                    ProductCount = u.ProductCount,
                    Status = u.Status,
                    Discount = u.Discount,
                    Tax = u.Tax,
                    Shipping = u.Shipping
                }).AsQueryable();
                if (!string.IsNullOrWhiteSpace(searchString))
                {
                    records = records.Where(p => p.Category.Contains(searchString));
                }

                if (!string.IsNullOrEmpty(sortBy) && !string.IsNullOrEmpty(direction))
                {
                    if (direction.Trim().ToLower() == "asc")
                    {
                        records = SortHelper.OrderBy(records, sortBy);
                    }
                    else
                    {
                        records = SortHelper.OrderByDescending(records, sortBy);
                    }
                }
                else
                {
                    records = SortHelper.OrderByDescending(records, "ProductId");
                }

                if (page.HasValue && limit.HasValue)
                {
                    int start = (page.Value - 1) * limit.Value;
                    records = records.Skip(start).Take(limit.Value);
                }

                total = records.Count();

                return(records.Select(p => new ProductDTO
                {
                    ProductId = p.ProductId,
                    ProductName = p.ProductName,
                    ProductSEOName = p.ProductSEOName,
                    Category = p.Category,
                    ProductPrice = p.ProductPrice,
                    ProductCount = p.ProductCount,
                    Status = p.Status,
                    Discount = p.Discount,
                    Tax = p.Tax,
                    Shipping = p.Shipping
                }).ToList());
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static List <OrderDTO> OrderSeller(int?page, int?limit, string sortBy, string direction, string searchString, out int total)
        {
            using (var db = new ShopContext())
            {
                int mid = MemberManage.Get(HttpContext.Current.User.Identity.Name).Id;


                var records = (from item in db.Orders
                               from subItem in item.OrderDetails
                               where subItem.Product.SellerId == mid
                               select new OrderDTO
                {
                    OrderId = item.Id,
                    ContactName = item.ContactName,
                    ContactAddress = item.ContactAddress,
                    ContactPhone = item.ContactPhone,
                    Status = item.OrderStatus.Name,
                    OrderDate = item.OrderDate
                }).Distinct().AsQueryable();

                //var records = (from u in db.OrderDetails
                //               where u.product.SellerId == mid
                //               select new OrderDTO
                //               {
                //                   OrderId = u.orderSummary.Id,
                //                   ContactName = u.orderSummary.ContactName,
                //                   ContactAddress = u.orderSummary.ContactAddress,
                //                   ContactPhone = u.orderSummary.ContactPhone,
                //                   Status = u.orderSummary.OrderStatus.Name,
                //                   OrderDate = u.orderSummary.OrderDate
                //               }).AsQueryable();


                if (!string.IsNullOrWhiteSpace(searchString))
                {
                    records = records.Where(p => p.ContactName.Contains(searchString) ||
                                            p.ContactAddress.Contains(searchString) ||
                                            p.ContactPhone.Contains(searchString)
                                            );
                }

                if (!string.IsNullOrEmpty(sortBy) && !string.IsNullOrEmpty(direction))
                {
                    if (direction.Trim().ToLower() == "asc")
                    {
                        records = SortHelper.OrderBy(records, sortBy);
                    }
                    else
                    {
                        records = SortHelper.OrderByDescending(records, sortBy);
                    }
                }
                else
                {
                    records = SortHelper.OrderByDescending(records, "OrderId");
                }

                if (page.HasValue && limit.HasValue)
                {
                    int start = (page.Value - 1) * limit.Value;
                    records = records.Skip(start).Take(limit.Value);
                }
                total = records.Count();
                return(records.Select(u => new OrderDTO
                {
                    OrderId = u.OrderId,
                    ContactName = u.ContactName,
                    ContactAddress = u.ContactAddress,
                    ContactPhone = u.ContactPhone,
                    Status = u.Status,
                    OrderDate = u.OrderDate
                }).ToList());
            }
        }