//------------------------------------------------------------------------------------------------------
        #endregion

        #region /*--------- Updat ---------*\
        //------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Converts the object properties to SQL paramters and executes the update procedure.
        /// </summary>
        /// <param name="ItemsOrdersObj">Model object.</param>
        /// <returns>The result of update query.</returns>
        //--------------------------------------------------------------------
        public bool Updat(ItemsOrdersModel ItemsOrdersObj)
        {
            bool result = false;
            using (SqlConnection myConnection = GetSqlConnection())
            {
                SqlCommand myCommand = new SqlCommand("[dbo].[ItemsOrders_Update]", myConnection);
                myCommand.CommandType = CommandType.StoredProcedure;
                //----------------------------------------------------------------------------------------------
                // Set the parameters
                //----------------------------------------------------------------------------------------------
                myCommand.Parameters.Add("@OrderID", SqlDbType.Int, 4).Value = ItemsOrdersObj.OrderID;
                //myCommand.Parameters.Add("@UserId", SqlDbType.UniqueIdentifier).Value = ItemsOrdersObj.UserId;
				myCommand.Parameters.Add("@Status", SqlDbType.Int, 4).Value = ItemsOrdersObj.Status;
				myCommand.Parameters.Add("@Comment", SqlDbType.NVarChar, 500).Value = ItemsOrdersObj.Comment;
				//myCommand.Parameters.Add("@DateAdded", SqlDbType.DateTime2, 8).Value = ItemsOrdersObj.DateAdded;

                //----------------------------------------------------------------------------------------------
                // Execute the command
                //----------------------------------------------------------------------------------------------
                myConnection.Open();
                if (myCommand.ExecuteNonQuery() > 0)
                {
                    result = true;
                }
                myConnection.Close();
                return result;
                //----------------------------------------------------------------------------------------------
            }
        }
        //------------------------------------------------------------------------------------------------------
        #endregion

        #region /*--------- Create ---------*\
        //------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Converts the  object properties to SQL paramters and executes the create  procedure 
        /// and updates the object with the SQL data by reference.
        /// </summary>
        /// <param name="ItemsOrdersObj">Model object.</param>
        /// <returns>The result of create query.</returns>
        //--------------------------------------------------------------------
        public bool Create(ItemsOrdersModel ItemsOrdersObj, List<ItemsOrdersDetailsModel> productsList)
        {
            bool result = false;
            using (SqlConnection myConnection = GetSqlConnection())
            {
                SqlCommand myCommand = new SqlCommand("[dbo].[ItemsOrders_Create]", myConnection);
                myCommand.CommandType = CommandType.StoredProcedure;
                //----------------------------------------------------------------------------------------------
                // Set the parameters
                //----------------------------------------------------------------------------------------------
                myCommand.Parameters.Add("@OrderID", SqlDbType.Int, 4).Direction = ParameterDirection.Output;
				myCommand.Parameters.Add("@UserId", SqlDbType.UniqueIdentifier).Value = ItemsOrdersObj.UserId;
				//myCommand.Parameters.Add("@Status", SqlDbType.Int, 4).Value = ItemsOrdersObj.Status;
				myCommand.Parameters.Add("@Comment", SqlDbType.NVarChar, 500).Value = ItemsOrdersObj.Comment;
                myCommand.Parameters.Add("@CustomerName", SqlDbType.NVarChar, 128).Value = ItemsOrdersObj.CustomerName;
                myCommand.Parameters.Add("@CustomerEmail", SqlDbType.NVarChar, 128).Value = ItemsOrdersObj.CustomerEmail;
                myCommand.Parameters.Add("@CustomerPhone", SqlDbType.NVarChar, 32).Value = ItemsOrdersObj.CustomerPhone;
                myCommand.Parameters.Add("@CustomerMobile", SqlDbType.NVarChar, 32).Value = ItemsOrdersObj.CustomerMobile;
                myCommand.Parameters.Add("@CustomerAddress", SqlDbType.NVarChar, 256).Value = ItemsOrdersObj.CustomerAddress;
				//myCommand.Parameters.Add("@DateAdded", SqlDbType.DateTime2, 8).Value = ItemsOrdersObj.DateAdded;
                //----------------------------------------------------------------------------------------------
                // Execute the command
                //----------------------------------------------------------------------------------------------
                myConnection.Open();
                if (myCommand.ExecuteNonQuery() > 0)
                {
                    result = true;
                    //Get ID value from database and set it in object
                    ItemsOrdersObj.OrderID = (int)myCommand.Parameters["@OrderID"].Value;
                SaveDetails(myConnection, ItemsOrdersObj.OrderID, productsList);
                }
                myConnection.Close();
                return result;
                //----------------------------------------------------------------------------------------------
            }
        }
