コード例 #1
0
ファイル: ProductService.cs プロジェクト: muswilam/eCom
 //get products by pageNo and pageSize
 public List <Product> GetProducts(int pageNo, int pageSize)
 {
     using (var context = new eComContext())
     {
         return(context.Products.OrderByDescending(p => p.Id).Skip((pageNo - 1) * pageSize).Take(pageSize).Include(p => p.Category).ToList());
     }
 }
コード例 #2
0
ファイル: OrderService.cs プロジェクト: muswilam/eCom
        //get list of orders by status, pageNo
        public List <Order> GetOrders(string status, int pageNo, string date, int pageSize)
        {
            using (var context = new eComContext())
            {
                IQueryable <Order> orders = context.Orders;

                if (!string.IsNullOrEmpty(date)) //linq-to-entities can't recognize convert datetime to satring then compare, so made this functioanlty.
                {
                    var ordersList = new List <Order>();
                    foreach (var order in orders)
                    {
                        if (order.OrderedAt.ToString("y") == date)
                        {
                            ordersList.Add(order);
                        }
                    }

                    orders = ordersList.AsQueryable();
                }

                if (!string.IsNullOrEmpty(status))
                {
                    orders = orders.Where(o => o.Status == status);
                }

                if (string.IsNullOrEmpty(status) && string.IsNullOrEmpty(date))
                {
                    orders = orders.Where(o => o.Status == "Pending");
                }

                return(orders.OrderBy(o => o.Id).Skip((pageNo - 1) * pageSize).Take(pageSize).ToList());
            }
        }
コード例 #3
0
 //get list of featured categoriess
 public List <Category> GetFeaturedCategories()
 {
     using (var context = new eComContext())
     {
         return(context.Categories.Where(c => c.IsFeatured && c.ImageUrl != null).ToList());
     }
 }
コード例 #4
0
ファイル: OrderService.cs プロジェクト: muswilam/eCom
 //get list of orders by userID
 public List <Order> GetOrdersByUserId(string userId, int pageNo, int pageSize)
 {
     using (var context = new eComContext())
     {
         return(context.Orders.Where(o => o.UserId == userId).OrderByDescending(o => o.Id).Skip((pageNo - 1) * pageSize).Take(pageSize).ToList());
     }
 }
コード例 #5
0
 //get categories that have products
 public List <Category> GetFilledCategories()
 {
     using (var context = new eComContext())
     {
         return(context.Categories.Include(c => c.Products).Where(c => c.Products.Count() > 0).ToList());
     }
 }
コード例 #6
0
 //get category by id
 public Category GetCategory(int id)
 {
     using (var context = new eComContext())
     {
         return(context.Categories.Where(c => c.Id == id).FirstOrDefault());
     }
 }
コード例 #7
0
ファイル: WishlistService.cs プロジェクト: muswilam/eCom
 //get wishlist by userId
 public Wishlist GetWishlist(string userId)
 {
     using (eComContext context = new eComContext())
     {
         return(context.Wishlists.Where(w => w.UserId == userId).Include(w => w.WishlistItems).Include("WishlistItems.Product").FirstOrDefault());
     }
 }
コード例 #8
0
ファイル: ProductService.cs プロジェクト: muswilam/eCom
 //get products by list of ids
 public List <Product> GetProducts(List <int> ids)
 {
     using (var context = new eComContext())
     {
         return(context.Products.Where(p => ids.Contains(p.Id)).ToList());
     }
 }
コード例 #9
0
ファイル: OrderService.cs プロジェクト: muswilam/eCom
 //get count of list of orders by userId
 public int GetOrdersCountByUserId(string userId)
 {
     using (var context = new eComContext())
     {
         return(context.Orders.Where(o => o.UserId == userId).Count());
     }
 }
コード例 #10
0
ファイル: OrderService.cs プロジェクト: muswilam/eCom
        //get count of list of orders
        public int GetOrdersCount(string status, string date)
        {
            using (var context = new eComContext())
            {
                var orders = context.Orders.AsQueryable();

                if (!string.IsNullOrEmpty(date))
                {
                    var ordersList = new List <Order>();
                    foreach (var order in orders)
                    {
                        if (order.OrderedAt.ToString("y") == date)
                        {
                            ordersList.Add(order);
                        }
                    }

                    orders = ordersList.AsQueryable();
                }

                if (!string.IsNullOrEmpty(status))
                {
                    orders = orders.Where(o => o.Status == status);
                }

                if (string.IsNullOrEmpty(status) && string.IsNullOrEmpty(date))
                {
                    orders = orders.Where(o => o.Status == "Pending");
                }

                return(orders.Count());
            }
        }
コード例 #11
0
ファイル: ProductService.cs プロジェクト: muswilam/eCom
 //get product by id
 public Product GetProduct(int id)
 {
     using (var context = new eComContext())
     {
         return(context.Products.Where(c => c.Id == id).Include(p => p.Category).Include(p => p.Reviews).FirstOrDefault());
     }
 }
コード例 #12
0
ファイル: ConfigurationService.cs プロジェクト: muswilam/eCom
 public Config GetConfig(string key)
 {
     using (var context = new eComContext())
     {
         return(context.Configurations.Find(key));
     }
 }
