public void UpdateItem(string updateCartID, int updateProductID, int quantity) { using (var _db = new EComLivro.Models.LivroContext()) { try { var myItem = (from c in _db.ShoppingCartItems where c.cart_id == updateCartID && c.livro_id == updateProductID select c).FirstOrDefault(); if (myItem != null) { myItem.quantidade = quantity; _db.SaveChanges(); } } catch (Exception exp) { throw new Exception("ERROR: Unable to Update Cart Item - " + exp.Message.ToString(), exp); } } }
public void RemoveItem(string removeCartID, int removeProductID) { using (var _db = new EComLivro.Models.LivroContext()) { try { var myItem = (from c in _db.ShoppingCartItems where c.cart_id == removeCartID && c.livro_id == removeProductID select c).FirstOrDefault(); if (myItem != null) { // Remove Item. _db.ShoppingCartItems.Remove(myItem); _db.SaveChanges(); } } catch (Exception exp) { throw new Exception("ERROR: Incapaz de remover item do carrinho - " + exp.Message.ToString(), exp); } } }