public void UpdateItem(int OrderID, int updateProductID, int qtyShipped, int qtyCancelled, string comment) { using (var _db = new FrontierAg.Models.ProductContext()) { try { var myDBOrderDetail = (from c in _db.OrderDetails where c.OrderId == OrderID && c.ProductId == updateProductID select c).FirstOrDefault(); if (myDBOrderDetail != null) { //do the work............. if (qtyCancelled + qtyShipped <= myDBOrderDetail.Quantity) { myDBOrderDetail.QtyShipped = qtyShipped; myDBOrderDetail.QtyCancelled = qtyCancelled; myDBOrderDetail.Comment = comment; } _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 FrontierAg.Models.ProductContext()) { try { var myItem = (from c in _db.ShoppingCartItems where c.CartId == removeCartID && c.Product.ProductId == removeProductID select c).FirstOrDefault(); if (myItem != null) { // Remove Item. _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, Decimal PriceOverride) // execute when changing price box or qty { using (var _db = new FrontierAg.Models.ProductContext()) { //try //{ //get item from CartItem Table in DB var myItem = (from c in _db.ShoppingCartItems where c.CartId == updateCartID && c.Product.ProductId == updateProductID select c).FirstOrDefault(); if (myItem != null) { //if QTY changed, get price from table if (myItem.Quantity != quantity) { myItem.Quantity = quantity; myItem.ItemPrice = GetPriceFromPrices(updateProductID, quantity); myItem.Charge = GetChargeFromPackCharges(updateProductID, quantity); myItem.OriginalPrice = myItem.ItemPrice; } else { //if Price changed, then use new price myItem.ItemPrice = PriceOverride; } CartSessionFlag = 0; _db.SaveChanges(); } else { CartSessionFlag = updateProductID; } //} //catch (Exception exp) //{ // throw new Exception("ERROR: Unable to Update Cart Item - " + exp.Message.ToString(), exp); //} } }