public List <Product> GetProducts(List <int> IDs)
 {
     using (var context = new ClothMarketContext())
     {
         return(context.Products.Where(product => IDs.Contains(product.ID)).ToList());
     }
 }
Beispiel #2
0
 public List <Category> GetFeaturedCategories()
 {
     using (var context = new ClothMarketContext())
     {
         return(context.Categories.Where(x => x.isFeatured && x.ImageURL != null).ToList());
     }
 }
 public int GetMaximumPrice()
 {
     using (var context = new ClothMarketContext())
     {
         return((int)(context.Products.Max(x => x.Price)));
     }
 }
 public List <Product> GetProducts(int pageNo, int pageSize)
 {
     using (var context = new ClothMarketContext())
     {
         return(context.Products.OrderByDescending(x => x.ID).Skip((pageNo - 1) * pageSize).Take(pageSize).Include(x => x.Category).ToList());
     }
 }
 public List <Product> GetLatestProducts(int numberOfProducts)
 {
     using (var context = new ClothMarketContext())
     {
         return(context.Products.OrderByDescending(x => x.ID).Take(numberOfProducts).Include(x => x.Category).ToList());
     }
 }
Beispiel #6
0
 public Order GetOrderByID(int ID)
 {
     using (var context = new ClothMarketContext())
     {
         return(context.Orders.Where(x => x.ID == ID).Include(x => x.OrderItems).Include("OrderItems.Product").FirstOrDefault());
     }
 }
Beispiel #7
0
 public Config GetConfig(string Key)
 {
     using (var context = new ClothMarketContext())
     {
         return(context.Configurations.Find(Key));
     }
 }
 public List <Product> GetProductsByCategory(int categoryID, int pageSize)
 {
     using (var context = new ClothMarketContext())
     {
         return(context.Products.Where(x => x.Category.ID == categoryID).OrderByDescending(x => x.ID).Take(pageSize).Include(x => x.Category).ToList());
     }
 }
Beispiel #9
0
 public Category GetCategory(int ID)
 {
     using (var context = new ClothMarketContext())
     {
         return(context.Categories.Find(ID));
     }
 }
 public List <Product> GetProducts(string search, int pageNo, int pageSize)
 {
     using (var context = new ClothMarketContext())
     {
         if (!string.IsNullOrEmpty(search))
         {
             return(context.Products.Where(product => product.Name != null &&
                                           product.Name.ToLower().Contains(search.ToLower()))
                    .OrderBy(x => x.ID)
                    .Skip((pageNo - 1) * pageSize)
                    .Take(pageSize)
                    .Include(x => x.Category)
                    .ToList());
         }
         else
         {
             return(context.Products
                    .OrderBy(x => x.ID)
                    .Skip((pageNo - 1) * pageSize)
                    .Take(pageSize)
                    .Include(x => x.Category)
                    .ToList());
         }
     }
 }
Beispiel #11
0
        public List <Category> GetCategories(string search, int pageNo)
        {
            int pageSize = 3;

            using (var context = new ClothMarketContext())
            {
                if (!string.IsNullOrEmpty(search))
                {
                    return(context.Categories.Where(category => category.Name != null &&
                                                    category.Name.ToLower().Contains(search.ToLower()))
                           .OrderBy(x => x.ID)
                           .Skip((pageNo - 1) * pageSize)
                           .Take(pageSize)
                           .Include(x => x.Products)
                           .ToList());
                }
                else
                {
                    return(context.Categories
                           .OrderBy(x => x.ID)
                           .Skip((pageNo - 1) * pageSize)
                           .Take(pageSize)
                           .Include(x => x.Products)
                           .ToList());
                }
            }
        }
 public Product GetProduct(int ID)
 {
     using (var context = new ClothMarketContext())
     {
         return(context.Products.Where(x => x.ID == ID).Include(x => x.Category).FirstOrDefault());
     }
 }
