コード例 #1
0
 public List <Product> GetWidgetProducts(int pageNo, int pageSize)
 {
     using (var context = new CbContext())
     {
         return(context.Products.OrderByDescending(x => x.Id).Skip((pageNo - 1) * pageSize).Take(pageSize).Include(x => x.Category).ToList());
     }
 }
コード例 #2
0
 public tbl_Location GetLocations()
 {
     using (var context = new CbContext())
     {
         return(context.tbl_Locations.FirstOrDefault());
     }
 }
コード例 #3
0
 public List <tbl_State> GetStates()
 {
     using (var context = new CbContext())
     {
         return(context.tbl_States.ToList());
     }
 }
コード例 #4
0
 public Category GetCategoryById(int id)
 {
     using (var context = new CbContext())
     {
         return(context.Categories.Find(id));
     }
 }
コード例 #5
0
 public List <Category> GetCategories()
 {
     using (var context = new CbContext())
     {
         return(context.Categories.ToList());
     }
 }
コード例 #6
0
 public List <Order> GetProducts()
 {
     using (var context = new CbContext())
     {
         return(context.Orders.ToList());
     }
 }
コード例 #7
0
 public List <Category> GetFeaturedCategories()
 {
     using (var context = new CbContext())
     {
         return(context.Categories.Where(x => x.isFeatured && x.ImageURL != null).ToList());
     }
 }
コード例 #8
0
 public List <tbl_Pincode> GetPincodeByDistrict(int id)
 {
     using (var context = new CbContext())
     {
         return(context.tbl_Pincodes.Where(x => x.DistrictId == id).ToList());
     }
 }
コード例 #9
0
 public Product GetProductById(int id)
 {
     using (var context = new CbContext())
     {
         return(context.Products.Where(x => x.Id == id).Include(x => x.Category).FirstOrDefault());
     }
 }
コード例 #10
0
 public Config GetConfig(string Key)
 {
     using (var context = new CbContext())
     {
         return(context.Configrations.Find(Key));
     }
 }
コード例 #11
0
 public List <tbl_District> GetDistrictByState(int id)
 {
     using (var context = new CbContext())
     {
         return(context.tbl_Districts.Where(x => x.StateId == id).ToList());
     }
 }
コード例 #12
0
 public List <Product> GetProducts(List <int> IDs)
 {
     using (var context = new CbContext())
     {
         return(context.Products.Where(product => IDs.Contains(product.Id)).ToList());
     }
 }
コード例 #13
0
 public int GetMaximumPrice()
 {
     using (var context = new CbContext())
     {
         return((int)(context.Products.Max(x => x.Price)));
     }
 }
コード例 #14
0
 public List <Product> GetProductsByCategory(int categoryID, int pageSize)
 {
     using (var context = new CbContext())
     {
         return(context.Products.Where(x => x.Category.Id == categoryID).OrderByDescending(x => x.Id).Take(pageSize).Include(x => x.Category).ToList());
     }
 }
コード例 #15
0
 public List <Product> GetLatestProducts(int noOfProducts)
 {
     using (var context = new CbContext())
     {
         return(context.Products.OrderByDescending(x => x.Id).Take(noOfProducts).Include(x => x.Category).ToList());
     }
 }
コード例 #16
0
 public void SaveOrder(Order order)
 {
     using (var context = new CbContext())
     {
         context.Orders.Add(order);
         context.SaveChanges();
     }
 }
コード例 #17
0
 public void UpdateCategory(Category category)
 {
     using (var context = new CbContext())
     {
         context.Entry(category).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
コード例 #18
0
 public void SaveCategory(Category category)
 {
     using (var context = new CbContext())
     {
         context.Categories.Add(category);
         context.SaveChanges();
     }
 }
コード例 #19
0
 public void UpdateProduct(Product product)
 {
     using (var context = new CbContext())
     {
         context.Entry(product).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
コード例 #20
0
 public int SaveOrder(Order order)
 {
     using (var context = new CbContext())
     {
         context.Orders.Add(order);
         return(context.SaveChanges());
     }
 }
コード例 #21
0
 public void SaveProduct(Product product)
 {
     using (var context = new CbContext())
     {
         context.Entry(product.Category).State = System.Data.Entity.EntityState.Unchanged;
         context.Products.Add(product);
         context.SaveChanges();
     }
 }
コード例 #22
0
 public void DeleteProduct(int id)
 {
     using (var context = new CbContext())
     {
         var productDelete = context.Products.Find(id);
         context.Products.Remove(productDelete);
         context.SaveChanges();
     }
 }
コード例 #23
0
        public int ShopPageSize()
        {
            using (var context = new CbContext())
            {
                var pageSizeConfig = context.Configrations.Find("ShopPageSize");

                return(pageSizeConfig != null?int.Parse(pageSizeConfig.Value) : 6);
            }
        }
コード例 #24
0
        public List <Product> GetProducts(int pageNo)
        {
            int pageSize = 5;// int.Parse(ConfigurationsService.Instance.GetConfig("ListingPageSize").Value);

            using (var context = new CbContext())
            {
                //return context.Products.OrderBy(x => x.Id).Skip((pageNo - 1) * pageSize).Take(pageSize).Include(x => x.Category).ToList();
                return(context.Products.Include(x => x.Category).ToList());
            }
        }
コード例 #25
0
        public void DeleteCategory(int id)
        {
            using (var context = new CbContext())
            {
                var category = context.Categories.Where(x => x.Id == id).Include(x => x.Products).FirstOrDefault();

                context.Products.RemoveRange(category.Products); //first delete products of this category
                context.Categories.Remove(category);
                context.SaveChanges();
            }
        }
コード例 #26
0
 public int GetProductsCount(string search)
 {
     using (var context = new CbContext())
     {
         if (!string.IsNullOrEmpty(search))
         {
             return(context.Products.Where(product => product.Name != null &&
                                           product.Name.ToLower().Contains(search.ToLower()))
                    .Count());
         }
         else
         {
             return(context.Products.Count());
         }
     }
 }
コード例 #27
0
        public int SearchProductsCount(string searchTerm, int?minimumPrice, int?maximumPrice, int?categoryID, int?sortBy)
        {
            using (var context = new CbContext())
            {
                var products = context.Products.ToList();

                if (categoryID.HasValue)
                {
                    products = products.Where(x => x.Category.Id == categoryID.Value).ToList();
                }

                if (!string.IsNullOrEmpty(searchTerm))
                {
                    products = products.Where(x => x.Name.ToLower().Contains(searchTerm.ToLower())).ToList();
                }

                if (minimumPrice.HasValue)
                {
                    products = products.Where(x => x.Price >= minimumPrice.Value).ToList();
                }

                if (maximumPrice.HasValue)
                {
                    products = products.Where(x => x.Price <= maximumPrice.Value).ToList();
                }

                if (sortBy.HasValue)
                {
                    switch (sortBy.Value)
                    {
                    case 2:
                        products = products.OrderByDescending(x => x.Id).ToList();
                        break;

                    case 3:
                        products = products.OrderBy(x => x.Price).ToList();
                        break;

                    default:
                        products = products.OrderByDescending(x => x.Price).ToList();
                        break;
                    }
                }

                return(products.Count);
            }
        }