コード例 #1
0
 public void UpdateItem(string updateCartID, int updateBookID, int
                        quantity)
 {
     using (var _db = new BookShopOnline.Models.BookContext())
     {
         try
         {
             var myItem = (from c in _db.ShoppingCartItems
                           where c.CartId == updateCartID && c.Book.MaSach ==
                           updateBookID
                           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);
         }
     }
 }
コード例 #2
0
 public void RemoveItem(string removeCartID, int removeBookID)
 {
     using (var _db = new BookShopOnline.Models.BookContext())
     {
         try
         {
             var myItem = (from c in _db.ShoppingCartItems
                           where c.CartId == removeCartID && c.Book.MaSach ==
                           removeBookID
                           select c).FirstOrDefault();
             if (myItem != null)
             {
                 // Xóa
                 _db.ShoppingCartItems.Remove(myItem);
                 _db.SaveChanges();
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Remove Cart Item - " +
                                 exp.Message.ToString(), exp);
         }
     }
 }