Beispiel #1
0
        public static Order FindCheckedOutOrder(Guid orderID)
        {
            //load the order
            var order = Order.SingleOrDefault(x => x.OrderID == orderID);

            //if it's not null, pull the products
            if (order != null)
            {
                KonaDB db  = new KonaDB();
                var    qry = (from p in db.Products
                              join oi in db.OrderItems on p.SKU equals oi.SKU
                              where oi.OrderID == orderID
                              select p).ToList();

                foreach (var item in order.OrderItems)
                {
                    item.Item = qry.SingleOrDefault(x => x.SKU == item.SKU);
                }

                //get the addresses
                order.ShippingAddress = Address.SingleOrDefault(x => x.AddressID == order.ShippingAddressID);
                order.BillingAddress  = Address.SingleOrDefault(x => x.AddressID == order.BillingAddressID);
            }


            return(order);
        }
Beispiel #2
0
        public static Address SaveIfNotExists(Address address)
        {
            if (!Address.Exists(x => x.UserName == address.UserName &&
                                x.Street1 == address.Street1 &&
                                x.StateOrProvince == address.StateOrProvince))
            {
                address.Add(address.UserName);
            }
            else
            {
                address = Address.SingleOrDefault(x => x.UserName == address.UserName &&
                                                  x.Street1 == address.Street1 &&
                                                  x.StateOrProvince == address.StateOrProvince);
            }

            return(address);
        }
Beispiel #3
0
        public static Order FindCurrentOrCreateNew(string userName)
        {
            var db = new KonaDB();

            Order result = Order.SingleOrDefault(x => x.UserName == userName && x.OrderStatusID == (int)OrderStatus.NotCheckedOut);

            if (result == null)
            {
                result                  = new Order();
                result.OrderID          = Guid.NewGuid();
                result.UserName         = userName;
                result.UserLanguageCode = System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName;
                result.OrderStatusID    = (int)OrderStatus.NotCheckedOut;
                result.Add("");
            }
            else
            {
                result.ShippingAddress = Address.SingleOrDefault(x => x.AddressID == result.ShippingAddressID);
                result.BillingAddress  = Address.SingleOrDefault(x => x.AddressID == result.BillingAddressID);
            }
            return(result);
        }