P0_TrevorGraham/StoreApplication/StoreMain/Logic/StoreSession.cs
/// <summary>
/// Attempts to add cart to db as order; Any quantities that are too high are dropped
/// </summary>
/// <returns>true if successful</returns>
Attempts to add cart to db as order; Any quantities that are too high are dropped
Attempts to add cart to db as order ; Any quantities that are too high are dropped
public bool AttemptCheckout(){
            if(!IsLoggedIn()||!ProductIsChosen()||!StoreIsChosen()){
                return false;
            }
            List<OrderLine> removeThese = new List<OrderLine>();
            foreach(OrderLine cartLine in cart){
                if(cartLine.Inventory.Quantity - cartLine.Quantity>=0){
                    cartLine.Inventory.Quantity -= cartLine.Quantity;
                }
                else{
                    removeThese.Add(cartLine);
                }
            }
            if(removeThese.Any()){
                foreach(OrderLine line in removeThese){
                    cart.Remove(line);
                }
            }
            if(cart.Any()){
                Order newOrder = new Order(){
                    Date = DateTime.Now,
                    Customer = currentCustomer,
                    OrderLines = cart
                };
                db.Orders.Add(newOrder);
                db.SaveChanges();
                return true;
            }
            return false;
        }
public bool AttemptCheckout ( ) { if ( ! IsLoggedIn ( ) || ! ProductIsChosen ( ) || ! StoreIsChosen ( ) ) { return false ; } List < OrderLine > removeThese = new List < OrderLine > ( ) ; foreach ( OrderLine cartLine in cart ) { if ( cartLine . Inventory . Quantity - cartLine . Quantity >= 0 ) { cartLine . Inventory . Quantity -= cartLine . Quantity ; } else { removeThese . Add ( cartLine ) ; } } if ( removeThese . Any ( ) ) { foreach ( OrderLine line in removeThese ) { cart . Remove ( line ) ; } } if ( cart . Any ( ) ) { Order newOrder = new Order ( ) { Date = DateTime . Now , Customer = currentCustomer , OrderLines = cart } ; db . Orders . Add ( newOrder ) ; db . SaveChanges ( ) ; return true ; } return false ; }
Attempts to add cart to db as order; Any quantities that are too high are dropped
Attempts to add cart to db as order ; Any quantities that are too high are dropped
//decrement inventories in db
true if successful
true if successful