/// <summary>
        /// Add a new Order to the database
        /// </summary>
        public virtual Int32 Add(Model.Order newOrder)
        {
            try
            {
                Trace.WriteVerbose("({0})", Trace.GetMethodName(), CLASSNAME, newOrder.ToString());
                var         helper  = Database.GetDbHelper();
                DbParameter IdParam = helper.CreateOutputParam("@Id", DbType.Int32);

                int recordsAffected = helper.ExecuteSPNonQuery(_storedProcedure_Add,
                                                               IdParam,
                                                               helper.CreateInputParam("@OrderMessageId", newOrder.OrderMessageId),
                                                               helper.CreateInputParam("@Code", newOrder.Code),
                                                               helper.CreateInputParam("@MaterialId", newOrder.MaterialId),
                                                               helper.CreateInputParam("@ResourceId", newOrder.ResourceId),
                                                               helper.CreateInputParam("@TargetQuantity", newOrder.TargetQuantity),
                                                               helper.CreateInputParam("@UOM", newOrder.UOM),
                                                               helper.CreateInputParam("@PlannedStartDate", newOrder.PlannedStartDate),
                                                               helper.CreateInputParam("@StartDate", newOrder.StartDate.HasValue ? (object)newOrder.StartDate : DBNull.Value),
                                                               helper.CreateInputParam("@FinishDate", newOrder.FinishDate.HasValue ? (object)newOrder.FinishDate : DBNull.Value));

                if (recordsAffected == 0)
                {
                    throw new DalNothingUpdatedException("Unable to add Order with Id={0}", newOrder);
                }

                return((Int32)IdParam.Value);
            }
            catch (Exception ex)
            {
                Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, newOrder.ToString());
                throw DbHelper.TranslateException(ex);
            }
        }
        /// <summary>
        /// Modify the given Order in the database
        /// </summary>
        public virtual void Modify(Model.Order modifiedOrder)
        {
            try
            {
                Trace.WriteVerbose("({0})", Trace.GetMethodName(), CLASSNAME, modifiedOrder.ToString());

                var helper          = Database.GetDbHelper();
                int recordsAffected = helper.ExecuteSPNonQuery(_storedProcedure_Modify,
                                                               helper.CreateInputParam("@Id", modifiedOrder.Id),
                                                               helper.CreateInputParam("@OrderMessageId", modifiedOrder.OrderMessageId),
                                                               helper.CreateInputParam("@Code", modifiedOrder.Code),
                                                               helper.CreateInputParam("@MaterialId", modifiedOrder.MaterialId),
                                                               helper.CreateInputParam("@ResourceId", modifiedOrder.ResourceId),
                                                               helper.CreateInputParam("@TargetQuantity", modifiedOrder.TargetQuantity),
                                                               helper.CreateInputParam("@UOM", modifiedOrder.UOM),
                                                               helper.CreateInputParam("@PlannedStartDate", modifiedOrder.PlannedStartDate),
                                                               helper.CreateInputParam("@StartDate", modifiedOrder.StartDate.HasValue ? (object)modifiedOrder.StartDate : DBNull.Value),
                                                               helper.CreateInputParam("@FinishDate", modifiedOrder.FinishDate.HasValue ? (object)modifiedOrder.FinishDate : DBNull.Value));

                if (recordsAffected == 0)
                {
                    throw new DalNothingUpdatedException("No records were updated (Table: Orders). Order=" + modifiedOrder.ToString());
                }
            }
            catch (Exception ex)
            {
                Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, modifiedOrder.ToString());
                throw DbHelper.TranslateException(ex);
            }
        }
        /// <summary>
        /// Delete the given Order from the database
        /// </summary>
        public virtual void Delete(Model.Order order)
        {
            try
            {
                Trace.WriteVerbose("({0})", Trace.GetMethodName(), CLASSNAME, order.ToString());

                var helper = Database.GetDbHelper();
                helper.ExecuteSPNonQuery(_storedProcedure_Delete,
                                         helper.CreateInputParam("@Id", order.Id));
            }
            catch (Exception ex)
            {
                Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, order.ToString());
                throw DbHelper.TranslateException(ex);
            }
        }