Beispiel #3
0
        //------------------------------------------------------------------------------------------------------
        #endregion

        #region --------------Updat--------------
        //------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Updates model object by calling sql data provider update method.
        /// </summary>
        /// <param name="ItemsOrdersObj">The model object.</param>
        /// <returns>The result of update operation.</returns>
        //--------------------------------------------------------------------
        public static bool Updat(ItemsOrdersModel ItemsOrdersObj)
        {
            return(ItemsOrdersSqlDataPrvider.Instance.Updat(ItemsOrdersObj));
        }
Beispiel #4
0
 //------------------------------------------------------------------------------------------------------
 /// <summary>
 /// Creates model object by calling News data provider create method.
 /// </summary>
 /// <param name="ItemsOrdersObj">The model object.</param>
 /// <returns>The result of create operation.</returns>
 //--------------------------------------------------------------------
 public static bool Create(ItemsOrdersModel ItemsOrdersObj, List <ItemsOrdersDetailsModel> productsList)
 {
     return(ItemsOrdersSqlDataPrvider.Instance.Create(ItemsOrdersObj, productsList));
 }
        //------------------------------------------------------------------------------------------------------
        #endregion

        #region /*--------- PopulateModelFromIDataReader ---------*\
        //------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Populates model from IDataReader .
        /// </summary>
        /// <param name="reader"></param>
        /// <returns>Model object.</returns>
        //--------------------------------------------------------------------
        private ItemsOrdersModel PopulateModelFromIDataReader(IDataReader reader)
        {
            //Create a new object
            ItemsOrdersModel ItemsOrdersObj = new ItemsOrdersModel();
            //Fill the object with data
            //------------------------------------------------
            //OrderID
            //------------------------------------------------
            if (reader["OrderID"] != DBNull.Value)
                ItemsOrdersObj.OrderID = (int)reader["OrderID"];
            //------------------------------------------------

			//------------------------------------------------
			//[UserId]
			//------------------------------------------------
			if (reader["UserId"] != DBNull.Value)
			    ItemsOrdersObj.UserId = (Guid)reader["UserId"];
			//------------------------------------------------
			//------------------------------------------------
			//[Status]
			//------------------------------------------------
			if (reader["Status"] != DBNull.Value)
			    ItemsOrdersObj.Status = (int)reader["Status"];
			//------------------------------------------------
			//------------------------------------------------
			//[Comment]
			//------------------------------------------------
			if (reader["Comment"] != DBNull.Value)
			    ItemsOrdersObj.Comment = (string)reader["Comment"];
			//------------------------------------------------
			//------------------------------------------------
			//[DateAdded]
			//------------------------------------------------
			if (reader["DateAdded"] != DBNull.Value)
			    ItemsOrdersObj.DateAdded = (DateTime)reader["DateAdded"];
			//------------------------------------------------
            //------------------------------------------------
            //[CustomerName]
			//------------------------------------------------
            if (reader["CustomerName"] != DBNull.Value)
                ItemsOrdersObj.CustomerName = (string)reader["CustomerName"];
            //------------------------------------------------
            //[CustomerEmail]
            //------------------------------------------------
            if (reader["CustomerEmail"] != DBNull.Value)
                ItemsOrdersObj.CustomerEmail = (string)reader["CustomerEmail"];
            //------------------------------------------------
            //[CustomerPhone]
            //------------------------------------------------
            if (reader["CustomerPhone"] != DBNull.Value)
                ItemsOrdersObj.CustomerPhone = (string)reader["CustomerPhone"];
            //------------------------------------------------
            //[CustomerMobile]
            //------------------------------------------------
            if (reader["CustomerMobile"] != DBNull.Value)
                ItemsOrdersObj.CustomerMobile = (string)reader["CustomerMobile"];
            //------------------------------------------------
            //[CustomerAddress]
            //------------------------------------------------
            if (reader["CustomerAddress"] != DBNull.Value)
                ItemsOrdersObj.CustomerAddress = (string)reader["CustomerAddress"];
            //------------------------------------------------
            //Return the populated object
            return ItemsOrdersObj;
        }