コード例 #13
0
ファイル: ProductService.cs プロジェクト: muswilam/eCom
 //get latest products
 public List <Product> GetLatestProducts(int numberOfProducts)
 {
     using (var context = new eComContext())
     {
         return(context.Products.OrderByDescending(p => p.Id).Take(numberOfProducts).Include(p => p.Category).Include(p => p.Reviews).ToList());
     }
 }
コード例 #14
0
ファイル: ReviewService.cs プロジェクト: muswilam/eCom
 //get reviews by productId
 public List <Review> GetReviews(int productId)
 {
     using (var context = new eComContext())
     {
         return(context.Reviews.Where(r => r.ProductId == productId).ToList());
     }
 }
コード例 #15
0
 //get all categoies
 public List <Category> GetCategories()
 {
     using (var context = new eComContext())
     {
         return(context.Categories.Include(c => c.Products).ToList());
     }
 }
コード例 #16
0
ファイル: WishlistService.cs プロジェクト: muswilam/eCom
 //is there a wishlist by userId
 public bool IsExistWishlist(string userId)
 {
     using (eComContext context = new eComContext())
     {
         var existing = context.Wishlists.Where(w => w.UserId == userId).Include(w => w.WishlistItems).FirstOrDefault();
         return(existing != null);
     }
 }
コード例 #17
0
 //edit category
 public void UpdateCategory(Category category)
 {
     using (var context = new eComContext())
     {
         context.Entry(category).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
コード例 #18
0
ファイル: ProductService.cs プロジェクト: muswilam/eCom
 //edit product
 public void UpdateProduct(Product product)
 {
     using (var context = new eComContext())
     {
         context.Entry(product).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
コード例 #19
0
 //create category
 public void SaveCategory(Category category)
 {
     using (var context = new eComContext())
     {
         context.Categories.Add(category);
         context.SaveChanges();
     }
 }
コード例 #20
0
ファイル: WishlistService.cs プロジェクト: muswilam/eCom
 //is there a product
 public bool IsExistProduct(int productId, Wishlist existWishlist)
 {
     using (eComContext context = new eComContext())
     {
         bool wishlist = existWishlist.WishlistItems.Exists(w => w.ProductId == productId);
         return(wishlist);
     }
 }
コード例 #21
0
ファイル: WishlistService.cs プロジェクト: muswilam/eCom
 //create wishlist
 public bool SaveWishlist(Wishlist wishlist)
 {
     using (eComContext context = new eComContext())
     {
         context.Wishlists.Add(wishlist);
         return(context.SaveChanges() > 0);
     }
 }
コード例 #22
0
ファイル: OrderService.cs プロジェクト: muswilam/eCom
 //create order with creating list of orderItems { orderId , productId }
 public int SaveOrder(Order order)
 {
     using (var context = new eComContext())
     {
         context.Orders.Add(order);
         return(context.SaveChanges());
     }
 }
コード例 #23
0
ファイル: ConfigurationService.cs プロジェクト: muswilam/eCom
 //edit config value
 public bool EditConfig(Config config)
 {
     using (var context = new eComContext())
     {
         context.Entry(config).State = EntityState.Modified;
         return(context.SaveChanges() > 0);
     }
 }
コード例 #24
0
ファイル: ConfigurationService.cs プロジェクト: muswilam/eCom
        public int ShopPageSize()
        {
            using (var context = new eComContext())
            {
                var pageSizeConfig = context.Configurations.Find("ShopPageSize");

                return(pageSizeConfig.Value != string.Empty ? int.Parse(pageSizeConfig.Value) : 12);
            }
        }
コード例 #25
0
ファイル: ReviewService.cs プロジェクト: muswilam/eCom
        //create a new review
        public bool SaveReview(Review newReview)
        {
            using (var context = new eComContext())
            {
                context.Reviews.Add(newReview);

                return(context.SaveChanges() > 0);
            }
        }
コード例 #26
0
ファイル: ProductService.cs プロジェクト: muswilam/eCom
        //add product
        public void SaveProduct(Product product)
        {
            using (var context = new eComContext())
            {
                context.Entry(product.Category).State = EntityState.Unchanged; //prevent adding category again with different id

                context.Products.Add(product);
                context.SaveChanges();
            }
        }
コード例 #27
0
ファイル: ProductService.cs プロジェクト: muswilam/eCom
        //delete product
        public void DeleteProduct(int id)
        {
            using (var context = new eComContext())
            {
                var product = context.Products.Find(id);

                context.Products.Remove(product);
                context.SaveChanges();
            }
        }
コード例 #28
0
        //delete category
        public void DeleteCategory(int id)
        {
            using (var context = new eComContext())
            {
                var category = context.Categories.Find(id);

                context.Categories.Remove(category);
                context.SaveChanges();
            }
        }
コード例 #29
0
ファイル: OrderService.cs プロジェクト: muswilam/eCom
 //get order by id
 public Order GetOrder(int id)
 {
     using (var context = new eComContext())
     {
         return(context.Orders
                .Where(o => o.Id == id).Include(o => o.OrderItems)
                .Include("OrderItems.Product")
                .FirstOrDefault());
     }
 }
コード例 #30
0
ファイル: ReviewService.cs プロジェクト: muswilam/eCom
        //delete review
        public void RemoveReview(int id)
        {
            using (var context = new eComContext())
            {
                var review = context.Reviews.Where(r => r.Id == id).First();

                context.Reviews.Remove(review);
                context.SaveChanges();
            }
        }