コード例 #1
0
 public int GetProductCountPerCategory(int categoryId)
 {
     using (var context = new ECommerceDbDataContext(_conStr))
     {
         return context.Products.Where(p => p.CategoryId == categoryId).Count();
     }
 }
コード例 #2
0
 public IEnumerable<Category> GetCategories()
 {
     using (var context = new ECommerceDbDataContext(_conStr))
     {
         return context.Categories.ToList();
     }
 }
コード例 #3
0
 public void AddProduct(Product product)
 {
     using(var context = new ECommerceDbDataContext(_conStr))
     {
         context.Products.InsertOnSubmit(product);
         context.SubmitChanges();
     }
 }
コード例 #4
0
ファイル: ImageRepository.cs プロジェクト: yudamaan/Ecommerce
 public void AddImage(List<Image> images)
 {
     using(var context = new ECommerceDbDataContext(_conStr))
     {
         context.Images.InsertAllOnSubmit(images);
         context.SubmitChanges();
     }
 }
コード例 #5
0
 public void AddCategory(Category category)
 {
     using(var context = new ECommerceDbDataContext(_conStr))
     {
         context.Categories.InsertOnSubmit(category);
         context.SubmitChanges();
     }
 }
コード例 #6
0
ファイル: CartRepository.cs プロジェクト: yudamaan/Ecommerce
 public int GetCartCount(int cartId)
 {
     using (var context = new ECommerceDbDataContext(_conStr))
     {
         context.Log = new DebugTextWriter();
         return context.CartItems.Where(c => c.CartId == cartId).Sum(q => q.Quantity);
     }
 }
コード例 #7
0
ファイル: CartRepository.cs プロジェクト: yudamaan/Ecommerce
        public void DeleteItem(int itemId)
        {
            using (var context = new ECommerceDbDataContext(_conStr))
            {
                context.ExecuteCommand("DELETE FROM CartItems WHERE CartItemsId = {0}", itemId);

            }
        }
コード例 #8
0
 public Product GetProductWithImages(int productId)
 {
     using(var context = new ECommerceDbDataContext(_conStr))
     {
         var loadOptions = new DataLoadOptions();
         loadOptions.LoadWith<Product>(p => p.Images);
         context.LoadOptions = loadOptions;
         return context.Products.Where(p => p.ProductId == productId).FirstOrDefault();
     }
 }
コード例 #9
0
 public IEnumerable<Product> GetProductsWithImage(int categoryId, int page)
 {
     int skip = (page - 1) * 3;
     using(var context = new ECommerceDbDataContext(_conStr))
     {
         var loadOptions = new DataLoadOptions();
         loadOptions.LoadWith<Product>(p => p.Images);
         context.LoadOptions = loadOptions;
         return context.Products.Skip(skip).Take(3).Where(p => p.CategoryId == categoryId).ToList();
     }
 }
コード例 #10
0
ファイル: CartRepository.cs プロジェクト: yudamaan/Ecommerce
 public Cart CreateCart()
 {
     using(var context = new ECommerceDbDataContext(_conStr))
     {
         Cart cart = new Cart();
         cart.DateCreated = DateTime.Now;
         context.Carts.InsertOnSubmit(cart);
         context.SubmitChanges();
         return cart;
     }
 }
コード例 #11
0
ファイル: CartRepository.cs プロジェクト: yudamaan/Ecommerce
 public IEnumerable<CartItem> GetItemsInCart(int? cartId)
 {
     if (cartId == null)
     {
         return null;
     }
     using (var context = new ECommerceDbDataContext(_conStr))
     {
         var loadOptions = new DataLoadOptions();
         loadOptions.LoadWith<CartItem>(c => c.Product);
         context.LoadOptions = loadOptions;
         return context.CartItems.Where(c => c.CartId == cartId).ToList();
     }
 }
コード例 #12
0
ファイル: UserRepository.cs プロジェクト: yudamaan/Ecommerce
 public void AddUser(string username, string password)
 {
     string salt = PasswordHelper.GenerateRandomSalt();
     string hash = PasswordHelper.HashPassword(password, salt);
     User user = new User
     {
         UserName = username,
         PasswordSalt = salt,
         PasswordHash = hash,
     };
     using(var context = new ECommerceDbDataContext(_connectionString))
     {
         context.Users.InsertOnSubmit(user);
         context.SubmitChanges();
     }
 }
コード例 #13
0
ファイル: CartRepository.cs プロジェクト: yudamaan/Ecommerce
        public void AddToCart(CartItem items)
        {
            using (var context = new ECommerceDbDataContext(_conStr))
            {
                if(CheckIfItemIsAlreadyInCart(items))
                {
                    var updateItem = context.CartItems.Where(i => i.CartId == items.CartId && i.ProductId == items.ProductId).FirstOrDefault();
                    updateItem.Quantity += items.Quantity;
                }
                else
                {
                    context.CartItems.InsertOnSubmit(items);
                }

                context.SubmitChanges();
            }
        }
コード例 #14
0
ファイル: UserRepository.cs プロジェクト: yudamaan/Ecommerce
        public User Login(string username, string password)
        {
            using (var context = new ECommerceDbDataContext(_connectionString))
            {
                User user = context.Users.FirstOrDefault(u => u.UserName == username);
                if (user == null)
                {
                    return null;
                }

                if (!PasswordHelper.PasswordMatch(password, user.PasswordSalt, user.PasswordHash))
                {
                    return null;
                }

                return user;
            }
        }
コード例 #15
0
ファイル: CartRepository.cs プロジェクト: yudamaan/Ecommerce
 public void UpdateQuantity(int quantity, int itemId)
 {
     using (var context = new ECommerceDbDataContext(_conStr))
     {
         var updateItem = context.CartItems.Where(i => i.CartItemsId == itemId).FirstOrDefault();
         updateItem.Quantity = quantity;
         context.SubmitChanges();
     }
 }
コード例 #16
0
ファイル: CartRepository.cs プロジェクト: yudamaan/Ecommerce
 private bool CheckIfItemIsAlreadyInCart(CartItem items)
 {
     using (var context = new ECommerceDbDataContext(_conStr))
     {
         return context.CartItems.Any(c => c.CartId == items.CartId && c.ProductId == items.ProductId);
     }
 }