Beispiel #1
0
 public void AddImage(List<Image> images)
 {
     using(var context = new ECommerceDbDataContext(_conStr))
     {
         context.Images.InsertAllOnSubmit(images);
         context.SubmitChanges();
     }
 }
 public void AddProduct(Product product)
 {
     using(var context = new ECommerceDbDataContext(_conStr))
     {
         context.Products.InsertOnSubmit(product);
         context.SubmitChanges();
     }
 }
 public void AddCategory(Category category)
 {
     using(var context = new ECommerceDbDataContext(_conStr))
     {
         context.Categories.InsertOnSubmit(category);
         context.SubmitChanges();
     }
 }
Beispiel #4
0
 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;
     }
 }
Beispiel #5
0
 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();
     }
 }
Beispiel #6
0
        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();
            }
        }
Beispiel #7
0
 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();
     }
 }