Beispiel #1
0
 public IEnumerable <Category> GetAllCategories()
 {
     using (var dc = new EcommerceDataContext(_connectionString))
     {
         return(dc.Categories.ToList());
     }
 }
Beispiel #2
0
 public IEnumerable <Image> GetAllImagesByProduct(int productId)
 {
     using (var dc = new EcommerceDataContext(_connectionString))
     {
         return(dc.Images.Where(i => i.ProductId == productId).ToList());
     }
 }
Beispiel #3
0
 public IEnumerable <Image> GetAllImages()
 {
     using (var dc = new EcommerceDataContext(_connectionString))
     {
         return(dc.Images.ToList());
     }
 }
Beispiel #4
0
 public Image GetFirstImageByProduct(int productId)
 {
     using (var dc = new EcommerceDataContext(_connectionString))
     {
         return(dc.Images.Where(i => i.ProductId == productId).FirstOrDefault());
     }
 }
Beispiel #5
0
 public void AddImages(IEnumerable <Image> images)
 {
     using (var dc = new EcommerceDataContext(_connectionString))
     {
         dc.Images.InsertAllOnSubmit(images);
         dc.SubmitChanges();
     }
 }
Beispiel #6
0
 public void AddProduct(Product product)
 {
     using (var dc = new EcommerceDataContext(_connectionString))
     {
         dc.Products.InsertOnSubmit(product);
         dc.SubmitChanges();
     }
 }
Beispiel #7
0
 public void AddCategory(Category category)
 {
     using (var dc = new EcommerceDataContext(_connectionString))
     {
         dc.Categories.InsertOnSubmit(category);
         dc.SubmitChanges();
     }
 }
 public void AddCartItems(CartItem c)
 {
     using (var dc = new EcommerceDataContext(_connectionString))
     {
         dc.CartItems.InsertOnSubmit(c);
         dc.SubmitChanges();
     }
 }
 public void AddNewShopCart(ShoppingCart s)
 {
     using (var dc = new EcommerceDataContext(_connectionString))
     {
         dc.ShoppingCarts.InsertOnSubmit(s);
         dc.SubmitChanges();
     }
 }
Beispiel #10
0
 public IEnumerable <Product> GetProductsByCategory(int?categoryId)
 {
     using (var dc = new EcommerceDataContext(_connectionString))
     {
         var loadOptions = new System.Data.Linq.DataLoadOptions();
         loadOptions.LoadWith <Product>(p => p.Images);
         dc.LoadOptions = loadOptions;
         return(dc.Products.Where(p => p.Categoryid == categoryId).ToList());
     }
 }
Beispiel #11
0
 public Product GetProduct(int id)
 {
     using (var dc = new EcommerceDataContext(_connectionString))
     {
         var loadOptions = new System.Data.Linq.DataLoadOptions();
         loadOptions.LoadWith <Product>(p => p.Images);
         loadOptions.LoadWith <Product>(p => p.Category);
         dc.LoadOptions = loadOptions;
         return(dc.Products.First(p => p.Id == id));
     }
 }
 public int GetTotalQuantityByShoppingCartId(int id)
 {
     using (var dc = new EcommerceDataContext(_connectionString))
     {
         DataLoadOptions options = new System.Data.Linq.DataLoadOptions();
         options.LoadWith <CartItem>(cartItem => cartItem.Product);
         options.LoadWith <Product>(product => product.Images);
         dc.LoadOptions = options;
         return(dc.CartItems.AsEnumerable().Where(c => c.ShoppingCartId == id).Sum(c => c.Quantity));////
     }
 }
 ///needs more work - done;
 public List <CartItem> GetCartItemsByShoppingCartId(int id)
 {
     using (var dc = new EcommerceDataContext(_connectionString))
     {
         DataLoadOptions options = new System.Data.Linq.DataLoadOptions();
         options.LoadWith <CartItem>(cartItem => cartItem.Product);
         options.LoadWith <Product>(product => product.Images);
         dc.LoadOptions = options;
         return(dc.CartItems.Where(c => c.ShoppingCartId == id).ToList());
     }
 }