public static IQueryable <ProcessError> AccessList(ModelGeneralAttribute attr, Dictionary <string, object> param = null)
        {
            int ShopID = 0;

            if (param != null && param.ContainsKey("ShopID"))
            {
                ShopID = int.Parse(param["ShopID"].ToString());
            }
            else if (attr.Acl)
            {
                ShopID = LS.CurrentShop.ID;
            }
            else
            {
                return(
                    from oi in LS.CurrentEntityContext.ProcessErrors
                    select oi);
            }
            if (ShopID == 0)
            {
                ShopID = -1;
            }
            return(
                from oi in LS.CurrentEntityContext.ProcessErrors
                where oi.ShopID == ShopID
                select oi);
        }
        public static IQueryable <OrderItem> AccessList(ModelGeneralAttribute attr, Dictionary <string, object> param = null)
        {
            int ShopID = 0;
            //sort
            bool sortCategory = false;

            if (param != null && param.ContainsKey("_SortVariants"))
            {
                var sortVariants = param["_SortVariants"] as List <JsonKeyValue>;
                if (sortVariants.Count > 0 && sortVariants.FirstOrDefault().Name == "ProductShop.OrderPosition")
                {
                    sortCategory = true;
                }
            }
            if (param != null && param.ContainsKey("ShopID"))
            {
                ShopID = (int)param["ShopID"];
            }
            else if (attr.Acl)
            {
                ShopID = LS.CurrentShop.ID;
            }
            else
            {
                if (sortCategory)
                {
                    return((
                               from oi in LS.CurrentEntityContext.OrderItems
                               from ps in LS.CurrentEntityContext.ProductShopMap.Where(x => x.ID == oi.ProductShopID
                                                                                       ).DefaultIfEmpty()
                               orderby ps.OrderPosition
                               select oi).Distinct());
                }

                return(
                    from oi in LS.CurrentEntityContext.OrderItems
                    select oi);
            }

            if (sortCategory)
            {
                return((
                           from oi in LS.CurrentEntityContext.OrderItems
                           from ps in LS.CurrentEntityContext.ProductShopMap.Where(x => x.ID == oi.ProductShopID &&
                                                                                   x.ShopID == ShopID).DefaultIfEmpty()
                           orderby ps.OrderPosition
                           select oi).Distinct());
            }

            return((
                       from oi in LS.CurrentEntityContext.OrderItems
                       from ps in LS.CurrentEntityContext.ProductShopMap.Where(x => x.ID == oi.ProductShopID &&
                                                                               x.ShopID == ShopID).DefaultIfEmpty()
                       //on oi.ProductShopID equals ps.ID
                       // where ps.ShopID == ShopID
                       select oi).Distinct());
        }
 public static bool AccessTest(DiscountUsage discount, ModelGeneralAttribute attr)
 {
     if (attr.Acl)
     {
         if (LS.CurrentShop != null)
         {
             return(discount.ShopID == LS.CurrentShop.ID);
         }
         return(false);
     }
     ;
     return(true);
 }
 public static bool AccessTest(ProcessError productShop, ModelGeneralAttribute attr)
 {
     if (attr.Acl)
     {
         if (LS.CurrentShop != null)
         {
             return(productShop.ShopID == LS.CurrentShop.ID);
         }
         return(false);
     }
     ;
     return(true);
 }
 public static IQueryable <Product> AccessList(ModelGeneralAttribute attr, Dictionary <string, object> param = null)
 {
     if (param != null)
     {
         if (param.ContainsKey("ShopID"))
         {
             var shopID = Convert.ToInt32(param["ShopID"]);
             return((from p in LS.CurrentEntityContext.Products
                     join ps in LS.CurrentEntityContext.ProductShopMap
                     on p.ID equals ps.ProductID
                     where !p.Deleted && ps.ShopID == shopID
                     select p).Distinct());
         }
     }
     return(LS.CurrentEntityContext.Products.Where(x => !x.Deleted).AsQueryable());
 }
 public static bool AccessTest(OrderItem orderItem, ModelGeneralAttribute attr)
 {
     if (attr.Acl)
     {
         if (LS.CurrentShop != null)
         {
             var productShop = LS.CurrentEntityContext.ProductShopMap.FirstOrDefault(x => x.ID == orderItem.ProductShopID);
             if (productShop != null)
             {
                 return(productShop.ShopID == LS.CurrentShop.ID);
             }
         }
         return(false);
     }
     ;
     return(true);
 }
 public static bool AccessTest(Order order, ModelGeneralAttribute attr)
 {
     if (attr.Acl)
     {
         if (LS.CurrentShop != null)
         {
             var join = (from oi in LS.CurrentEntityContext.OrderItems
                         join ps in LS.CurrentEntityContext.ProductShopMap
                         on oi.ProductShopID equals ps.ID
                         where ps.ShopID == LS.CurrentShop.ID
                         select ps.ShopID).Any();
             return(join);
         }
         return(false);
     }
     ;
     return(true);
 }
        public static IQueryable <User> AccessList(ModelGeneralAttribute attr, Dictionary <string, object> param = null)
        {
            int ShopID = 0;

            var query = from oi in LS.CurrentEntityContext.Users
                        select oi;

            if (attr.Acl) // show only ordered users
            {
                ShopID = LS.CurrentShop.ID;
                query  = (from oi in LS.CurrentEntityContext.Users
                          join o in LS.CurrentEntityContext.Orders
                          on oi.ID equals o.UserID
                          where o.ShopID == ShopID
                          select oi).Distinct();
            }

            return(query);
        }
        public static IQueryable <Order> AccessList(ModelGeneralAttribute attr, Dictionary <string, object> param = null)
        {
            int ShopID = 0;

            if (param != null && param.ContainsKey("ShopID"))
            {
                ShopID = (int)param["ShopID"];
            }
            else if (attr.Acl)
            {
                ShopID = LS.CurrentShop.ID;
            }
            else
            {
                return(LS.CurrentEntityContext.Orders);
            }
            return((
                       from o in LS.CurrentEntityContext.Orders

                       where o.ShopID == ShopID
                       select o).Distinct());
        }
        public static IQueryable <DiscountUsage> AccessList(ModelGeneralAttribute attr, Dictionary <string, object> param = null)
        {
            int ShopID = 0;

            if (param != null && param.ContainsKey("ShopID"))
            {
                ShopID = (int)param["ShopID"];
            }
            else if (attr.Acl)
            {
                ShopID = LS.CurrentShop.ID;
            }
            else
            {
                return(
                    from oi in LS.CurrentEntityContext.DiscountUsages
                    select oi);
            }
            return(
                from oi in LS.CurrentEntityContext.DiscountUsages
                where oi.ShopID == ShopID
                select oi);
        }
