public bool saveOrder(List <CartDetail> cartDetails) { try { var userID = getUserAccID(); var isValid = false; foreach (var cart in cartDetails) { var storeID = cart.StoreDetailId; //check if cart is active, then change status to submitted //and save to the db if (cart.CartStatusId == 1) { //update cart status to Submitted //var cartStatus = db.CartStatus.Find(2); //Submitted cart.CartStatu = cartdb.GetCartStatus(2); var addResult = cartdb.AddCartDetails(cart); if (addResult) { if (addCartHistory(cart, 2, userID)) { if (removeCartSession(storeID)) { isValid = true; } } } else { return(false); } } } if (isValid) { if (cartdb.Save()) { return(true); } } return(false); } catch { return(false); } }