Exemple #1
0
        public IQueryable <product> GetProducts(long subdomain, string categoryID,
                                                string sidx, string sord, string alarm, ProductFlag flag, long?collection)
        {
            IQueryable <product> results = db.products.Where(x => x.subdomainid == subdomain);

            if (!string.IsNullOrEmpty(categoryID))
            {
                var id = long.Parse(categoryID);
                results = results.Where(x => x.category == id || x.productCategory.parentID == id);
            }

            switch (flag)
            {
            case ProductFlag.NONE:
                results = results.Where(x => (x.flags & (int)(ProductFlag.INACTIVE | ProductFlag.ARCHIVED)) == 0);
                break;

            case ProductFlag.INACTIVE:
                results = results.Where(x => (x.flags & (int)ProductFlag.INACTIVE) != 0);
                break;

            case ProductFlag.ARCHIVED:
                results = results.Where(x => (x.flags & (int)ProductFlag.ARCHIVED) != 0);
                break;
            }

            if (collection.HasValue)
            {
                results =
                    results.Where(x => x.productCollectionMembers.Count(y => y.collectionid == collection.Value) != 0);
            }

            IOrderedQueryable <product> ordered = null;

            if (!string.IsNullOrEmpty(sord) && !string.IsNullOrEmpty(sidx))
            {
                if (sord == "asc")
                {
                    ordered = results.OrderBy(sidx);
                }
                else if (sord == "desc")
                {
                    ordered = results.OrderByDescending(sidx);
                }
            }

            return(ordered ?? results);
        }
Exemple #2
0
 public Product(string productname, ProductFlag _flag, double inprice = 0.0)
 {
     name  = productname;
     price = inprice;
     flag  = _flag;
 }