Beispiel #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;
         }
     }
 }
 public void AddProductDiscount(Discount discount)
 {
     using (AirShoppContext _context = new AirShoppContext())
     {
         _context.Discount.Add(discount);
         _context.SaveChanges();
     }
 }
Beispiel #3
0
 public void AddCartItem(CartItem cartItem)
 {
     using (AirShoppContext _context = new AirShoppContext())
     {
         _context.CartItem.Add(cartItem);
         _context.SaveChanges();
     }
 }
Beispiel #4
0
 public void AddInventoryAction(InventoryAction inventoryAction)
 {
     using (AirShoppContext _context = new AirShoppContext())
     {
         _context.InventoryAction.Add(inventoryAction);
         _context.SaveChanges();
     }
 }
Beispiel #5
0
 public long AddProductInFactory(ProductInFactory productInFactory)
 {
     using (AirShoppContext _context = new AirShoppContext())
     {
         _context.ProductInFactory.Add(productInFactory);
         _context.SaveChanges();
         return(productInFactory.Id);
     }
 }
Beispiel #6
0
 public long AddInventory(Inventory inventory)
 {
     using (AirShoppContext _context = new AirShoppContext())
     {
         _context.Inventory.Add(inventory);
         _context.SaveChanges();
         return(inventory.Id);
     }
 }
Beispiel #7
0
 public long AddProduct(Product product)
 {
     using (AirShoppContext _context = new AirShoppContext())
     {
         _context.Product.Add(product);
         _context.SaveChanges();
         return(product.Id);
     }
 }
Beispiel #8
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();
     }
 }
Beispiel #9
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;
                }
            }
        }
Beispiel #10
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();
         }
     }
 }
Beispiel #11
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();
         }
     }
 }
Beispiel #12
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);
     }
 }
Beispiel #13
0
 public void AddDeliveryOrderItem(DeliveryOrderItem deliveryOrderItem)
 {
     _context.DeliveryOrderItem.Add(deliveryOrderItem);
     _context.SaveChanges();
 }
Beispiel #14
0
 public void AddDeliveryNote(DeliveryNote deliveryNote)
 {
     _context.DeliveryNote.Add(deliveryNote);
     _context.SaveChanges();
 }
Beispiel #15
0
 public void AddAddress(Address address)
 {
     _context.Address.Add(address);
     _context.SaveChanges();
 }
Beispiel #16
0
 public void AddCourier(Courier courier)
 {
     _context.Courier.Add(courier);
     _context.SaveChanges();
 }
Beispiel #17
0
 public void AddCustomer(Customer customer)
 {
     _context.Customer.Add(customer);
     _context.SaveChanges();
 }
Beispiel #18
0
 public long AddDeliveryOrder(DeliveryOrder deliveryOrder)
 {
     _context.DeliveryOrder.Add(deliveryOrder);
     _context.SaveChanges();
     return(deliveryOrder.Id);
 }
 public void AddDeliverInfo(DeliveryInfo deliveryInfo)
 {
     _context.DeliveryInfo.Add(deliveryInfo);
     _context.SaveChanges();
 }
Beispiel #20
0
 public void AddComment(Comment comment)
 {
     _context.Comments.Add(comment);
     _context.SaveChanges();
 }
Beispiel #21
0
 public Order AddOrder(Order order)
 {
     order = _context.Order.Add(order);
     _context.SaveChanges();
     return(order);
 }
 public void AddDeliveryStation(DeliveryStation deliveryStation)
 {
     _context.DeliveryStation.Add(deliveryStation);
     _context.SaveChanges();
 }