Beispiel #13
0
 public int SaveOrder(Order order)
 {
     using (var context = new ClothMarketContext())
     {
         context.Orders.Add(order);
         return(context.SaveChanges());
     }
 }
 public void UpdateProduct(Product product)
 {
     using (var context = new ClothMarketContext())
     {
         context.Entry(product).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Beispiel #15
0
 public List <Category> GetAllCategories()
 {
     using (var context = new ClothMarketContext())
     {
         return(context.Categories
                .ToList());
     }
 }
Beispiel #16
0
 public void SaveCategory(Category category)
 {
     using (var context = new ClothMarketContext())
     {
         context.Categories.Add(category);
         context.SaveChanges();
     }
 }
Beispiel #17
0
 public void UpdateCategory(Category category)
 {
     using (var context = new ClothMarketContext())
     {
         context.Entry(category).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Beispiel #18
0
        public int ShopPageSize()
        {
            using (var context = new ClothMarketContext())
            {
                var pageSizeConfig = context.Configurations.Find("ShopPageSize");

                return(pageSizeConfig != null?int.Parse(pageSizeConfig.Value) : 6);
            }
        }
        public void SaveProduct(Product product)
        {
            using (var context = new ClothMarketContext())
            {
                context.Entry(product.Category).State = System.Data.Entity.EntityState.Unchanged;

                context.Products.Add(product);
                context.SaveChanges();
            }
        }
        public void DeleteProduct(int ID)
        {
            using (var context = new ClothMarketContext())
            {
                var product = context.Products.Find(ID);

                context.Products.Remove(product);
                context.SaveChanges();
            }
        }
        public List <Product> GetProducts(int pageNo)
        {
            int pageSize = 5;// int.Parse(ConfigurationsService.Instance.GetConfig("ListingPageSize").Value);

            using (var context = new ClothMarketContext())
            {
                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();
            }
        }
Beispiel #22
0
        public void DeleteCategory(int ID)
        {
            using (var context = new ClothMarketContext())
            {
                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();
            }
        }
Beispiel #23
0
        public bool UpdateOrderStatus(int ID, string status)
        {
            using (var context = new ClothMarketContext())
            {
                var order = context.Orders.Find(ID);

                order.Status = status;

                context.Entry(order).State = EntityState.Modified;

                return(context.SaveChanges() > 0);
            }
        }
Beispiel #24
0
 public int GetCategoriesCount(string search)
 {
     using (var context = new ClothMarketContext())
     {
         if (!string.IsNullOrEmpty(search))
         {
             return(context.Categories.Where(category => category.Name != null &&
                                             category.Name.ToLower().Contains(search.ToLower())).Count());
         }
         else
         {
             return(context.Categories.Count());
         }
     }
 }
 public int GetProductsCount(string search)
 {
     using (var context = new ClothMarketContext())
     {
         if (!string.IsNullOrEmpty(search))
         {
             return(context.Products.Where(product => product.Name != null &&
                                           product.Name.ToLower().Contains(search.ToLower()))
                    .Count());
         }
         else
         {
             return(context.Products.Count());
         }
     }
 }
        public int SearchProductsCount(string searchTerm, int?minimumPrice, int?maximumPrice, int?categoryID, int?sortBy)
        {
            using (var context = new ClothMarketContext())
            {
                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);
            }
        }
Beispiel #27
0
        public List <Order> SearchOrders(string userID, string status, int pageNo, int pageSize)
        {
            using (var context = new ClothMarketContext())
            {
                var orders = context.Orders.ToList();

                if (!string.IsNullOrEmpty(userID))
                {
                    orders = orders.Where(x => x.UserID.ToLower().Contains(userID.ToLower())).ToList();
                }

                if (!string.IsNullOrEmpty(status))
                {
                    orders = orders.Where(x => x.Status.ToLower().Contains(status.ToLower())).ToList();
                }

                return(orders.Skip((pageNo - 1) * pageSize).Take(pageSize).ToList());
            }
        }
Beispiel #28
0
        public int SearchOrdersCount(string userID, string status)
        {
            using (var context = new ClothMarketContext())
            {
                var orders = context.Orders.ToList();

                if (!string.IsNullOrEmpty(userID))
                {
                    orders = orders.Where(x => x.UserID.ToLower().Contains(userID.ToLower())).ToList();
                }

                if (!string.IsNullOrEmpty(status))
                {
                    orders = orders.Where(x => x.Status.ToLower().Contains(status.ToLower())).ToList();
                }

                return(orders.Count);
            }
        }