public IQueryable <Category> GetCategories() { var _db = new Models.ProductContext(); IQueryable <Category> query = _db.Categories; return(query); }
public void UpdateShoppingCartDatabase(String cartId, List <ShoppingCartUpdates> cartUpdates) { using (var db = new Kidsmeer.Models.ProductContext()) { try { List <CartItem> myCart = GetCartItems(); foreach (var cartUpdateItem in cartUpdates) { var currentCartItem = myCart.SingleOrDefault(ci => ci.ProductId == cartUpdateItem.ProductId); if (currentCartItem != null) { if (cartUpdateItem.PurchaseQuantity < 1 || cartUpdateItem.RemoveItem) { RemoveItem(currentCartItem.CartId, currentCartItem.ProductId); } else { UpdateItem(cartId, currentCartItem.ProductId, cartUpdateItem.PurchaseQuantity); } } } } catch (Exception exp) { throw new Exception("ERROR: Unable to Update Cart Database - " + exp.Message.ToString(), exp); } } }
public void RemoveItem(string removeCartID, int removeProductID) { using (var _db = new Kidsmeer.Models.ProductContext()) { try { var myItem = (from c in _db.ShoppingCartItems where c.CartId == removeCartID && c.ProductId == 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); } } }
public void UpdateItem(string updateCartID, int updateProductID, int quantity) { using (var _db = new Kidsmeer.Models.ProductContext()) { try { var myItem = (from c in _db.ShoppingCartItems where c.CartId == updateCartID && c.ProductId == 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); } } }