public OrdersApiModel()
 {
     Order = new Order();
     OrderDetail = new OrderDetail();
     Customer = new Customer();
     Orders = new List<OrderInquiry>();
     Shippers = new List<Shipper>();
     OrderDetails = new List<OrderDetails>();
 }
        /// <summary>
        /// Validate Order
        /// </summary>
        /// <param name="orderr"></param>
        /// <param name="dataService"></param>
        public void ValidateOrder(Order order, IOrdersDataService dataService)
        {
            ordersDataService = dataService;

            InitializeValidationRules(order);
           
            ValidateRequired("ShipName", "Ship To Name");
            ValidateRequired("ShipCity", "Ship To City");
            ValidateRequired("ShipRegion", "Ship To Region");
            ValidateRequired("ShipPostalCode", "Ship To Postal Code");
            ValidateRequired("ShipCountry", "Ship To Country");
            ValidateRequired("ShipAddress", "Ship To Address");                            
            ValidateRequiredDate("RequiredDate", "Required Ship Date");
            ValidateSelectedValue("ShipVia", "Ship Via");
       
        }
        /// <summary>
        /// Create Order
        /// </summary>
        /// <param name="customerID"></param>
        /// <param name="requiredDate"></param>
        /// <param name="shipName"></param>
        /// <param name="shipAddress"></param>
        /// <param name="shipCity"></param>
        /// <param name="shipRegion"></param>
        /// <param name="shipPostalCode"></param>
        /// <param name="shipCountry"></param>
        /// <param name="shipperID"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        public Order CreateOrder(Guid customerID, DateTime requiredDate, string shipName, 
                                string shipAddress, string shipCity, string shipRegion, 
                                string shipPostalCode, string shipCountry, int shipperID, 
                                out TransactionalInformation transaction)
        {
       
            transaction = new TransactionalInformation();

            OrdersBusinessRules ordersBusinessRules = new OrdersBusinessRules();

            Order order = new Order();

            order.CustomerID = customerID;
            order.OrderDate = DateTime.Now;
            order.RequiredDate = requiredDate;
            order.ShipAddress = shipAddress;
            order.ShipName = shipName;
            order.ShipCity = shipCity;
            order.ShipPostalCode = shipPostalCode;
            order.ShipRegion = shipRegion;
            order.ShipCountry = shipCountry;
            order.ShipVia = shipperID;
            order.OrderTotal = 0.00m;


            try
            {

                ordersDataService.CreateSession();

                ordersBusinessRules.ValidateOrder(order, ordersDataService);

                if (ordersBusinessRules.ValidationStatus == true)
                {
                    ordersDataService.BeginTransaction();
                    ordersDataService.CreateOrder(order);
                    ordersDataService.CommitTransaction(true);
                    transaction.ReturnStatus = true;
                    transaction.ReturnMessage.Add("Order successfully created.");
                }
                else
                {
                    transaction.ReturnStatus = ordersBusinessRules.ValidationStatus;
                    transaction.ReturnMessage = ordersBusinessRules.ValidationMessage;
                    transaction.ValidationErrors = ordersBusinessRules.ValidationErrors;
                }

            }
            catch (Exception ex)
            {
                transaction.ReturnMessage = new List<string>();
                string errorMessage = ex.Message;
                transaction.ReturnStatus = false;
                transaction.ReturnMessage.Add(errorMessage);
            }
            finally
            {
                ordersDataService.CloseSession();
            }

            return order;


        }
        /// <summary>
        /// Get Order
        /// </summary>
        /// <param name="orderID"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        public Order GetOrder(int orderID, out TransactionalInformation transaction)
        {
            transaction = new TransactionalInformation();

            Order order = new Order();

            try
            {
                ordersDataService.CreateSession();
                order = ordersDataService.GetOrder(orderID);
                transaction.ReturnStatus = true;
            }
            catch (Exception ex)
            {
                transaction.ReturnMessage = new List<string>();
                string errorMessage = ex.Message;
                transaction.ReturnStatus = false;
                transaction.ReturnMessage.Add(errorMessage);
            }
            finally
            {
                ordersDataService.CloseSession();
            }

            return order;

        }
 /// <summary>
 /// Update Order
 /// </summary>
 /// <param name="order"></param>
 public void UpdateOrder(Order order)
 {
     order.DateUpdated = DateTime.Now;
 }
        /// <summary>
        /// Create Order
        /// </summary>
        /// <param name="order"></param>
        public void CreateOrder(Order order)
        {
            dbConnection.Orders.Add(order);

        }
        /// <summary>
        /// Initialize user Business Rules
        /// </summary>
        /// <param name="user"></param>
        /// <param name="dataService"></param>
        public void InitializeCustomersBusinessRules(Order order, IOrdersDataService dataService)
        {
            ordersDataService = dataService;
            InitializeValidationRules(order);

        }