Example #1
0
 public void UpdateProductInfo(long productId, string productName, string productUrl, bool isOnSale, decimal price)
 {
     using (AirShoppContext _context = new AirShoppContext())
     {
         try
         {
             var product = _context.Product.Where(p => p.Id == productId).FirstOrDefault();
             if (product != null)
             {
                 product.ProductName = productName;
                 if (productUrl != null)
                 {
                     product.Url = productUrl;
                 }
                 product.IsOnSale = isOnSale;
                 product.Price    = price;
                 _context.Entry(product).State = System.Data.Entity.EntityState.Modified;
                 _context.SaveChanges();
             }
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
Example #2
0
        public List <Product> Products()
        {
            string path     = HttpRuntime.AppDomainAppPath.ToString() + "\\Content\\Images\\HomePage\\p1.jpg";
            string imgPath  = path.Substring(path.IndexOf("\\Content"));
            string RealPath = imgPath.Replace("\\", "/");


            using (AirShoppContext _context = new AirShoppContext())
            {
                List <Product> products = new List <Product>();
                _context.Product.OrderBy(x => Guid.NewGuid()).Take(10).ToList().ForEach(product =>
                {
                    products.Add(new Product()
                    {
                        Id             = product.Id,
                        Price          = product.Price,
                        KeepDate       = product.KeepDate,
                        ProductionDate = product.ProductionDate,
                        ProductName    = product.ProductName,
                        Description    = product.Description,
                        Url            = RealPath
                    });
                });
                return(products);
            }
        }
Example #3
0
 public void AddProductDiscount(Discount discount)
 {
     using (AirShoppContext _context = new AirShoppContext())
     {
         _context.Discount.Add(discount);
         _context.SaveChanges();
     }
 }
Example #4
0
 public int GetProductAmountByProductId(long productId)
 {
     using (AirShoppContext _context = new AirShoppContext())
     {
         var inventory = _context.Inventory.Where(I => I.ProductId == productId).FirstOrDefault();
         return(inventory.Amount);
     }
 }
Example #5
0
 public void AddInventoryAction(InventoryAction inventoryAction)
 {
     using (AirShoppContext _context = new AirShoppContext())
     {
         _context.InventoryAction.Add(inventoryAction);
         _context.SaveChanges();
     }
 }
Example #6
0
 public void AddCartItem(CartItem cartItem)
 {
     using (AirShoppContext _context = new AirShoppContext())
     {
         _context.CartItem.Add(cartItem);
         _context.SaveChanges();
     }
 }
Example #7
0
        public void DeleteProduct(long productId)
        {
            using (AirShoppContext _context = new AirShoppContext())
            {
                try
                {
                    var productSales = _context.ProductSales.Where(ps => ps.ProductId == productId).FirstOrDefault();
                    if (productSales != null)
                    {
                        _context.ProductSales.Remove(productSales);
                        _context.SaveChanges();
                    }

                    var inventory       = _context.Inventory.Where(i => i.ProductId == productId).FirstOrDefault();
                    var inventoryAction = _context.InventoryAction.Where(ia => ia.InventoryId == inventory.Id).FirstOrDefault();
                    if (inventory != null)
                    {
                        if (inventoryAction != null)
                        {
                            _context.InventoryAction.Remove(inventoryAction);
                            _context.SaveChanges();
                        }
                        _context.Inventory.Remove(inventory);
                        _context.SaveChanges();
                    }
                    var orderItem = _context.OrderItem.Where(oi => oi.ProductId == productId).FirstOrDefault();
                    if (orderItem != null)
                    {
                        _context.OrderItem.Remove(orderItem);
                        _context.SaveChanges();
                    }
                    var discount = _context.Discount.Where(d => d.ProductId == productId).FirstOrDefault();
                    if (discount != null)
                    {
                        _context.Discount.Remove(discount);
                        _context.SaveChanges();
                    }
                    var comment = _context.Comments.Where(c => c.ProductId == productId).FirstOrDefault();
                    if (comment != null)
                    {
                        _context.Comments.Remove(comment);
                        _context.SaveChanges();
                    }
                    var cartItem = _context.CartItem.Where(ci => ci.ProductId == productId).FirstOrDefault();

                    var product = _context.Product.Where(p => p.Id == productId).FirstOrDefault();
                    if (product != null)
                    {
                        _context.Product.Remove(product);
                        _context.SaveChanges();
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Example #8
0
 public Product GetProductById(long productId)
 {
     using (AirShoppContext _context = new AirShoppContext())
     {
         Product product = null;
         product = _context.Product.FirstOrDefault(x => x.Id == productId);
         return(product);
     }
 }
Example #9
0
 public long AddProduct(Product product)
 {
     using (AirShoppContext _context = new AirShoppContext())
     {
         _context.Product.Add(product);
         _context.SaveChanges();
         return(product.Id);
     }
 }
Example #10
0
 public long AddInventory(Inventory inventory)
 {
     using (AirShoppContext _context = new AirShoppContext())
     {
         _context.Inventory.Add(inventory);
         _context.SaveChanges();
         return(inventory.Id);
     }
 }
Example #11
0
 public long AddProductInFactory(ProductInFactory productInFactory)
 {
     using (AirShoppContext _context = new AirShoppContext())
     {
         _context.ProductInFactory.Add(productInFactory);
         _context.SaveChanges();
         return(productInFactory.Id);
     }
 }
Example #12
0
 public void UpdateCartItem(long cartItemId)
 {
     using (AirShoppContext _context = new AirShoppContext())
     {
         CartItem cartItem = _context.CartItem.Find(cartItemId);
         cartItem.ItemStatus = Constants.BOUGHT;
         _context.Entry <CartItem>(cartItem).State = EntityState.Modified;
         _context.SaveChanges();
     }
 }
Example #13
0
 public void DeleteCartProduct(long cartItemId)
 {
     using (AirShoppContext _context = new AirShoppContext())
     {
         var cartItem = _context.CartItem.Find(cartItemId);
         if (cartItem != null)
         {
             _context.CartItem.Remove(cartItem);
             _context.SaveChanges();
         }
     }
 }
Example #14
0
 public void UpdateProductDiscount(long productId, decimal discounts)
 {
     using (AirShoppContext _context = new AirShoppContext())
     {
         var d = _context.Discount.Where(dt => dt.ProductId == productId).FirstOrDefault();
         if (d != null)
         {
             d.Discounts             = discounts;
             _context.Entry(d).State = System.Data.Entity.EntityState.Modified;
             _context.SaveChanges();
         }
     }
 }
Example #15
0
 public List <Category> GetCategories()
 {
     using (AirShoppContext _context = new AirShoppContext())
     {
         List <Category> CategoryList = new List <Category>();
         _context.Category.Where(e => e.ParentId == 0).ToList().ForEach(category =>
         {
             CategoryList.Add(new Category
             {
                 Id           = category.Id,
                 CategoryName = category.CategoryName
             });
         });
         return(CategoryList);
     }
 }
Example #16
0
 public string GetCategoryNameByProductId(long productId)
 {
     using (AirShoppContext _context = new AirShoppContext())
     {
         try
         {
             var product  = _context.Product.Where(p => p.Id == productId).FirstOrDefault();
             var category = _context.Category.Where(c => c.Id == product.CategoryId).FirstOrDefault();
             return(category.CategoryName);
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
Example #17
0
 public string GetCategoryNameByChildcategoryId(long childCategoryid)
 {
     using (AirShoppContext _context = new AirShoppContext())
     {
         Category category     = null;
         string   categoryName = null;
         long     parentId     = 0;
         _context.Category.Where(e => e.Id == childCategoryid).ToList().ForEach(c =>
         {
             category = new Category()
             {
                 Id       = c.Id,
                 ParentId = c.ParentId
             };
         });
         _context.Category.Where(e => e.Id == parentId).ToList().ForEach(c =>
         {
             categoryName = c.CategoryName;
         });
         return(categoryName);
     }
 }
Example #18
0
 public long AddCart(Cart cart)
 {
     using (AirShoppContext _context = new AirShoppContext())
     {
         long cartId          = 0;
         bool isExistCustomer = false;
         foreach (var c in _context.Cart.ToList())
         {
             if (c.CustomerId == cart.CustomerId)
             {
                 cartId          = c.Id;
                 isExistCustomer = true;
                 break;
             }
         }
         if (isExistCustomer == false)
         {
             _context.Cart.Add(cart);
             _context.SaveChanges();
             cartId = cart.Id;
         }
         return(cartId);
     }
 }