Esempio n. 1
0
 public void UpdateShoppingCartDatabase(String cartId, ShoppingCartUpdates[] CartItemUpdates)
 {
     using (var db = new CatalogiaWebForms.Models.CatalogObjectContext())
     {
         try
         {
             int             CartItemCount = CartItemUpdates.Count();
             List <CartItem> myCart        = GetCartItems();
             foreach (var cartItem in myCart)
             {
                 // Iterate through all rows within shopping cart list
                 for (int i = 0; i < CartItemCount; i++)
                 {
                     if (cartItem.CatalogObject.ObjectId == CartItemUpdates[i].ObjectId)
                     {
                         if (CartItemUpdates[i].PurchaseQuantity < 1 || CartItemUpdates[i].RemoveItem == true)
                         {
                             RemoveItem(cartId, cartItem.CatalogObject.ObjectId);
                         }
                         else
                         {
                             UpdateItem(cartId, cartItem.CatalogObject.ObjectId, CartItemUpdates[i].PurchaseQuantity);
                         }
                     }
                 }
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Update Cart Database - " + exp.Message.ToString(), exp);
         }
     }
 }
Esempio n. 2
0
        public IQueryable <CatalogObject> GetCatalogItems([QueryString("id")] int?categoryId, [RouteData] string categoryName)
        {
            var _db = new CatalogiaWebForms.Models.CatalogObjectContext();

            IQueryable <CatalogiaWebForms.Models.CatalogObject> query = _db.CatalogObjects;

            if (categoryId.HasValue && categoryId > 0)
            {
                query = query.Where(p => p.CategoryID == categoryId);
            }

            if (!String.IsNullOrEmpty(categoryName))
            {
                int?categoryIdToFind = null;
                // Need to get CategoryId from CatalogObjectCategory
                CatalogObjectCategory extractedCategory = _db.CatalogObjectCategories.Where(x => x.CategoryName == categoryName).FirstOrDefault();

                if (extractedCategory != null)
                {
                    categoryIdToFind = extractedCategory.CategoryID;
                    query            = query.Where(p => p.CategoryID == categoryIdToFind);
                }
            }

            return(query);
        }
Esempio n. 3
0
        public IQueryable GetCatalogObjects()
        {
            var        _db   = new CatalogiaWebForms.Models.CatalogObjectContext();
            IQueryable query = _db.CatalogObjects;

            return(query);
        }
Esempio n. 4
0
        public IQueryable <CatalogObjectCategory> GetAllCategories()
        {
            var _db = new CatalogiaWebForms.Models.CatalogObjectContext();
            IQueryable <CatalogObjectCategory> q = _db.CatalogObjectCategories;

            return(q);
        }
Esempio n. 5
0
        public IQueryable GetCategories()
        {
            var        _db   = new CatalogiaWebForms.Models.CatalogObjectContext();
            IQueryable query = _db.CatalogObjectCategories;

            List <CatalogObjectCategory> cList = new ObservableCollection <Models.CatalogObjectCategory>((IQueryable <CatalogObjectCategory>)query).ToList();

            return(query);
        }
        // The id parameter should match the DataKeyNames value set on the control
        // or be decorated with a value provider attribute, e.g. [QueryString]int id
        public IQueryable <CatalogObject> GetCatalogObjectDetails([QueryString("ObjectId")] string id)
        {
            var _db = new CatalogiaWebForms.Models.CatalogObjectContext();
            IQueryable <CatalogObject> query = _db.CatalogObjects;

            if (!string.IsNullOrEmpty(id))
            {
                query = query.Where(q => q.ObjectId == id);
            }
            else
            {
                query = null;
            }

            return(query);
        }
Esempio n. 7
0
 public void UpdateItem(string updateCartID, string updateObjectId, int quantity)
 {
     using (var _db = new CatalogiaWebForms.Models.CatalogObjectContext())
     {
         try
         {
             var myItem = (from c in _db.ShoppingCartItems where c.CartId == updateCartID && c.CatalogObject.ObjectId == updateObjectId 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);
         }
     }
 }
Esempio n. 8
0
 public void RemoveItem(string removeCartID, string objectIdToRemove)
 {
     using (var _db = new CatalogiaWebForms.Models.CatalogObjectContext())
     {
         try
         {
             var myItem = (from c in _db.ShoppingCartItems where c.CartId == removeCartID && c.CatalogObject.ObjectId == objectIdToRemove 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);
         }
     }
 }
Esempio n. 9
0
        protected void btnRemoveCatalogItem_Click(object sender, EventArgs e)
        {
            using (var _db = new CatalogiaWebForms.Models.CatalogObjectContext())
            {
                string objectId = ddlRemoveCatalogObject.SelectedValue;
                var    myItem   = (from c in _db.CatalogObjects where c.ObjectId == objectId select c).FirstOrDefault();
                if (myItem != null)
                {
                    _db.CatalogObjects.Remove(myItem);
                    _db.SaveChanges();

                    // Reload the page.
                    string pageUrl = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.Count() - Request.Url.Query.Count());
                    Response.Redirect(pageUrl + "?CatalogObjectAction=remove");
                }
                else
                {
                    LabelRemoveStatus.Text = "Unable to locate catalog item.";
                }
            }
        }