Exemplo n.º 1
0
 public void UpdateShoppingCartDatabase(String cartId, ShoppingCartUpdates[] CartItemUpdates)
 {
     using (var db = new ProjektRWA.Models.ArtikalContext())
     {
         try
         {
             int             CartItemCount = CartItemUpdates.Count();
             List <CartItem> myCart        = GetCartItems();
             foreach (var cartItem in myCart)
             {
                 for (int i = 0; i < CartItemCount; i++)
                 {
                     if (cartItem.Product.ArtikalID == CartItemUpdates[i].ProductId)
                     {
                         if (CartItemUpdates[i].PurchaseQuantity < 1 || CartItemUpdates[i].RemoveItem == true)
                         {
                             RemoveItem(cartId, cartItem.ProductId);
                         }
                         else
                         {
                             UpdateItem(cartId, cartItem.ProductId, CartItemUpdates[i].PurchaseQuantity);
                         }
                     }
                 }
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Update Cart Database - " + exp.Message.ToString(), exp);
         }
     }
 }
Exemplo n.º 2
0
        public IQueryable <Kategorija> GetKategorije()
        {
            var _db = new ProjektRWA.Models.ArtikalContext();
            IQueryable <Kategorija> query = _db.Kategorije;

            return(query);
        }
Exemplo n.º 3
0
        public IQueryable <Artikal> GetArtikli([QueryString("id")] int?kategorijaID)
        {
            var _db = new ProjektRWA.Models.ArtikalContext();
            IQueryable <Artikal> query = _db.Artikli;

            if (kategorijaID.HasValue && kategorijaID > 0)
            {
                query = query.Where(p => p.KategorijaID == kategorijaID);
            }

            return(query);
        }
Exemplo n.º 4
0
        public IQueryable <Artikal> GetArtikal([QueryString("productID")] int?artikalID)
        {
            var _db = new ProjektRWA.Models.ArtikalContext();
            IQueryable <Artikal> query = _db.Artikli;

            if (artikalID.HasValue && artikalID > 0)
            {
                query = query.Where(p => p.ArtikalID == artikalID);
            }
            else
            {
                query = null;
            }

            return(query);
        }
Exemplo n.º 5
0
 public void UpdateItem(string updateCartID, int updateProductID, int quantity)
 {
     using (var _db = new ProjektRWA.Models.ArtikalContext())
     {
         try
         {
             var myItem = (from c in _db.ShoppingCartItems where c.CartId == updateCartID && c.Product.ArtikalID == updateProductID select c).FirstOrDefault();
             if (myItem != null)
             {
                 myItem.Quantity = quantity;
                 _db.SaveChanges();
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Update Cart Item - " + exp.Message.ToString(), exp);
         }
     }
 }
Exemplo n.º 6
0
 public void RemoveItem(string removeCartID, int removeProductID)
 {
     using (var _db = new ProjektRWA.Models.ArtikalContext())
     {
         try
         {
             var myItem = (from c in _db.ShoppingCartItems where c.CartId == removeCartID && c.Product.ArtikalID == removeProductID select c).FirstOrDefault();
             if (myItem != null)
             {
                 _db.ShoppingCartItems.Remove(myItem);
                 _db.SaveChanges();
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Remove Cart Item - " + exp.Message.ToString(), exp);
         }
     }
 }