Exemple #11
0
        public static IQueryable <ProductShop> AccessList(ModelGeneralAttribute attr, Dictionary <string, object> param = null)
        {
            int    ShopID      = 0;
            int    CategoryID  = 0;
            string productName = null;
            string productSku  = null;
            var    query       = from oi in LS.CurrentEntityContext.ProductShopMap
                                 select oi;

            if (param != null && param.ContainsKey("ShopID"))
            {
                ShopID = int.Parse(param["ShopID"].ToString());
            }
            else if (attr.Acl)
            {
                ShopID = LS.CurrentShop.ID;
            }
            //sort
            bool sortCategory = false;

            if (param != null && param.ContainsKey("_SortVariants"))
            {
                var sortVariants = param["_SortVariants"] as List <JsonKeyValue>;
                if (sortVariants.Count > 0 && sortVariants.FirstOrDefault().Name == "Product.CategoryID")
                {
                    sortCategory = true;
                }
            }



            if (ShopID > 0)
            {
                if (sortCategory)
                {
                    query = (
                        from oi in LS.CurrentEntityContext.ProductShopMap
                        join p in LS.CurrentEntityContext.Products.AsQueryable()
                        on oi.ProductID equals p.ID
                        where oi.ShopID == ShopID
                        orderby p.CategoryID
                        select oi);
                }
                else
                {
                    query = (
                        from oi in LS.CurrentEntityContext.ProductShopMap
                        where oi.ShopID == ShopID
                        select oi);
                }
            }
            if (param != null)
            {
                if (param.ContainsKey("Product.CategoryID"))
                {
                    CategoryID = int.Parse(param["Product.CategoryID"].ToString());
                }
                if (param.ContainsKey("Product.Name"))
                {
                    productName = param["Product.Name"].ToString();
                }
                if (param.ContainsKey("Product.SKU"))
                {
                    productSku = param["Product.SKU"].ToString();
                }
            }
            if (CategoryID > 0 || !string.IsNullOrEmpty(productName) || !string.IsNullOrEmpty(productSku))
            {
                var productQuery = LS.CurrentEntityContext.Products.AsQueryable();
                if (CategoryID > 0)
                {
                    productQuery = productQuery.Where(x => x.CategoryID == CategoryID);
                }
                if (!string.IsNullOrEmpty(productName))
                {
                    productQuery = productQuery.Where(x => x.Name.Contains(productName));
                }
                if (!string.IsNullOrEmpty(productSku))
                {
                    productQuery = productQuery.Where(x => x.SKU.Contains(productSku));
                }
                if (sortCategory)
                {
                    query = from ps in query
                            join p in productQuery
                            on ps.ProductID equals p.ID
                            orderby p.CategoryID
                            select ps;
                }
                else
                {
                    query = from ps in query
                            join p in productQuery
                            on ps.ProductID equals p.ID
                            select ps;
                }
            }
            else
            {
                if (sortCategory)
                {
                    query = (
                        from oi in query
                        join p in LS.CurrentEntityContext.Products.AsQueryable()
                        on oi.ProductID equals p.ID
                        orderby p.CategoryID
                        select oi);
                }
            }


            return(query);
        }