P1_TrevorGraham/MvcStoreApplication/Repository/Repository.cs
/// <summary>
/// gets an open order for the given customer id
/// </summary>
/// <param name="customerId"></param>
/// <returns></returns>
gets an open order for the given customer id
gets an open order for the given customer id
public Order GetOpenCartForCustomer(Guid customerId)
        {
            Order cart = _dbContext.Orders.Include(x=>x.Customer).Where(x=>x.Customer.UserId==customerId).Where(x => x.OrderIsComplete == false).FirstOrDefault();
            if (cart == null)
            {
                cart = new Order()
                {
                    OrderId = Guid.NewGuid(),
                    Date = DateTime.Now,
                    Customer = GetCustomerById(customerId),
                    OrderIsComplete = false
                };
                _dbContext.SaveChanges();
            }
            return cart;
        }
public Order GetOpenCartForCustomer ( Guid customerId ) { Order cart = _dbContext . Orders . Include ( x => x . Customer ) . Where ( x => x . Customer . UserId == customerId ) . Where ( x => x . OrderIsComplete == false ) . FirstOrDefault ( ) ; if ( cart == null ) { cart = new Order ( ) { OrderId = Guid . NewGuid ( ) , Date = DateTime . Now , Customer = GetCustomerById ( customerId ) , OrderIsComplete = false } ; _dbContext . SaveChanges ( ) ; } return cart ; }
gets an open order for the given customer id
gets an open order for the given customer id
None
customerId
Guid
None